//Long Conditions
if (Position.MarketPosition == MarketPosition.Flat)
// Other conditions here
{
EnterLong();
state = 1
}
//Set TP & SL Targets
if ((Position.MarketPosition == MarketPosition.Long)
&& (state == 1))
{
MyStop = (Low[0] + (-10 * TickSize)) ;
MyProfit = (Position.AveragePrice + (10 * TickSize)) ;
state = 2;
}
//Submit Exit order
if (Position.MarketPosition == MarketPosition.Long)
&& (state == 2))
{
ExitLong();
}
What's the best way to adapt this code to work with OnBarClose?

Comment