I am testing the order methods offered by the Managed Aproach.
I use the method EnterLongStopMarket() to define the entry price for long position. When the order is executed, at the same time should enter two orders; a target (ExitLongLimit) and the stop (ExitLongStopLimit) but it does not work, How can I solve these issues?
Thanks,
Richard Martínez M.
protected override void OnBarUpdate()
{
if (State == State.Historical)
return;
if (CurrentBar < BarsRequiredToTrade)
return;
if (BarsInProgress == 1)
{
if (Position.MarketPosition == MarketPosition.Flat)
{
if (entryOrder != null)
{
if (stopPrice.ApproxCompare(Close[0]) == 1)
{
CancelOrder(entryOrder);
}
}
}
else if (Position.MarketPosition == MarketPosition.Long)
{
if (isEntry)
{
Print("Target Order Position");
ExitLongLimit(targetPrice, "Target", "entryOrder");
Print("Target Order Colocda");
Print("Target Order position");
ExitLongLimit(stopPrice, "Stoploss", "entryOrder");
Print("Stop Order Colocda");
isEntry = false;
}
}
}
if (BarsInProgress == 0)
{
if (Position.MarketPosition == MarketPosition.Flat)
{
if (entryOrder == null && Close[0] > Open[0] && !isEntry)
{
Print("Enter Long Block Start - " + Time[0]);
EnterLongStopMarket(Close[0] + 2 * TickSize, "entryOrder");
barEntry = CurrentBar;
targetPrice = Close[0] + 10 * TickSize;
stopPrice = Close[0] - 5 * TickSize;
isEntry = true;
Print("Enter Long Block End - " + Time[0]);
}
else if (barEntry + 1 == CurrentBar)
{
Print("Cancel Long Block Start - " + Time[0]);
CancelOrder(entryOrder);
isEntry = false;
Print("Cancel Long Block End - " + Time[0]);
}
}
}
}

Comment