Search code examples
pine-scriptpine-script-v5pine-script-v4forex

Enter Pip offset for a line


The code below draws the previous days high and low. I want to be able to enter a offset, I want to enter X number of pips so that high line is (high + X) and the low line is (low - X). Thanks for the help.

study(title="Daily High/Low", shorttitle="Daily High/Low", overlay=true)
active = input(true, title="Show On Chart")
pricehigh = security(tickerid, 'D', high[1])
pricelow = security(tickerid, 'D', low[1])
//Daily Plots
offs_daily = 0 
plot(active and pricehigh ? pricehigh : na, title="Previous Daily High", style=linebr, linewidth=2, color=white)
plot(active and pricelow ? pricelow : na, title="Previous Daily Low", style=linebr, linewidth=2, color=white)

Solution

  • Example:

    nb_pips = input(10, "Nb Pips")
    pip() => syminfo.mintick * (syminfo.type == "forex" ? 10 : 1)
    
    plot(active and pricehigh ? pricehigh + (nb_pips * pip()) : na, title="Previous Daily High", style=linebr, linewidth=2, color=white)
    plot(active and pricelow ? pricelow - (nb_pips * pip()) : na, title="Previous Daily Low", style=linebr, linewidth=2, color=white)