How can I create an indicator which is a straight line plus a constant value above it. The idea being that I want to show where my brokers price is compared to the trading view value. So far I’ve only been able to draw a horizontal line:
//@version=5
indicator("Close+Constant", overlay=true)
if barstate.islast
line.new(bar_index[10], close, bar_index, close, width = 2, color = color.blue, extend = extend.both)
But trying to add a constant float to bar_index[10] (for instance) gives a type error, expected int but got float.
Existing solutions result in the same error:
Cannot call 'hline' with argument An argument of 'series float' type was used but a 'input float' is expected
>Solution :
You must add your spread to the Y value in line :
//@version=5
indicator("Close+Constant", overlay=true)
spread = 0.005 // Adjust your spread with the one from your broker
if barstate.islast
line.new(bar_index[10], close + spread, bar_index, close + spread, width = 2, color = color.blue, extend = extend.both)