i have an issue using setstoploss in onbarupdate method.
what i am trying to do is if i am in a long position and the current bar closes upwards i want my stoploss be placed or changed to the low of the current bar - vice versa for a short position.
i am using the following code in onbarupdate:
if (Position.MarketPosition == MarketPosition.Short)
{
Print("Short");
if (Close[0] < Open[0])
{
SetStopLoss(CalculationMode.Price, High[0] + TickSize);
Print("Close < Open - High[0] " + High[0]);
}
}
if (Position.MarketPosition == MarketPosition.Long)
{
Print("Long");
if (Close[0] > Open[0])
{
SetStopLoss(CalculationMode.Price, Low[0] - TickSize);
Print("Close > Open - Low[0] " + Low[0]);
}
}
P.S. code is called on bar close
Cannot understand why its not working - the print statements are called correctly
Thanks in advance

Comment