Search code examples
tradingview-api

Tradingview Pine Script to manually input horizontal price levels


I'm trying to create a simple script to manually plot 5 horizontal price levels for SpotGamma levels(Key Gamma, Key Delta, Put Wall, Call Wall, and Hedge Wall).

I'm not a coder but I've done well in the past taking existing code for another study and tweaking it for my purposes.

Really just need the ability to change line style, make it extend all the way to the right, and to remove the colon on the label.

I have a script for this in ToS but I'm moving away from charting on ToS and on to TradingView.

Any help would be appreciated.

This is the current code I'm working with:

study(" ", shorttitle="", overlay = true)

//Levels

c_level1 = input(1, "KEY GAMMA", type=input.float)
c_level2 = input(1, "KEY DELTA", type=input.float)
c_level3 = input(1, "HEDGE WALL", type=input.float)
c_level4 = input(1, "CALL WALL", type=input.float)
c_level5 = input(1, "PUT WALL", type=input.float)

// Levels

plot(c_level1, title = "KEY GAMMA", color = #007bff, linewidth = 2)
plot(c_level2, title = "KEY DELTA", color = #f2ff00, linewidth = 2)
plot(c_level3, title = "HEDGE WALL", color = #ff00a2, linewidth = 2)
plot(c_level4, title = "CALL WALL", color = #00ff08, linewidth = 2)
plot(c_level5, title = "PUT WALL", color = #ff0000, linewidth = 2)

Solution

  • Use hline instead of plot to draw extended lines.

    Here is a Pine v5 version of your script:

    //@version=5
    
    indicator("hlines", overlay = true)
    
    // Inputs
    
    c_level1 = input.float(20000, "KEY GAMMA")
    c_level2 = input.float(22000, "KEY DELTA")
    c_level3 = input.float(24000, "HEDGE WALL")
    c_level4 = input.float(26000, "CALL WALL")
    c_level5 = input.float(28000, "PUT WALL")
    
    // Plots
    
    hline(c_level1, title = "KEY GAMMA", color = #007bff, linewidth = 2, linestyle = hline.style_solid)
    hline(c_level2, title = "KEY DELTA", color = #f2ff00, linewidth = 2, linestyle = hline.style_solid)
    hline(c_level3, title = "HEDGE WALL", color = #ff00a2, linewidth = 2, linestyle = hline.style_solid)
    hline(c_level4, title = "CALL WALL", color = #00ff08, linewidth = 2, linestyle = hline.style_solid)
    hline(c_level5, title = "PUT WALL", color = #ff0000, linewidth = 2, linestyle = hline.style_solid)
    

    View Screenshot