♥ 0 |
I am trying to script a dynamic trailing stop on a daily chart. I can plot the current price with a horizontal line and plot a second line to follow as the price rises and falls. What I can’t figure out is how to get the second line to stop when the current price line falls. Any help would be greatly appreciated. Here is the code I have written so far: input StopDiff = 00.00; def Diff = StopDiff; def vClose = close; def nan = double.NaN; def highestClose = HighestAll(if IsNaN(vClose[-1]) then highest (vClose) else nan); plot hc = highestClose; hc.SetPaintingStrategy(PaintingStrategy.Horizontal); hc.SetDefaultColor(Color.DARK_GREEN); hc.SetLineWeight(2); hc.HideBubble(); hc.HideTitle(); def TrailingStop = if high<=(hc) then (hc)-Diff else high – diff; plot TS = hc-Diff; TS.SetPaintingStrategy(PaintingStrategy.Horizontal); TS.SetDefaultColor(Color.Blue); TS.SetLineWeight(2);
Marked as spam
|
Please log in to post questions.