AM
Topics
Replies
amantalpur007@gmail.com
09 Jul 2017, 19:09
RE:
HI, i want sample martingale cbot to stop doubling my position after 5 consecutive loses. please tell me the coding to do so. i shall be really really grateful to you lucian.
lucian said:
Try backtest with:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class PTrader : Robot { [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)] public int InitialVolume { get; set; } [Parameter("Stop Loss", DefaultValue = 40)] public int StopLoss { get; set; } [Parameter("Take Profit", DefaultValue = 40)] public int TakeProfit { get; set; } [Parameter("Start hour", DefaultValue = 11)] public int _start_hour { get; set; } [Parameter("End Hour", DefaultValue = 18)] public int _end_hour { get; set; } public bool trigger; private Random random = new Random(); protected override void OnStart() { trigger = false; Positions.Closed += OnPositionsClosed; } protected override void OnTick() { if ((Server.Time.Hour == _start_hour) && (Positions.Count == 0) && (!trigger)) { ExecuteOrder(InitialVolume, GetRandomTradeType()); trigger = true; } } private void ExecuteOrder(long volume, TradeType tradeType) { var result = ExecuteMarketOrder(tradeType, Symbol, volume, "Martingale", StopLoss, TakeProfit); if (result.Error == ErrorCode.NoMoney) Stop(); } private void OnPositionsClosed(PositionClosedEventArgs args) { if (Server.Time.Hour > _start_hour) { trigger = false; } var position = args.Position; if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code) return; if ((Server.Time.Hour >= _start_hour) && (Server.Time.Hour < _end_hour)) { if (position.GrossProfit > 0) { ExecuteOrder(InitialVolume, GetRandomTradeType()); } else { ExecuteOrder((int)position.Volume * 2, position.TradeType); } } } private TradeType GetRandomTradeType() { return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell; } } }
@amantalpur007@gmail.com
amantalpur007@gmail.com
09 Jul 2017, 19:30
RE: RE:
HI, i use Sample MArtingale Cbot. in that cbot. i want this cbot to stop doubling my postion after 5 consecutive loses. please tell me the code to do so. i saw your comment and in that comment you've added MAs. i just want to add a setting so that cbot stops doubling after 5 consecutive loses. my email is amantalpur007@gmail.com. i've inserted code of that cbot. please write the whole coding including my need. i shall be really grateful to you.
tradermatrix said:
@amantalpur007@gmail.com