xmd79

Normalized 45 Degree Angle Line

May 6th, 2023
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. //@version=5
  2. indicator('Normalized 45 Degree Angle Line', overlay=true)
  3.  
  4. // Determine starting point
  5. lowest_1 = ta.lowest(low, 50)
  6. startPrice = lowest_1 == low ? low[50] : high[50]
  7.  
  8. // Calculate angle line
  9. angleLine = startPrice + (close[1] - startPrice) * math.sqrt(2)
  10.  
  11. // Normalize angle line
  12. chartMin = ta.lowest(low, 50)
  13. chartMax = ta.highest(high, 50)
  14. normalizedAngleLine = (angleLine - chartMin) / (chartMax - chartMin)
  15. scaledAngleLine = chartMin + normalizedAngleLine * (chartMax - chartMin)
  16.  
  17. // Plot angle line
  18. plot(scaledAngleLine, color=color.new(color.blue, 0), style=plot.style_line)
  19.  
  20. // Define targets
  21. target1 = angleLine + angleLine - startPrice
  22. target2 = angleLine + (angleLine - startPrice) * 2
  23.  
  24. // Normalize targets
  25. normalizedTarget1 = (target1 - chartMin) / (chartMax - chartMin)
  26. scaledTarget1 = chartMin + normalizedTarget1 * (chartMax - chartMin)
  27. normalizedTarget2 = (target2 - chartMin) / (chartMax - chartMin)
  28. scaledTarget2 = chartMin + normalizedTarget2 * (chartMax - chartMin)
  29.  
  30. // Plot targets
  31. plot(scaledTarget1, color=color.new(color.green, 0), style=plot.style_line)
  32. plot(scaledTarget2, color=color.new(color.red, 0), style=plot.style_line)
  33.  
  34. // Add labels to targets
  35. label.new(bar_index, scaledTarget1, 'Target 1', xloc=xloc.bar_index, yloc=scaledTarget1 > scaledAngleLine ? yloc.abovebar : yloc.belowbar, color=color.green)
  36. label.new(bar_index, scaledTarget2, 'Target 2', xloc=xloc.bar_index, yloc=scaledTarget2 > scaledAngleLine ? yloc.abovebar : yloc.belowbar, color=color.red)
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment