﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.ru/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.ru/css/bbeditor.css'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">StopLossTakeProfitStrategy for Binance</title>
  <id>~/topic/16244/stoplosstakeprofitstrategy-for-binance/</id>
  <rights type="text">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  <updated>2026-04-14T23:20:33Z</updated>
  <logo>https://stocksharp.ru/images/logo.png</logo>
  <link href="https://stocksharp.ru/handlers/atom.ashx?category=topic&amp;id=16244" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.ru/posts/m/58033/</id>
    <title type="text">Dear developers, I have a problem when I try to use StopLossTakeProfitStrategy. I&amp;apos;m using HistoryEmu...</title>
    <published>2022-01-21T05:10:34Z</published>
    <updated>2022-01-21T05:10:34Z</updated>
    <author>
      <name>Mohammadreza Heidari</name>
      <uri>https://stocksharp.ru/users/162027/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">Dear developers,&lt;br /&gt;&lt;br /&gt;I have a problem when I try to use StopLossTakeProfitStrategy. I&amp;#39;m using HistoryEmulationConnector with my Binance downloaded History Candles.&lt;br /&gt;&lt;br /&gt;The code is as per below:&lt;br /&gt;&lt;br /&gt;Configurations for Security, Portfolio and Connector is as per below:&lt;br /&gt;&lt;div class="code"&gt;&lt;strong&gt;Код&lt;/strong&gt;&lt;div class="innercode"&gt;&lt;br /&gt;            _security = new Security&lt;br /&gt;            {&lt;br /&gt;                Id = &amp;quot;BTCUSDT_PERPETUAL@BNB&amp;quot;,&lt;br /&gt;                Code = &amp;quot;BTCUSDT&amp;quot;,&lt;br /&gt;                PriceStep = 0.01m,&lt;br /&gt;                Board = ExchangeBoard.Binance,&lt;br /&gt;                VolumeStep = 0.01M&lt;br /&gt;            };&lt;br /&gt;&lt;br /&gt;            //.................initialize portfolio...................&lt;br /&gt;            _portfolio = new Portfolio { Name = &amp;quot;test account&amp;quot;, BeginValue = 1000 };&lt;br /&gt;            var storageRegistry = new StorageRegistry&lt;br /&gt;            {&lt;br /&gt;                DefaultDrive = new LocalMarketDataDrive(_pathHistory),&lt;br /&gt;            };&lt;br /&gt;&lt;br /&gt;            //.................initialize connector...................&lt;br /&gt;            _connector = new HistoryEmulationConnector(new&amp;#91;&amp;#93; { _security }, new&amp;#91;&amp;#93; { _portfolio })&lt;br /&gt;            {&lt;br /&gt;                HistoryMessageAdapter =&lt;br /&gt;                {&lt;br /&gt;                    StorageRegistry = storageRegistry,&lt;br /&gt;                    StorageFormat = StorageFormats.Binary,&lt;br /&gt;                    StartDate = DatePickerBegin.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),&lt;br /&gt;                    StopDate = DatePickerEnd.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),&lt;br /&gt;                },&lt;br /&gt;                LogLevel = LogLevels.Info,&lt;br /&gt;            };&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The code with which I try to Buy and Set SL and TP is as per below:&lt;br /&gt;&lt;div class="code"&gt;&lt;strong&gt;Код&lt;/strong&gt;&lt;div class="innercode"&gt;&lt;br /&gt;                        var order = this.BuyAtMarket(0.01M);&lt;br /&gt;                        order.WhenNewTrade(Connector).Do(NewOrderTrade).Until(() =&amp;gt; order.State == OrderStates.Done).Apply(this);&lt;br /&gt;                        ChildStrategies.ToList().ForEach(child =&amp;gt; child.Stop());&lt;br /&gt;                        RegisterOrder(order);&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And here is the method in which I specified StopLoss and TakeProfit:&lt;br /&gt;&lt;div class="code"&gt;&lt;strong&gt;Код&lt;/strong&gt;&lt;div class="innercode"&gt;&lt;br /&gt;        private void NewOrderTrade(StockSharp.BusinessEntities.MyTrade mytrade)&lt;br /&gt;        {&lt;br /&gt;            var takeProfit = new TakeProfitStrategy(mytrade, 20)&lt;br /&gt;            {&lt;br /&gt;                WaitAllTrades = true,&lt;br /&gt;            };&lt;br /&gt;            var stopLoss = new StopLossStrategy(mytrade, 20)&lt;br /&gt;            {&lt;br /&gt;                WaitAllTrades = true,&lt;br /&gt;            };&lt;br /&gt;&lt;br /&gt;            var protectiveStrategies = new TakeProfitStopLossStrategy(takeProfit, stopLoss)&lt;br /&gt;            {&lt;br /&gt;                WaitAllTrades = true,&lt;br /&gt;            };&lt;br /&gt;            ChildStrategies.Add(protectiveStrategies);&lt;br /&gt;        }&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The problem is when I start the strategy there are buy and sell orders but non of StopLoss or TakeProfit executes.&lt;br /&gt;&lt;br /&gt;And for more information, I attached the Log info after execution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
</feed>