Search code examples
pine-scriptpine-script-v4

Plot a custom volume over candles in tradingview


In Tradingview - I would like to plot a volume overlay over the candles - but the code below does not scale the volume bars in their own y-axis scale.

Therefore, the volume bars only show and the candles do not.

//@version=3
study("Candles", overlay=false) 

plotcandle(open*2,high*2,low*2,close*2, title="Candles", color = close>=open ? green : red, wickcolor=black)

plot(series=volume*2, style=columns, color = close>=open ? green : red, transp=80)

Thanks


Solution

  • The script could be assigned only to 1 single y axis. In pinescript version4 you can control it with scale argument of the study function.

    In your example the difference in values won't let you visualize candles + volume bars correctly, you have to create two separate scripts as in the example below.

    //@version=4
    study("Volume on the left scale", overlay=false, scale = scale.left) 
    
    plot(series=volume*2, style=plot.style_columns, color = close>=open ? color.green : color.red, transp=80)
    

    //@version=4
    study("Candles on the right scale", overlay=false) 
    
    plotcandle(open*2,high*2,low*2,close*2, title="Candles", color = close>=open ? color.green : color.red, wickcolor=color.black)
    

    enter image description here