xmd79

45 Degree Angle from Last Low/High

May 29th, 2023
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. //@version=4
  2. study("45 Degree Angle from Last Low/High", overlay=true)
  3.  
  4. // Determine whether the last point was a high or low
  5. lastHigh = highest(high, 500)
  6. lastLow = lowest(low, 500)
  7. lastPoint = bar_index - nz(max(lastLow, lastHigh))
  8.  
  9. // Calculate the slope of the line
  10. slope = 1
  11.  
  12. // Calculate the y-intercept of the line
  13. yIntercept = lastHigh - slope * (bar_index - lastPoint)
  14.  
  15. // Calculate the 45-degree angle line using the formula y = x
  16. angleLine = bar_index - lastPoint
  17.  
  18. // Plot the angle line
  19. plot(angleLine + yIntercept,
  20. color=color.new(color.green, 0),
  21. style=plot.style_line,
  22. show_last=1,
  23. linewidth=1,
  24. trackprice=true,
  25. transp=0)
  26.  
  27. // Extend the angle line into the future
  28. futureAngleLine = angleLine + (bar_index - lastPoint) * 2 // Change the multiplier to adjust the length of the projected line
  29.  
  30. // Plot the future angle line
  31. plot(futureAngleLine + yIntercept,
  32. color=color.new(color.yellow, 0),
  33. style=plot.style_line,
  34. show_last=1,
  35. linewidth=2,
  36. trackprice=true,
  37. transp=0)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment