pine-scriptpine-script-v5tradingview-apitradingpine-script-v4

Custom volume indicator for future indices volume above 50K show in spot indices


I want to see future indices volume in the Spot chart with customized volume only above 50K. For this, I made the script. It's working fine in future charts however volume bars are not getting highlighted in the spot chart as required.

what am I doing wrong?

Result with current code in spot chart:

Above threshold volume bars are not getting highlighted

enter image description here

Required result in spot chart:

enter image description here

the script:

//@version=4
study("Banknifty volume",resolution="",format=format.volume)

Averageval1 = input(title='Average Volume BankNifty', defval=50, minval=1)
string i_maType2 = syminfo.prefix + ":" + syminfo.ticker
hi_vol= i_maType2=="NSE:BANKNIFTY1!"?Averageval1 * 1000:na

a= security("NSE:Banknifty1!",timeframe.period, volume)

/// Marking bull bear

Bear= input(defval = color.new(color.red,0), title = "Bearish", group = "Colors")
Bull= input(defval = color.new(color.green,0), title = "Bullish", group = "Colors")
std=input(defval = color.new(#d1d4dc,0), title = "Std Bull", group = "Colors")

colorofbar = open < close and volume>hi_vol? Bull:open > close and volume>hi_vol? 
Bear:std

plot(a, color = colorofbar, style=plot.style_columns, title="Banknifty volume")

Solution

  • I was working on something similar on version 5 check it out

        // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © Codex Maximus
    
    //@version=5
    indicator("BNF VOL ON SPOT")
    avgvol = input(title = "Avg volume for BNF",defval = 50000)
    barcolor = color.gray
    
    //get volume of banknifty
    bnffutvol = request.security("NSE:BANKNIFTY1!",timeframe.period,volume)
    
    //BULL AND BEAR CANDLE
    bull = open < close and bnffutvol > avgvol
    bear = open > close and bnffutvol > avgvol
    
    //define geater than 50k parameter
    abvavgerage = bull ? color.green : color.gray
    
    //check whether bull or bear 
    if bull
        barcolor := color.green
    else if bear
        barcolor := color.red
    else
        barcolor := color.gray
    
    
    plot(bnffutvol,style = plot.style_columns, color = barcolor)