Untitled
unknown
plain_text
2 years ago
3.3 kB
13
Indexable
Never
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © konidtaly88 //@version=5 indicator("Reversal Indicator", overlay=true) debug = input.bool(false) price = input.source(close) ma9 = ta.ema(price,9) ma14 = ta.ema(price,14) ma21 = ta.ema(price,21) buy = ma9>ma14 and ma14>ma21 and low>ma9 stopbuy = ma9<=ma14 buynow = not buy[1] and buy var int buysignal = 0 buysignal := bar_index < 1 ? 0 : (buynow and not stopbuy ? 1 : (buysignal[1] == 1 and stopbuy ? 0 : buysignal[1])) Buy_Signal = buysignal[1] == 0 and buysignal == 1 Momentum_Down = buysignal[1] == 1 and buysignal == 0 sell = ma9 < ma14 and ma14 < ma21 and high < ma9 stopsell = ma9 >= ma14 sellnow = not sell[1] and sell var int sellsignal = 0 sellsignal := bar_index < 1 ? 0 : (sellnow and not stopsell ? 1 : (sellsignal[1] == 1 and stopsell ? 0 : sellsignal[1])) Sell_Signal = sellsignal[1] == 0 and sellsignal Momentum_Up = sellsignal[1] == 1 and sellsignal == 0 Colorbars = buysignal == 1 ? 1 : (sellsignal == 1 ? 2 : (buysignal == 0 or sellsignal == 0 ? 3 : 0)) colorbars = switch Colorbars 0 => na 1 => color.green 2 => color.red 3 => color.fuchsia barcolor(debug? colorbars:na) //------------------------------------------------------------------------------------------------------------------------------------------ method = input.string("average", options=["average", "high_low"]) pricehigh = input.source(high) pricelow = input.source(low) mah = ta.ema(pricehigh, 5) mal = ta.ema(pricelow, 5) priceh = method=="average"? mah : pricehigh pricel = method=="average"? mal : pricelow ZZPercent = input.float(0.01, minval=0, maxval = 100, step=0.01) ATRPeriod = input.int(5, minval=1) ATRFactor = input.float(1.5, minval=0) var bool trend_up = true var float ll = 0 var float hh = 0 var int llb = 0 var int lhb = 0 atrPeriod = ta.atr(ATRPeriod) update_chart = false float HLPivot = na if bar_index < 1 ll := pricel hh := priceh llb := 0 lhb := 0 trend_up := true update_chart := true else HLPivot := ZZPercent*0.01 + ATRFactor*atrPeriod/close if trend_up if priceh >= hh hh := priceh lhb := bar_index else if pricel < hh * (1 - HLPivot) ll := pricel llb := bar_index trend_up := false update_chart := true else if pricel <= ll ll := pricel llb := bar_index else if priceh > ll * (1 + HLPivot) hh := priceh lhb := bar_index trend_up := true update_chart := true var float zz = 0 if update_chart zz := trend_up? ll:hh plot(not update_chart? na : zz, linewidth=2) color_bull = color.new(color.green,50) color_bear = color.new(color.red,50) plotshape(trend_up and update_chart and debug, color=color_bull) plotshape(not trend_up and update_chart and debug, color=color_bear, location=location.belowbar) plot(not debug or update_chart? na : trend_up? hh * (1 - HLPivot):ll * (1 + HLPivot), color=trend_up?color_bull:color_bear, style=plot.style_linebr)