I've been working on coding my strategy in order to backtest it. I'm trying to simulate a trailing stop on my last lot ("Long1c") so that my SetStopLoss trails the price by 50 ticks. Since I'm new to coding, I can't figure out what the errors mean or how to fix the issue. Any help would be much appreciated! Here is that section of code:
// If a short position is open, allow for stop loss modification to breakeven
elseif (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+40 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 40 * TickSize)
{
SetStopLoss("Long1b", CalculationMode.Price, Position.AvgPrice, true);
SetStopLoss("Long1c", CalculationMode.Price, Position.AvgPrice, true);
}
if (Close[0] > Position.AvgPrice + 60 * TickSize)
SetStopLoss("Long1c", CalculationMode.Price, Position.AvgPrice + 10 * TickSize, true);
for (Position.AvgPrice + 60; Position.AvgPrice + 60 < 100; Position.AvgPrice + 60++)
{
SetStopLoss("Long1c", CalculationMode.Price, Position.AvgPrice + 10++ * TickSize, true);
}
My biggest issue, I think, is how to reference the price in a way that the SetStopLoss could follow behind and yet not lose ground. I'm pretty sure that my way of referencing it is wrong... perhaps I'm approaching the situation wrong all together?
Also, since I'm not trying to automate the strategy, does that change the way it needs to be addressed?
Thank you for any help that you can give!

Comment