Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('Normalized 45 Degree Angle Line', overlay=true)
- // Determine starting point
- lowest_1 = ta.lowest(low, 50)
- startPrice = lowest_1 == low ? low[50] : high[50]
- // Calculate angle line
- angleLine = startPrice + (close[1] - startPrice) * math.sqrt(2)
- // Normalize angle line
- chartMin = ta.lowest(low, 50)
- chartMax = ta.highest(high, 50)
- normalizedAngleLine = (angleLine - chartMin) / (chartMax - chartMin)
- scaledAngleLine = chartMin + normalizedAngleLine * (chartMax - chartMin)
- // Plot angle line
- plot(scaledAngleLine, color=color.new(color.blue, 0), style=plot.style_line)
- // Define targets
- target1 = angleLine + angleLine - startPrice
- target2 = angleLine + (angleLine - startPrice) * 2
- // Normalize targets
- normalizedTarget1 = (target1 - chartMin) / (chartMax - chartMin)
- scaledTarget1 = chartMin + normalizedTarget1 * (chartMax - chartMin)
- normalizedTarget2 = (target2 - chartMin) / (chartMax - chartMin)
- scaledTarget2 = chartMin + normalizedTarget2 * (chartMax - chartMin)
- // Plot targets
- plot(scaledTarget1, color=color.new(color.green, 0), style=plot.style_line)
- plot(scaledTarget2, color=color.new(color.red, 0), style=plot.style_line)
- // Add labels to targets
- label.new(bar_index, scaledTarget1, 'Target 1', xloc=xloc.bar_index, yloc=scaledTarget1 > scaledAngleLine ? yloc.abovebar : yloc.belowbar, color=color.green)
- label.new(bar_index, scaledTarget2, 'Target 2', xloc=xloc.bar_index, yloc=scaledTarget2 > scaledAngleLine ? yloc.abovebar : yloc.belowbar, color=color.red)
Advertisement
Add Comment
Please, Sign In to add comment