'Number of bullish candles across USD for a given timeperiod

For a backtesting study I need to know how many of the most recent closed candles are bullish across USD for a given timeperiod. That is, how many of the most recent closed candles of AUDUSD, USDCAD, EURUSD, GBPUSD, USDJPY, NZDUSD closed approx. at the top of each candle (i.e. with a very little wick or no wick at all), e.g. 4 out of the 6 just mentioned. How could I code this? Below are mentioned (some of) the steps I believe is needed:

//@version=4
study(title="test", overlay=false)

timeperiod = "5"

v1 = security("OANDA:AUDUSD", timeframe.period, close)
v2 = security("OANDA:USDCAD", timeframe.period, close)
v3 = security("OANDA:EURUSD", timeframe.period, close)
v4 = security("OANDA:GBPUSD", timeframe.period, close)
v5 = security("OANDA:USDJPY", timeframe.period, close)
v6 = security("OANDA:NZDUSD", timeframe.period, close)

// Identification of bullish candle
// ...
// ...
closeHigherV1 = v1(close > close[1])
        
// Initilization
var bullishCandleCount = 0 
    
// Sum of bullish candles
bullishCandleCount += 1


Solution 1:[1]

//@version=4
study(title="test", overlay=false)

v1Open = security("OANDA:AUDUSD", timeframe.period, open)
v1Close = security("OANDA:AUDUSD", timeframe.period, close)
v2Open = security("OANDA:USDCAD", timeframe.period, open)
v2Close = security("OANDA:USDCAD", timeframe.period, close)
v3Open = security("OANDA:EURUSD", timeframe.period, open)
v3Close = security("OANDA:EURUSD", timeframe.period, close)
v4Open = security("OANDA:GBPUSD", timeframe.period, open)
v4Close = security("OANDA:GBPUSD", timeframe.period, close)
v5Open = security("OANDA:USDJPY", timeframe.period, open)
v5Close = security("OANDA:USDJPY", timeframe.period, close)
v6Open = security("OANDA:NZDUSD", timeframe.period, open)
v6Close = security("OANDA:NZDUSD", timeframe.period, close)

// Identification of bullish candle
closeHigherV1 = v1Open[1] > v1Close[1]
closeHigherV2 = v2Open[1] > v2Close[1]
closeHigherV3 = v3Open[1] > v3Close[1]
closeHigherV4 = v4Open[1] > v4Close[1]
closeHigherV5 = v5Open[1] > v5Close[1]
closeHigherV6 = v6Open[1] > v6Close[1]
        
// Sum of bullish candles
bullishCandleCount = (closeHigherV1 ? 1 : 0) + 
                     (closeHigherV2 ? 1 : 0) + 
                     (closeHigherV3 ? 1 : 0) + 
                     (closeHigherV4 ? 1 : 0) + 
                     (closeHigherV5 ? 1 : 0) + 
                     (closeHigherV6 ? 1 : 0)

plot(bullishCandleCount)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1