StopLossTakeProfitStrategy for Binance~/topic/16244/stoplosstakeprofitstrategy-for-binance/Copyright @ StockSharp Platform LLC 2010 - 20242024-03-29T11:10:36Zhttps://stocksharp.com/images/logo.pnghttps://stocksharp.com/posts/m/58033/Dear developers, I have a problem when I try to use StopLossTakeProfitStrategy. I'm using HistoryEmu...2022-01-21T05:10:34Z2022-01-21T05:10:34ZMohammadreza Heidarihttps://stocksharp.com/users/162027/info@stocksharp.comDear developers,<br /><br />I have a problem when I try to use StopLossTakeProfitStrategy. I'm using HistoryEmulationConnector with my Binance downloaded History Candles.<br /><br />The code is as per below:<br /><br />Configurations for Security, Portfolio and Connector is as per below:<br /><div class="code"><strong>Code</strong><div class="innercode"><br /> _security = new Security<br /> {<br /> Id = "BTCUSDT_PERPETUAL@BNB",<br /> Code = "BTCUSDT",<br /> PriceStep = 0.01m,<br /> Board = ExchangeBoard.Binance,<br /> VolumeStep = 0.01M<br /> };<br /><br /> //.................initialize portfolio...................<br /> _portfolio = new Portfolio { Name = "test account", BeginValue = 1000 };<br /> var storageRegistry = new StorageRegistry<br /> {<br /> DefaultDrive = new LocalMarketDataDrive(_pathHistory),<br /> };<br /><br /> //.................initialize connector...................<br /> _connector = new HistoryEmulationConnector(new[] { _security }, new[] { _portfolio })<br /> {<br /> HistoryMessageAdapter =<br /> {<br /> StorageRegistry = storageRegistry,<br /> StorageFormat = StorageFormats.Binary,<br /> StartDate = DatePickerBegin.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),<br /> StopDate = DatePickerEnd.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),<br /> },<br /> LogLevel = LogLevels.Info,<br /> };<br /></div></div><br /><br /><br />The code with which I try to Buy and Set SL and TP is as per below:<br /><div class="code"><strong>Code</strong><div class="innercode"><br /> var order = this.BuyAtMarket(0.01M);<br /> order.WhenNewTrade(Connector).Do(NewOrderTrade).Until(() => order.State == OrderStates.Done).Apply(this);<br /> ChildStrategies.ToList().ForEach(child => child.Stop());<br /> RegisterOrder(order);<br /></div></div><br /><br /><br /><br />And here is the method in which I specified StopLoss and TakeProfit:<br /><div class="code"><strong>Code</strong><div class="innercode"><br /> private void NewOrderTrade(StockSharp.BusinessEntities.MyTrade mytrade)<br /> {<br /> var takeProfit = new TakeProfitStrategy(mytrade, 20)<br /> {<br /> WaitAllTrades = true,<br /> };<br /> var stopLoss = new StopLossStrategy(mytrade, 20)<br /> {<br /> WaitAllTrades = true,<br /> };<br /><br /> var protectiveStrategies = new TakeProfitStopLossStrategy(takeProfit, stopLoss)<br /> {<br /> WaitAllTrades = true,<br /> };<br /> ChildStrategies.Add(protectiveStrategies);<br /> }<br /></div></div><br /><br /><br />The problem is when I start the strategy there are buy and sell orders but non of StopLoss or TakeProfit executes.<br /><br />And for more information, I attached the Log info after execution.<br /><br /><br />Copyright @ StockSharp Platform LLC 2010 - 2024