Significant Levels Robot
Replies
hichem
31 May 2013, 13:19
using cAlgo.API; using cAlgo.API.Requests; using System; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; namespace cAlgo.Robots { [Robot] public class SIGLEVEL : Robot { private Position position; [Parameter(DefaultValue = 10000, MinValue = 1000)] public int InitialVolume { get; set; } [Parameter("Trade on bounce", DefaultValue = 0, MinValue = 0, MaxValue = 1)] public int Tbounce { get; set; } [Parameter("Trade on breakout", DefaultValue = 0, MinValue = 0, MaxValue = 1)] public int Tbreak { get; set; } [Parameter("Stop Loss (pips)", DefaultValue = 20, MinValue = 0)] public int StopLoss { get; set; } [Parameter("TakeProfit (pips)", DefaultValue = 20, MinValue = 0)] public int TakeProfit { get; set; } [Parameter("Trailing Stop (pips)", DefaultValue = 20, MinValue = 0)] public int TrailingStop { get; set; } [Parameter("Breakeven (pips)", DefaultValue = 0, MinValue = 0)] public int Breakeven { get; set; } [Parameter("Trigger (pips)", DefaultValue = 5, MinValue = 0)] public int Trigger { get; set; } [Parameter("Start time (Hour)", DefaultValue = 0, MinValue = 0, MaxValue = 24)] public int Starttime { get; set; } [Parameter("Stop time (Hour)", DefaultValue = 24, MinValue = 0, MaxValue = 24)] public int Stoptime { get; set; } [Parameter(DefaultValue = 1, MinValue = 0, MaxValue = 50)] public int RiskPct { get; set; } [Parameter(DefaultValue = 500, MinValue = 100, MaxValue = 500)] public int Leverage { get; set; } [Parameter("Robot Code", DefaultValue = 0, MinValue = 222)] public int code { get; set; } protected override void OnStart() { string text = "SIG LEVEL"; string message = "PLEASE UPDATE ME.Contact cAlgoFx"; double num = 2013.0; double num2 = 8.0; double num3 = 30.0; double num4 = (double)base.Server.Time.Year; double num5 = (double)base.Server.Time.Month; double num6 = (double)base.Server.Time.Day; bool flag = num4 > num || (num4 >= num && num5 > num2) || (num4 >= num && num5 >= num2 && num6 > num3); if (flag) { base.Print(message, new object[0]); base.Stop(); } base.ChartObjects.DrawText("SIG LEVEL", text, StaticPosition.BottomLeft, new Colors?(Colors.Lime)); double num7 = base.MarketSeries.High.Maximum(base.MarketSeries.High.Count); double num8 = base.MarketSeries.Low.Minimum(base.MarketSeries.Low.Count); double num9 = base.Symbol.PipSize * 100.0; double num10 = Math.Floor(num8 / num9) * num9; for (double num11 = num10; num11 <= num7 + num9; num11 += num9) { base.ChartObjects.DrawHorizontalLine("line_" + num11, num11, Colors.Blue, 1.0, LineStyle.Solid); } } protected override void OnBar() { if (base.Trade.IsExecuting) { return; } int num = base.Account.Positions.Count((Position position) => position.Label == this.code.ToString() && position.SymbolCode == base.Symbol.Code); int index = base.MarketSeries.Low.Count - 2; int index2 = base.MarketSeries.High.Count - 2; int index3 = base.MarketSeries.Low.Count - 3; int index4 = base.MarketSeries.High.Count - 3; int index5 = base.MarketSeries.Close.Count - 3; int index6 = base.MarketSeries.Open.Count - 2; int index7 = base.MarketSeries.Close.Count - 2; double num2 = base.MarketSeries.Open[index6]; double num3 = base.MarketSeries.Close[index7]; double num4 = base.MarketSeries.High[index2]; double num5 = base.MarketSeries.Low[index]; double arg_114_0 = base.MarketSeries.High[index4]; double arg_126_0 = base.MarketSeries.Low[index3]; double arg_139_0 = base.MarketSeries.Close[index5]; double arg_14A_0 = base.MarketSeries.High.LastValue; double arg_15B_0 = base.MarketSeries.Low.LastValue; double lastValue = base.MarketSeries.Close.LastValue; double arg_17E_0 = base.MarketSeries.Open.LastValue; double num6 = (double)base.Server.Time.Hour; double a = base.Account.FreeMargin * (double)this.RiskPct / 100.0 / (double)(this.InitialVolume / this.Leverage); double num7 = Math.Max(1.0, Math.Min(50.0, Math.Round(a))); double num8 = base.Symbol.PipSize * 100.0; Math.Floor(lastValue / num8); bool flag = num6 >= (double)this.Starttime && num6 < (double)this.Stoptime; bool flag2 = (base.Symbol.Digits == 4 && Math.Truncate(num2) > Math.Truncate(num5) && Math.Truncate(num3) > Math.Truncate(num5)) || (base.Symbol.Digits == 5 && Math.Truncate(num2 * 100.0) > Math.Truncate(num5 * 100.0) && Math.Truncate(num3 * 100.0) > Math.Truncate(num5 * 100.0)); bool flag3 = (base.Symbol.Digits == 4 && Math.Truncate(num2) < Math.Truncate(num4) && Math.Truncate(num3) < Math.Truncate(num4)) || (base.Symbol.Digits == 5 && Math.Truncate(num2 * 100.0) < Math.Truncate(num4 * 100.0) && Math.Truncate(num3 * 100.0) < Math.Truncate(num5 * 100.0)); bool flag4 = (base.Symbol.Digits == 4 && Math.Truncate(num2) < Math.Truncate(num4) && Math.Truncate(num3) > Math.Truncate(num5)) || (base.Symbol.Digits == 5 && Math.Truncate(num3 * 100.0) > Math.Truncate(num5 * 100.0)); bool flag5 = (base.Symbol.Digits == 4 && Math.Truncate(num2) > Math.Truncate(num5) && Math.Truncate(num3) < Math.Truncate(num4)) || (base.Symbol.Digits == 5 && Math.Truncate(num3 * 100.0) < Math.Truncate(num5 * 100.0)); if (num < 1 && flag) { if ((flag2 && this.Tbounce > 0) || (flag4 && this.Tbreak > 0)) { MarketOrderRequest request = new MarketOrderRequest(TradeType.Buy, (int)((double)this.InitialVolume * num7)) { Label = this.code.ToString(), SlippagePips = new int?(1), StopLossPips = new int?(this.StopLoss), TakeProfitPips = new int?(this.TakeProfit) }; base.Trade.Send(request); return; } if ((flag3 && this.Tbounce > 0) || (flag5 && this.Tbreak > 0)) { MarketOrderRequest request2 = new MarketOrderRequest(TradeType.Sell, (int)((double)this.InitialVolume * num7)) { Label = this.code.ToString(), SlippagePips = new int?(1), StopLossPips = new int?(this.StopLoss), TakeProfitPips = new int?(this.TakeProfit) }; base.Trade.Send(request2); } } } protected override void OnTick() { int num = base.Account.Positions.Count((Position position) => position.Label == this.code.ToString() && position.SymbolCode == base.Symbol.Code); if (num < 1) { return; } foreach (Position current in base.Account.Positions) { if (current.Label == this.code.ToString() && current.SymbolCode == base.Symbol.Code) { if (current.TradeType == TradeType.Sell) { if (current.Pips >= (double)this.Trigger && this.Breakeven > 0) { double num2 = current.EntryPrice - (double)this.Breakeven * base.Symbol.PipSize; double num3 = num2; double? stopLoss = current.StopLoss; if (num3 < stopLoss.GetValueOrDefault() && stopLoss.HasValue) { base.Trade.ModifyPosition(current, new double?(num2), current.TakeProfit); } } if (current.Pips >= (double)this.Trigger && this.Breakeven < 1) { double num4 = base.Symbol.Ask + (double)this.TrailingStop * base.Symbol.PipSize; double num5 = num4; double? stopLoss2 = current.StopLoss; if (num5 < stopLoss2.GetValueOrDefault() && stopLoss2.HasValue) { base.Trade.ModifyPosition(current, new double?(num4), current.TakeProfit); } } } else { if (current.Pips >= (double)this.Trigger && this.Breakeven > 0) { double entryPrice = current.EntryPrice; double? stopLoss3 = current.StopLoss; double num6 = entryPrice; if (stopLoss3.GetValueOrDefault() < num6 && stopLoss3.HasValue) { base.Trade.ModifyPosition(current, new double?(entryPrice), current.TakeProfit); } } if (current.Pips >= (double)this.Trigger && this.Breakeven < 1) { double num7 = base.Symbol.Bid - (double)this.TrailingStop * base.Symbol.PipSize; double? stopLoss4 = current.StopLoss; double num8 = num7; if (stopLoss4.GetValueOrDefault() < num8 && stopLoss4.HasValue) { base.Trade.ModifyPosition(current, new double?(num7), current.TakeProfit); } } } } } } protected override void OnPositionOpened(Position openedPosition) { this.position = openedPosition; //openedPosition.SymbolCode == base.Symbol.Code; if (this.position.TradeType == TradeType.Sell) { if (this.position.Pips < 0.0) { if (this.position.StopLoss.HasValue) { double? stopLoss = this.position.StopLoss; double entryPrice = this.position.EntryPrice; double? num = stopLoss.HasValue ? new double?(stopLoss.GetValueOrDefault() - entryPrice) : null; double num2 = base.Symbol.PipSize * (double)this.StopLoss; if (num.GetValueOrDefault() <= num2 || !num.HasValue) { return; } } base.Trade.ModifyPosition(this.position, new double?(this.position.EntryPrice + base.Symbol.PipSize * (double)this.StopLoss), this.position.TakeProfit); return; } } else { if (this.position.Pips < 0.0) { if (this.position.StopLoss.HasValue) { double entryPrice2 = this.position.EntryPrice; double? stopLoss2 = this.position.StopLoss; double? num3 = stopLoss2.HasValue ? new double?(entryPrice2 - stopLoss2.GetValueOrDefault()) : null; double num4 = base.Symbol.PipSize * (double)this.StopLoss; if (num3.GetValueOrDefault() <= num4 || !num3.HasValue) { return; } } base.Trade.ModifyPosition(this.position, new double?(this.position.EntryPrice - base.Symbol.PipSize * (double)this.StopLoss), this.position.TakeProfit); } } } protected override void OnError(Error error) { base.Print("{0}", new object[] { error.Code }); } } }
@hichem
cAlgoFx
31 May 2013, 13:46
RE:
using cAlgo.API; using cAlgo.API.Requests; using System; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; namespace cAlgo.Robots { [Robot] public class SIGLEVEL : Robot { private Position position; [Parameter(DefaultValue = 10000, MinValue = 1000)] public int InitialVolume { get; set; } [Parameter("Trade on bounce", DefaultValue = 0, MinValue = 0, MaxValue = 1)] public int Tbounce { get; set; } [Parameter("Trade on breakout", DefaultValue = 0, MinValue = 0, MaxValue = 1)] public int Tbreak { get; set; } [Parameter("Stop Loss (pips)", DefaultValue = 20, MinValue = 0)] public int StopLoss { get; set; } [Parameter("TakeProfit (pips)", DefaultValue = 20, MinValue = 0)] public int TakeProfit { get; set; } [Parameter("Trailing Stop (pips)", DefaultValue = 20, MinValue = 0)] public int TrailingStop { get; set; } [Parameter("Breakeven (pips)", DefaultValue = 0, MinValue = 0)] public int Breakeven { get; set; } [Parameter("Trigger (pips)", DefaultValue = 5, MinValue = 0)] public int Trigger { get; set; } [Parameter("Start time (Hour)", DefaultValue = 0, MinValue = 0, MaxValue = 24)] public int Starttime { get; set; } [Parameter("Stop time (Hour)", DefaultValue = 24, MinValue = 0, MaxValue = 24)] public int Stoptime { get; set; } [Parameter(DefaultValue = 1, MinValue = 0, MaxValue = 50)] public int RiskPct { get; set; } [Parameter(DefaultValue = 500, MinValue = 100, MaxValue = 500)] public int Leverage { get; set; } [Parameter("Robot Code", DefaultValue = 0, MinValue = 222)] public int code { get; set; } protected override void OnStart() { string text = "SIG LEVEL"; string message = "PLEASE UPDATE ME.Contact cAlgoFx"; double num = 2013.0; double num2 = 8.0; double num3 = 30.0; double num4 = (double)base.Server.Time.Year; double num5 = (double)base.Server.Time.Month; double num6 = (double)base.Server.Time.Day; bool flag = num4 > num || (num4 >= num && num5 > num2) || (num4 >= num && num5 >= num2 && num6 > num3); if (flag) { base.Print(message, new object[0]); base.Stop(); } base.ChartObjects.DrawText("SIG LEVEL", text, StaticPosition.BottomLeft, new Colors?(Colors.Lime)); double num7 = base.MarketSeries.High.Maximum(base.MarketSeries.High.Count); double num8 = base.MarketSeries.Low.Minimum(base.MarketSeries.Low.Count); double num9 = base.Symbol.PipSize * 100.0; double num10 = Math.Floor(num8 / num9) * num9; for (double num11 = num10; num11 <= num7 + num9; num11 += num9) { base.ChartObjects.DrawHorizontalLine("line_" + num11, num11, Colors.Blue, 1.0, LineStyle.Solid); } } protected override void OnBar() { if (base.Trade.IsExecuting) { return; } int num = base.Account.Positions.Count((Position position) => position.Label == this.code.ToString() && position.SymbolCode == base.Symbol.Code); int index = base.MarketSeries.Low.Count - 2; int index2 = base.MarketSeries.High.Count - 2; int index3 = base.MarketSeries.Low.Count - 3; int index4 = base.MarketSeries.High.Count - 3; int index5 = base.MarketSeries.Close.Count - 3; int index6 = base.MarketSeries.Open.Count - 2; int index7 = base.MarketSeries.Close.Count - 2; double num2 = base.MarketSeries.Open[index6]; double num3 = base.MarketSeries.Close[index7]; double num4 = base.MarketSeries.High[index2]; double num5 = base.MarketSeries.Low[index]; double arg_114_0 = base.MarketSeries.High[index4]; double arg_126_0 = base.MarketSeries.Low[index3]; double arg_139_0 = base.MarketSeries.Close[index5]; double arg_14A_0 = base.MarketSeries.High.LastValue; double arg_15B_0 = base.MarketSeries.Low.LastValue; double lastValue = base.MarketSeries.Close.LastValue; double arg_17E_0 = base.MarketSeries.Open.LastValue; double num6 = (double)base.Server.Time.Hour; double a = base.Account.FreeMargin * (double)this.RiskPct / 100.0 / (double)(this.InitialVolume / this.Leverage); double num7 = Math.Max(1.0, Math.Min(50.0, Math.Round(a))); double num8 = base.Symbol.PipSize * 100.0; Math.Floor(lastValue / num8); bool flag = num6 >= (double)this.Starttime && num6 < (double)this.Stoptime; bool flag2 = (base.Symbol.Digits == 4 && Math.Truncate(num2) > Math.Truncate(num5) && Math.Truncate(num3) > Math.Truncate(num5)) || (base.Symbol.Digits == 5 && Math.Truncate(num2 * 100.0) > Math.Truncate(num5 * 100.0) && Math.Truncate(num3 * 100.0) > Math.Truncate(num5 * 100.0)); bool flag3 = (base.Symbol.Digits == 4 && Math.Truncate(num2) < Math.Truncate(num4) && Math.Truncate(num3) < Math.Truncate(num4)) || (base.Symbol.Digits == 5 && Math.Truncate(num2 * 100.0) < Math.Truncate(num4 * 100.0) && Math.Truncate(num3 * 100.0) < Math.Truncate(num5 * 100.0)); bool flag4 = (base.Symbol.Digits == 4 && Math.Truncate(num2) < Math.Truncate(num4) && Math.Truncate(num3) > Math.Truncate(num5)) || (base.Symbol.Digits == 5 && Math.Truncate(num3 * 100.0) > Math.Truncate(num5 * 100.0)); bool flag5 = (base.Symbol.Digits == 4 && Math.Truncate(num2) > Math.Truncate(num5) && Math.Truncate(num3) < Math.Truncate(num4)) || (base.Symbol.Digits == 5 && Math.Truncate(num3 * 100.0) < Math.Truncate(num5 * 100.0)); if (num < 1 && flag) { if ((flag2 && this.Tbounce > 0) || (flag4 && this.Tbreak > 0)) { MarketOrderRequest request = new MarketOrderRequest(TradeType.Buy, (int)((double)this.InitialVolume * num7)) { Label = this.code.ToString(), SlippagePips = new int?(1), StopLossPips = new int?(this.StopLoss), TakeProfitPips = new int?(this.TakeProfit) }; base.Trade.Send(request); return; } if ((flag3 && this.Tbounce > 0) || (flag5 && this.Tbreak > 0)) { MarketOrderRequest request2 = new MarketOrderRequest(TradeType.Sell, (int)((double)this.InitialVolume * num7)) { Label = this.code.ToString(), SlippagePips = new int?(1), StopLossPips = new int?(this.StopLoss), TakeProfitPips = new int?(this.TakeProfit) }; base.Trade.Send(request2); } } } protected override void OnTick() { int num = base.Account.Positions.Count((Position position) => position.Label == this.code.ToString() && position.SymbolCode == base.Symbol.Code); if (num < 1) { return; } foreach (Position current in base.Account.Positions) { if (current.Label == this.code.ToString() && current.SymbolCode == base.Symbol.Code) { if (current.TradeType == TradeType.Sell) { if (current.Pips >= (double)this.Trigger && this.Breakeven > 0) { double num2 = current.EntryPrice - (double)this.Breakeven * base.Symbol.PipSize; double num3 = num2; double? stopLoss = current.StopLoss; if (num3 < stopLoss.GetValueOrDefault() && stopLoss.HasValue) { base.Trade.ModifyPosition(current, new double?(num2), current.TakeProfit); } } if (current.Pips >= (double)this.Trigger && this.Breakeven < 1) { double num4 = base.Symbol.Ask + (double)this.TrailingStop * base.Symbol.PipSize; double num5 = num4; double? stopLoss2 = current.StopLoss; if (num5 < stopLoss2.GetValueOrDefault() && stopLoss2.HasValue) { base.Trade.ModifyPosition(current, new double?(num4), current.TakeProfit); } } } else { if (current.Pips >= (double)this.Trigger && this.Breakeven > 0) { double entryPrice = current.EntryPrice; double? stopLoss3 = current.StopLoss; double num6 = entryPrice; if (stopLoss3.GetValueOrDefault() < num6 && stopLoss3.HasValue) { base.Trade.ModifyPosition(current, new double?(entryPrice), current.TakeProfit); } } if (current.Pips >= (double)this.Trigger && this.Breakeven < 1) { double num7 = base.Symbol.Bid - (double)this.TrailingStop * base.Symbol.PipSize; double? stopLoss4 = current.StopLoss; double num8 = num7; if (stopLoss4.GetValueOrDefault() < num8 && stopLoss4.HasValue) { base.Trade.ModifyPosition(current, new double?(num7), current.TakeProfit); } } } } } } protected override void OnPositionOpened(Position openedPosition) { this.position = openedPosition; //openedPosition.SymbolCode == base.Symbol.Code; if (this.position.TradeType == TradeType.Sell) { if (this.position.Pips < 0.0) { if (this.position.StopLoss.HasValue) { double? stopLoss = this.position.StopLoss; double entryPrice = this.position.EntryPrice; double? num = stopLoss.HasValue ? new double?(stopLoss.GetValueOrDefault() - entryPrice) : null; double num2 = base.Symbol.PipSize * (double)this.StopLoss; if (num.GetValueOrDefault() <= num2 || !num.HasValue) { return; } } base.Trade.ModifyPosition(this.position, new double?(this.position.EntryPrice + base.Symbol.PipSize * (double)this.StopLoss), this.position.TakeProfit); return; } } else { if (this.position.Pips < 0.0) { if (this.position.StopLoss.HasValue) { double entryPrice2 = this.position.EntryPrice; double? stopLoss2 = this.position.StopLoss; double? num3 = stopLoss2.HasValue ? new double?(entryPrice2 - stopLoss2.GetValueOrDefault()) : null; double num4 = base.Symbol.PipSize * (double)this.StopLoss; if (num3.GetValueOrDefault() <= num4 || !num3.HasValue) { return; } } base.Trade.ModifyPosition(this.position, new double?(this.position.EntryPrice - base.Symbol.PipSize * (double)this.StopLoss), this.position.TakeProfit); } } } protected override void OnError(Error error) { base.Print("{0}", new object[] { error.Code }); } } }
Hello,
Your point is?
@cAlgoFx
elodie
07 Jun 2013, 13:45
not trade sell
hello !!!
not trade sell...?
error flag3 and flag 5.
the error may be here
someone has a 't have any idea ..?
if ((flag3 && this.Tbounce > 0) || (flag5 && this.Tbreak > 0))
{
MarketOrderRequest request2 = new MarketOrderRequest(TradeType.Sell, (int)((double)this.InitialVolume * num7))
bool flag = num6 >= (double)this.Starttime && num6 < (double)this.Stoptime;
bool flag2 = (base.Symbol.Digits == 4 && Math.Truncate(num2) > Math.Truncate(num5) && Math.Truncate(num3) > Math.Truncate(num5)) || (base.Symbol.Digits == 5 && Math.Truncate(num2 * 100.0) > Math.Truncate(num5 * 100.0) && Math.Truncate(num3 * 100.0) > Math.Truncate(num5 * 100.0));
bool flag3 = (base.Symbol.Digits == 4 && Math.Truncate(num2) < Math.Truncate(num4) && Math.Truncate(num3) < Math.Truncate(num4)) || (base.Symbol.Digits == 5 && Math.Truncate(num2 * 100.0) < Math.Truncate(num4 * 100.0) && Math.Truncate(num3 * 100.0) < Math.Truncate(num5 * 100.0));
bool flag4 = (base.Symbol.Digits == 4 && Math.Truncate(num2) < Math.Truncate(num4) && Math.Truncate(num3) > Math.Truncate(num5)) || (base.Symbol.Digits == 5 && Math.Truncate(num3 * 100.0) > Math.Truncate(num5 * 100.0));
bool flag5 = (base.Symbol.Digits == 4 && Math.Truncate(num2) > Math.Truncate(num5) && Math.Truncate(num3) < Math.Truncate(num4)) || (base.Symbol.Digits == 5 && Math.Truncate(num3 * 100.0) < Math.Truncate(num5 * 100.0));
if (num < 1 && flag)
@elodie
cAlgoFx
31 May 2013, 12:51 ( Updated at: 21 Dec 2023, 09:20 )
A test version of the Significant Level robot has been released.
You have to enable a trade condition(Bounce / Break as highlighted below) or both by setting them to 1.
We will release a later version with our trading strategy.
Please inform us of the features you will like to see in the robot.
calgofx.com
Happy hunting
@cAlgoFx