﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/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-06-17T09:40:51Z</updated>
  <logo>https://stocksharp.com/images/logo.png</logo>
  <link href="https://stocksharp.com/handlers/atom.ashx?category=topic&amp;id=16244" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.com/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.com/users/162027/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;p&gt;Dear developers,&lt;/p&gt;
&lt;p&gt;I have a problem when I try to use StopLossTakeProfitStrategy. I'm using HistoryEmulationConnector with my Binance downloaded History Candles.&lt;/p&gt;
&lt;p&gt;The code is as per below:&lt;/p&gt;
&lt;p&gt;Configurations for Security, Portfolio and Connector is as per below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
            _security = new Security
            {
                Id = &amp;quot;BTCUSDT_PERPETUAL@BNB&amp;quot;,
                Code = &amp;quot;BTCUSDT&amp;quot;,
                PriceStep = 0.01m,
                Board = ExchangeBoard.Binance,
                VolumeStep = 0.01M
            };

            //.................initialize portfolio...................
            _portfolio = new Portfolio { Name = &amp;quot;test account&amp;quot;, BeginValue = 1000 };
            var storageRegistry = new StorageRegistry
            {
                DefaultDrive = new LocalMarketDataDrive(_pathHistory),
            };

            //.................initialize connector...................
            _connector = new HistoryEmulationConnector(new[] { _security }, new[] { _portfolio })
            {
                HistoryMessageAdapter =
                {
                    StorageRegistry = storageRegistry,
                    StorageFormat = StorageFormats.Binary,
                    StartDate = DatePickerBegin.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),
                    StopDate = DatePickerEnd.SelectedDate.Value.ChangeKind(DateTimeKind.Utc),
                },
                LogLevel = LogLevels.Info,
            };

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The code with which I try to Buy and Set SL and TP is as per below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
                        var order = this.BuyAtMarket(0.01M);
                        order.WhenNewTrade(Connector).Do(NewOrderTrade).Until(() =&amp;gt; order.State == OrderStates.Done).Apply(this);
                        ChildStrategies.ToList().ForEach(child =&amp;gt; child.Stop());
                        RegisterOrder(order);

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And here is the method in which I specified StopLoss and TakeProfit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
        private void NewOrderTrade(StockSharp.BusinessEntities.MyTrade mytrade)
        {
            var takeProfit = new TakeProfitStrategy(mytrade, 20)
            {
                WaitAllTrades = true,
            };
            var stopLoss = new StopLossStrategy(mytrade, 20)
            {
                WaitAllTrades = true,
            };

            var protectiveStrategies = new TakeProfitStopLossStrategy(takeProfit, stopLoss)
            {
                WaitAllTrades = true,
            };
            ChildStrategies.Add(protectiveStrategies);
        }

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem is when I start the strategy there are buy and sell orders but non of StopLoss or TakeProfit executes.&lt;/p&gt;
&lt;p&gt;And for more information, I attached the Log info after execution.&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
</feed>