Dear developers,
I have a problem when I try to use StopLossTakeProfitStrategy. I'm using HistoryEmulationConnector with my Binance downloaded History Candles.
The code is as per below:
Configurations for Security, Portfolio and Connector is as per below:
_security = new Security
{
Id = "BTCUSDT_PERPETUAL@BNB",
Code = "BTCUSDT",
PriceStep = 0.01m,
Board = ExchangeBoard.Binance,
VolumeStep = 0.01M
};
//.................initialize portfolio...................
_portfolio = new Portfolio { Name = "test account", 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,
};
The code with which I try to Buy and Set SL and TP is as per below:
var order = this.BuyAtMarket(0.01M);
order.WhenNewTrade(Connector).Do(NewOrderTrade).Until(() => order.State == OrderStates.Done).Apply(this);
ChildStrategies.ToList().ForEach(child => child.Stop());
RegisterOrder(order);
And here is the method in which I specified StopLoss and TakeProfit:
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);
}
The problem is when I start the strategy there are buy and sell orders but non of StopLoss or TakeProfit executes.
And for more information, I attached the Log info after execution.
Kommentare (0)
Anmelden oder Konto erstellen, Melden Sie sich an oder registrieren Sie sich, um einen Kommentar zu hinterlassen
Noch keine Kommentare. Seien Sie der Erste!