BTC Price Trend
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marvixino

//@version=5
indicator("BTC Price Trend", overlay=true)

string BTC_TREND = 'Config » BTC Trend'
btcDownPerc_in = input.float(2, "BTC Down %", step=0.1, group=BTC_TREND, tooltip="Disable trading if price decreases down by x%")
btcDownTF = input.timeframe("240", "BTC Down Timeframe", group=BTC_TREND,options=['30','60','120','240','D'], tooltip="Time in minutes.")
btcUpPerc_in = input.float(0.1, "BTC Up %", step=0.1, group=BTC_TREND, tooltip="Enable trading if price increased by x%")
btcUpTF = input.timeframe("5", "BTC UP Timeframe", group=BTC_TREND,options=['1','5','10','15','30','60','240', 'D'], tooltip="Time in minutes.")

getSecurity(sym, tf, src) =>
    request.security(sym, tf, src[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]
bool btcTrend = na
//-- Down
btcNow = getSecurity("BINANCE:BTCUSD", btcDownTF, close)
btcBefore = getSecurity("BINANCE:BTCUSD", btcDownTF, close[1])
btcDownPerc = math.round(100* (btcNow-btcBefore)/btcNow, 1)
if(btcDownPerc < btcDownPerc_in)
    btcTrend := false
    
//-- up
btcNowUp = getSecurity("BINANCE:BTCUSD", btcUpTF, close)
btcBeforeUp = getSecurity("BINANCE:BTCUSD", btcUpTF, close[1])
btcUpPerc = math.round(100* (btcNowUp-btcBeforeUp)/btcNowUp, 1)
if(btcUpPerc > btcUpPerc_in)
    btcTrend := true
    
color = btcTrend ? color.lime : color.maroon
barcolor(color)

