I’ve incorporated the following code into my script which is faily much the same as yours. I have found a couple of issues which I hope you could shed some light on….
1) In my script which I have incorporated SetStopLoss, within the entry conditions I have BarSinceExit() > 1, and this works without problem with other exit conditions, except for SetStopLoss. After a SetStopLoss has been executed, another entry can be executed immediately in the same bar without waiting for the next bar.
Is this an issue with SetStopLoss, and is there a way around this?
2) I have also noticed in the output window that the nested SetStopLoss code loops quite intensively, and although it works, my PC performance has taken a hit! Are there inefficiencies in the code I have not seen?
Thanks in advance….
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss("", CalculationMode.Ticks, FixedStop, true);
}
elseif (Position.MarketPosition == MarketPosition.Long)
{
if (High[0] > Position.AvgPrice + 10 * TickSize)
{
SetStopLoss("", CalculationMode.Price, (Position.AvgPrice - 20), true);
}
if (High[0] > Position.AvgPrice + 40 * TickSize)
{
SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 18), true);
}
if (High[0] > Position.AvgPrice + 65 * TickSize)
{
SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 50), true);
}
if (High[0] > Position.AvgPrice + 100 * TickSize)
{
SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 80), true);
}
Comment