//@version=5 indicator("OAAO Trend Confirmation HTF", overlay=true) // Input parameters strategy = input.int(2, title="Strategy", minval=1, maxval=3) showOneSignalPerConfirmation = input.bool(false, title="Show One Signal Per Confirmation") tcTimeFrame = input.timeframe("D", title="TC Time Frame") tcChannelPeriod = input.int(5, title="TC Channel Period") tcMaxChannelPeriod = input.int(30, title="TC Max Channel Period") tcMinChannelWidth = input.int(10, title="TC Min Channel Width") useHTFOAAOTrendConfirmation = input.bool(false, title="Use HTF OAAO Trend Confirmation") tcHTFTimeFrame = input.timeframe("60", title="TC HTF Time Frame") tcHTFChannelPeriod = input.int(5, title="TC HTF Channel Period") tcHTFMaxChannelPeriod = input.int(30, title="TC HTF Max Channel Period") tcHTFMinChannelWidth = input.int(10, title="TC HTF Min Channel Width") useXCandles = input.bool(false, title="Use X Candles") htf1XCandles = input.int(1, title="HTF1 X Candles") arrowDistance = input.int(0, title="Arrow Distance") // Helper functions heikenAshiClose() => (open + high + low + close) / 4 donchianUpper(period) => ta.highest(high, period) donchianLower(period) => ta.lowest(low, period) donchianWidth(period) => donchianUpper(period) - donchianLower(period) // Check Buy and Sell Conditions checkBuyTC() => haMedian = heikenAshiClose() donchianUpperVal = donchianUpper(tcChannelPeriod) haMedian > donchianUpperVal checkSellTC() => haMedian = heikenAshiClose() donchianLowerVal = donchianLower(tcChannelPeriod) haMedian < donchianLowerVal // Signal calculation var float buySignal = na var float sellSignal = na var int lastTrade = 0 // Trend Confirmation Logic tcHTFHaMedian = request.security(syminfo.tickerid, tcHTFTimeFrame, heikenAshiClose()) tcHTFUpper = request.security(syminfo.tickerid, tcHTFTimeFrame, donchianUpper(tcHTFChannelPeriod)) tcHTFLower = request.security(syminfo.tickerid, tcHTFTimeFrame, donchianLower(tcHTFChannelPeriod)) if (useHTFOAAOTrendConfirmation) if (tcHTFHaMedian > tcHTFUpper and lastTrade != 1) buySignal := low - arrowDistance * syminfo.mintick lastTrade := 1 else if (tcHTFHaMedian < tcHTFLower and lastTrade != 2) sellSignal := high + arrowDistance * syminfo.mintick lastTrade := 2 else for i = 0 to 1 if (checkBuyTC() and lastTrade != 1) buySignal := low[i] - arrowDistance * syminfo.mintick lastTrade := 1 else buySignal := na if (checkSellTC() and lastTrade != 2) sellSignal := high[i] + arrowDistance * syminfo.mintick lastTrade := 2 else sellSignal := na plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY") plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")