Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to draw a line x pips above or below close price in trading view pine script?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading