I have been modifying the 20/50 SMA cross over so I can use the ATR or ATR multiple as the distance for my stop loss. It works fine apart from the ATR variable doesnt read into the script.
When I hard code a value in the Trailing stop method it works fine but when I use the ATR forumula and assign it to a variable and put that variable into the Trailing Stop method it doesnt work at all - the trailing stop method reads it as 1 or 0.
Heres my code. I have tried putting the code in both the initialize and onBarUpdate method but neither work.
protected override void Initialize() { SMA(Fast).Plots[0].Pen.Color = Color.Red; SMA(Slow).Plots[0].Pen.Color = Color.Green; Add(SMA(Fast)); Add(SMA(Slow)); CalculateOnBarClose = true; //Trailing stop and ATR code double value = ATR(14)[0]; double TrailingSL = High[0] - value; SetTrailStop(CalculationMode.Ticks, TrailingSL); }
Thanks
Mike
Comment