Pine scripts default behavior is to use the chart bars even on higher time frame security calls. This seems odd to me and it doesn't help my desired use.
When I view my script on charts less than 1 day, the background colors only populate 1 bar at a time. I happens when the condition becomes true even thou it stays true for the rest of the day.
I want to use this on the 1 minute chart as a daily trade filter. In other words, I don't want my scripts to fire when both the market cap and dominance for a coin are down from the previous day.
//@version=6
strategy(title = 'Market Dominance', shorttitle = 'Market Dominance', overlay = false)
viewBTC = input(false, "View BTC Dominance")
viewBTCMinus = input(false, "View BTC Dominance Minus Stable Coins")
viewStable = input(false, "View Stable Coin Dominance (Top 5)")
viewChart = input(false, "View On Chart Coin Dominance")
res = input.timeframe("D", "Timeframe")
src = input.source(hl2, "Source")
length = input(1, "Days of market cap in calculation")
division1 = input("/////", "On chart asset cap - Change if analyzing on chart asset")
chartCap = request.security(input.symbol("CRYPTOCAP:ETH") , res, ta.sma(src, length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
division2 = input("/////", "BTC and Stable Coin - Market Caps - Do Not Change")
btcCap = request.security(input.symbol("BTC_MARKETCAP") , res, ta.sma(src, length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
cryptoCap = request.security(input.symbol("TOTAL") , res, ta.sma(src, length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
usdcCap = request.security(input.symbol("USDC_MARKETCAP") , res, ta.sma(src, length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
usdtCap = request.security(input.symbol("USDT_MARKETCAP") , res, ta.sma(src, length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
busdCap = request.security(input.symbol("BUSD_MARKETCAP") , res, ta.sma(src, length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
daiCap = request.security(input.symbol("DAI_MARKETCAP") , res, ta.sma(src, length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
stableCap = (usdcCap + usdtCap + busdCap + daiCap)
btcDom = btcCap / (cryptoCap) *100
btcDomMinus = btcCap / (cryptoCap - stableCap) *100
stableDom = (usdcCap + usdtCap + busdCap + daiCap) / (cryptoCap - stableCap) *100
chartDom = (chartCap) / (cryptoCap - stableCap) *100
plot(viewBTC ? btcDom : na, title = 'BTC Dominance', color = color.green)
plot(viewBTCMinus ? btcDomMinus : na, title = 'BTC Dominance Minus Stable Coins ', color = color.blue)
plot(viewChart ? chartDom : na, title = 'Chart Asset Dominance Minus Stable Coins ', color = color.yellow)
plot(viewStable ? stableDom : na, title = 'Stable Dominance Minus Stable Coins ', color = color.red)
btcCon = btcDom[0] > btcDom[1] or btcCap[0] > btcCap[1]
btcMCon = btcDomMinus[0] > btcDomMinus[1] or btcCap[0] > btcCap[1]
chartCon = chartDom[0] > chartDom[1] or chartCap[0] > chartCap[1]
stableCon = stableDom[0] > stableDom[1] or stableCap[0] > stableCap[1]
bgcolor(btcCon and viewBTC? #bdfdbf51 : na)
bgcolor(btcMCon and viewBTCMinus ? #bdfdbf51 : na)
bgcolor(chartCon and viewChart ? #bdfdbf51 : na)
bgcolor(stableCon and viewStable ? #bdfdbf51 : na)
btcCon = btcDom[0] > btcDom[1] or btcCap[0] > btcCap[1]