I am building an strategy that places two market orders with their respective stoploss. I want one of the two orders to be issued when it has reached a certain price and the other when it meets a certain coded condition, according to the following script:
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss (@"Compra1", CalculationMode.Price, stop, false);
SetStopLoss (@"Compra2", CalculationMode.Price, stop, false);
SetProfitTarget (@"Compra1", CalculationMode.Price, objetivo);
EnterLong (@"Compra1");
EnterLong (@"Compra2");
}
if (/*condition*/)
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"Salida1", @"Compra2");
}
I have also tried the following alternative, but when the Target of one of the positions is executed and the logic of the strategy triggers an entry again, it adds another new position to the existing one, which is something I want to avoid:
{
SetStopLoss (@"Compra1", CalculationMode.Price, stop, false);
SetStopLoss (@"Compra2", CalculationMode.Price, stop, false);
SetProfitTarget (@"Compra1", CalculationMode.Price, objetivo);
EnterLong (@"Compra1");
EnterLong (@"Compra2");
}
if (/*condition*/)
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"Salida1", @"Compra2");
}
that's the reason why I added the if (Position.MarketPosition == MarketPosition.Flat) sentence but it doesn´t work as I explained in the begining of the message.
How could I code it properly?
Thanks in advance!

Comment