Не работает TakeProfitStopLossStrategy
Уже в 3ий раз пишу о том что не работает TakeProfitStopLossStrategy.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Ecng.Collections;
using Ecng.Common;
namespace StockSharp
{
using StockSharp.Quik;
using StockSharp.Algo;
using StockSharp.Algo.Candles;
using StockSharp.Algo.Strategies;
using StockSharp.BusinessEntities;
internal sealed class MyStrategy : Strategy
{
private readonly MarketDepth _depth;
public MyStrategy(MarketDepth marketDepth)
{
_depth = marketDepth;
}
protected override void OnStarted()
{
_depth
.WhenChanged()
.Do(ProccesDepth)
.Apply(this);
base.OnStarted();
}
protected override void OnStopping()
{
try
{
CancelActiveOrders();
}
catch (Exception ex)
{
MessageBox.Show("Заявки в процессе отмены {0}".Put(ex));
}
base.OnStopping();
}
private void ProccesDepth()
{
var bids = _depth.Bids.Max().Volume;
var asks = _depth.Asks.Max().Volume;
bool isBuyDirection = bids > asks;
var order = new Order
{
Price = isBuyDirection ? _depth.BestBid.Price : _depth.BestAsk.Price,
Direction = isBuyDirection ? OrderDirections.Buy : OrderDirections.Sell,
Type = OrderTypes.Limit,
Volume = 1,
Comment = "Вход",
};
order
.WhenNewTrades()
.Do(SetProtectedOrders)
.Apply(this);
RegisterOrder(order);
}
private void SetProtectedOrders(IEnumerable<MyTrade> myTrades)
{
// для каждой сделки добавляем защитную пару стратегии
var protectiveStrategies = myTrades.Select(t =>
{
// выставляет тейк-профит в 40 пунктов
var takeProfit = new TakeProfitStrategy(t, 50);
// выставляет стоп-лосс в 20 пунктов
var stopLoss = new StopLossStrategy(t, 20);
return new TakeProfitStopLossStrategy(takeProfit,
stopLoss);
});
ChildStrategies.AddRange(protectiveStrategies);
}
}
}
В коде использовался пример из документации, и не сработал :)
Вход и не сработавший 20пт стоп:

Позиции:

Ордера:

Т.е. ордера пытаются выставится, но сразу же отменяются, и второй раз уже не работают, т.к. срабатывание единоразовое.
В то что все работает правильно, как-то не верится :)