Untitled
//@version=6 indicator(title = 'RSN Fisher Divergence MTF', shorttitle = 'RSN Fisher MTF', overlay = false) // Fisher Transform Input Paramesters len = input.int(10, minval = 1, title = 'Length') lookbackBars = input.int(8, minval = 1, title = 'Lookback Bars') timeframe = input.timeframe('60', title = 'Timeframe') // Fisher Transform calculation round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val value = 0.0 value := round_(.66 * ((hl2 - ta.lowest(hl2, len)) / (ta.highest(hl2, len) - ta.lowest(hl2, len)) - .5) + .67 * nz(value[1])) fish = 0.0 fish := .5 * math.log((1 + value) / (1 - value)) + .5 * nz(fish[1]) // Çoklu zaman diliminden veri alma fishMTF = request.security(syminfo.tickerid, timeframe, fish) hl2MTF = request.security(syminfo.tickerid, timeframe, hl2) lowMTF = request.security(syminfo.tickerid, timeframe, low) highMTF = request.security(syminfo.tickerid, timeframe, high) // Divergence parameters rangeUpper = 60 rangeLower = 5 // Colors bearColor = color.red bullColor = color.navy hiddenBullColor = color.new(color.yellow, 50) hiddenBearColor = color.new(color.yellow, 50) textColor = color.white noneColor = color.new(color.white, 100) // Pivot detection plFound = na(ta.pivotlow(fishMTF, lookbackBars, lookbackBars)) ? false : true phFound = na(ta.pivothigh(fishMTF, lookbackBars, lookbackBars)) ? false : true // Range check function _inRange(cond) => bars = ta.barssince(cond == true) rangeLower <= bars and bars <= rangeUpper // Regular Bullish Divergence oscHL = fishMTF[lookbackBars] > ta.valuewhen(plFound, fishMTF[lookbackBars], 1) and _inRange(plFound[1]) priceLL = lowMTF[lookbackBars] < ta.valuewhen(plFound, lowMTF[lookbackBars], 1) bullCond = priceLL and oscHL and plFound plot(plFound ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Regular Bullish', linewidth = 2, color = bullCond ? bullColor : noneColor) plotshape(bullCond ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Regular Bullish Label', text = 'D', style = shape.labelup, location = location.absolute, color = bullColor, textcolor = textColor) // Hidden Bullish Divergence oscLL = fishMTF[lookbackBars] < ta.valuewhen(plFound, fishMTF[lookbackBars], 1) and _inRange(plFound[1]) priceHL = lowMTF[lookbackBars] > ta.valuewhen(plFound, lowMTF[lookbackBars], 1) hiddenBullCond = priceHL and oscLL and plFound plot(plFound ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Hidden Bullish', linewidth = 2, color = hiddenBullCond ? hiddenBullColor : noneColor) plotshape(hiddenBullCond ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Hidden Bullish Label', text = 'H', style = shape.labelup, location = location.absolute, color = bullColor, textcolor = textColor) // Regular Bearish Divergence oscLH = fishMTF[lookbackBars] < ta.valuewhen(phFound, fishMTF[lookbackBars], 1) and _inRange(phFound[1]) priceHH = highMTF[lookbackBars] > ta.valuewhen(phFound, highMTF[lookbackBars], 1) bearCond = priceHH and oscLH and phFound plot(phFound ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Regular Bearish', linewidth = 2, color = bearCond ? bearColor : noneColor) plotshape(bearCond ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Regular Bearish Label', text = 'D', style = shape.labeldown, location = location.absolute, color = bearColor, textcolor = textColor) // Hidden Bearish Divergence oscHH = fishMTF[lookbackBars] > ta.valuewhen(phFound, fishMTF[lookbackBars], 1) and _inRange(phFound[1]) priceLH = highMTF[lookbackBars] < ta.valuewhen(phFound, highMTF[lookbackBars], 1) hiddenBearCond = priceLH and oscHH and phFound plot(phFound ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Hidden Bearish', linewidth = 2, color = hiddenBearCond ? hiddenBearColor : noneColor) plotshape(hiddenBearCond ? fishMTF[lookbackBars] : na, offset = -lookbackBars, title = 'Hidden Bearish Label', text = 'H', style = shape.labeldown, location = location.absolute, color = bearColor, textcolor = textColor) // Fisher candlestick color adjustment fisher_color = fishMTF > fishMTF[1] ? color.new(color.green, 0) : color.new(color.red, 0) // Fisher bars plotcandle(open = fishMTF[1], high = fishMTF, low = fishMTF, close = fishMTF, color = fisher_color, wickcolor = fisher_color, bordercolor = fisher_color, title = 'Fisher Candles') // Alert Conditions alertcondition(bullCond or hiddenBullCond, title = 'bull_alert', message = '↑ Bullish sign appeared!! by Fisher divergence') alertcondition(bearCond or hiddenBearCond, title = 'bear_alert', message = '↓ Bearish sign appeared!! by Fisher divergence')
Leave a Comment