Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('Gann medians', overlay=true, format=format.price, precision=12, max_bars_back=500)
- method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length1 = input(12)
- mult1 = input.int(1, minval=0, maxval=1)
- method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length2 = input(27)
- mult2 = input.int(1, minval=0, maxval=1)
- method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length3 = input(56)
- mult3 = input.int(1, minval=0, maxval=1)
- //----
- Avg(x, length, method) =>
- sma_1 = ta.sma(x, length)
- ema_1 = ta.ema(x, length)
- percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
- method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
- //----
- a1 = ta.highest(length1) - math.max(close, open)
- b1 = math.min(close, open) - ta.lowest(length1)
- c1 = math.max(close, open) + a1 * mult1
- d1 = math.min(close, open) - b1 * mult1
- a2 = ta.highest(length2) - math.max(close, open)
- b2 = math.min(close, open) - ta.lowest(length2)
- c2 = math.max(close, open) + a2 * mult2
- d2 = math.min(close, open) - b2 * mult2
- a3 = ta.highest(length3) - math.max(close, open)
- b3 = math.min(close, open) - ta.lowest(length3)
- c3 = math.max(close, open) + a3 * mult3
- d3 = math.min(close, open) - b3 * mult3
- //----
- e1 = Avg(c1, length1, method1)
- f1 = Avg(d1, length1, method1)
- g1 = 0
- cross_1 = ta.cross(close, f1)
- g1 := ta.cross(close, e1) ? 1 : cross_1 ? 0 : nz(g1[1])
- e2 = Avg(c2, length2, method2)
- f2 = Avg(d2, length2, method2)
- g2 = 0
- cross_2 = ta.cross(close, f2)
- g2 := ta.cross(close, e2) ? 1 : cross_2 ? 0 : nz(g2[1])
- e3 = Avg(c3, length3, method3)
- f3 = Avg(d3, length3, method3)
- g3 = 0
- cross_3 = ta.cross(close, f3)
- g3 := ta.cross(close, e3) ? 1 : cross_3 ? 0 : nz(g3[1])
- //---
- hilo1 = g1 * f1 + (1 - g1) * e1
- css1 = g1 == 1 ? color.green : color.red
- plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- hilo2 = g2 * f2 + (1 - g2) * e2
- css2 = g2 == 1 ? color.green : color.red
- plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- hilo3 = g3 * f3 + (1 - g3) * e3
- css3 = g3 == 1 ? color.green : color.red
- plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- //end of this part
- testStartYear = input(2019, 'Backtest Start Year')
- testStartMonth = input(10, 'Backtest Start Month')
- testStartDay = input(20, 'Backtest Start Day')
- testStartHour = input(0, 'Backtest Start Hour')
- testStartMin = input(0, 'Backtest Start Minute')
- testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, testStartHour, testStartMin)
- testStopYear = input(2099, 'Backtest Stop Year')
- testStopMonth = input(1, 'Backtest Stop Month')
- testStopDay = input(30, 'Backtest Stop Day')
- testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)
- testPeriod() =>
- time >= testPeriodStart and time <= testPeriodStop ? true : false
- lenH = input.int(title='Length High', defval=20, minval=1)
- lenL = input.int(title='Length Low', defval=20, minval=1)
- fun(src, len, isHigh, _style, _yloc, _color) =>
- p = nz(src[len])
- isFound = true
- for i = 0 to len * 2 by 1
- if isHigh and src[i] > p
- isFound := false
- isFound
- if not isHigh and src[i] < p
- isFound := false
- isFound
- if isFound and testPeriod()
- label.new(bar_index[len], p, str.tostring(p), style=_style, yloc=_yloc, color=_color)
- line.new(bar_index[len], p, bar_index, p, extend=extend.right, color=_color)
- fun(high, lenH, true, label.style_label_down, yloc.abovebar, color.red)
- fun(low, lenL, false, label.style_label_up, yloc.belowbar, color.green)
- //end of this part
- price = input(defval=ohlc4)
- // Strategy vars setup here
- Depth = input(56, title='Depth') // Depth
- Deviation = input(5, title='Deviation') // Deviation
- // main logic
- // ZigZag
- lastlow = 0.0
- lasthigh = 0.0
- lastlow := nz(lastlow[1])
- lasthigh := nz(lasthigh[1])
- data(x) =>
- d = request.security(syminfo.tickerid, timeframe.period, x, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
- d
- getLow(x, y, z, a) =>
- lastlow = y
- v = data(x)
- m = v == lastlow or data(z) - v > a * syminfo.mintick
- if v != lastlow
- lastlow := v
- lastlow
- if m
- v := 0.0
- v
- [v, lastlow]
- getHigh(x, y, z, a) =>
- lasthigh = y
- v = data(x)
- m = v == lasthigh or v - data(z) > a * syminfo.mintick
- if v != lasthigh
- lasthigh := v
- lasthigh
- if m
- v := 0.0
- v
- [v, lasthigh]
- [v, e] = getLow(ta.lowest(Depth), lastlow, low, Deviation)
- lastlow := e
- zBB = v != 0.0
- [v1, ee1] = getHigh(ta.highest(Depth), lasthigh, high, Deviation)
- lasthigh := ee1
- zSS = v1 != 0.0
- zigzagDirection = -1
- zigzagHigh = 0
- zigzagLow = 0
- zigzagDirection := zBB ? 0 : zSS ? 1 : nz(zigzagDirection[1], -1)
- virtualLow = zigzagLow[1] + 1
- if not zBB or zBB and zigzagDirection == zigzagDirection[1] and low > low[virtualLow]
- zigzagLow := nz(zigzagLow[1]) + 1
- zigzagLow
- virtualHigh = zigzagHigh[1] + 1
- if not zSS or zSS and zigzagDirection == zigzagDirection[1] and high < high[virtualHigh]
- zigzagHigh := nz(zigzagHigh[1]) + 1
- zigzagHigh
- a = bar_index - zigzagLow
- b = bar_index - zigzagHigh
- var color c = na
- c := fixnan(a < b[1] ? color.lime : a > b[1] ? color.red : na)
- //barcolor(color=color.lime)
- line zigzag = line.new(bar_index - zigzagLow, low[zigzagLow], bar_index - zigzagHigh, high[zigzagHigh], color=c, style=line.style_solid, width=4)
- if zigzagDirection == zigzagDirection[1]
- line.delete(zigzag[1])
- l = label.new(bar_index - zigzagHigh, na)
- label.set_text(l, 'Sell')
- label.set_color(l, color.red)
- label.set_yloc(l, yloc.abovebar)
- label.set_style(l, label.style_label_down)
- if zigzagDirection == zigzagDirection[1]
- label.delete(l[1])
- l_b = label.new(bar_index - zigzagLow, na)
- label.set_text(l_b, 'Buy')
- label.set_color(l_b, color.green)
- label.set_yloc(l_b, yloc.belowbar)
- label.set_style(l_b, label.style_label_up)
- if zigzagDirection == zigzagDirection[1]
- label.delete(l_b[1])
- zzPrevHigh = zigzagHigh[1]
- zzPrevLow = zigzagLow[1]
- if not na(zzPrevHigh[1])
- zzPrevHigh := zzPrevHigh[1] + 1
- zzPrevHigh
- if not na(zzPrevLow[1])
- zzPrevLow := zzPrevLow[1] + 1
- zzPrevLow
- if zigzagDirection != zigzagDirection[1]
- if zigzagDirection == 1
- zzPrevHigh := zigzagHigh[1] + 1
- zzPrevHigh
- if zigzagDirection == 0
- zzPrevLow := zigzagLow[1] + 1
- zzPrevLow
- //end of this part
- // RSI Settings for user
- rsiSource = input(title='RSI Source', defval=close)
- rsiLength = input(title='RSI Length', defval=7)
- rsiOverbought = input.int(title='RSI Overbought', defval=70, minval=50, maxval=100)
- rsiOvesold = input.int(title='RSI Oversold', defval=30, minval=1, maxval=50)
- // RSI value based on inbuilt RSI
- rsiValue = ta.rsi(rsiSource, rsiLength)
- // Get the current state
- isOverbought = rsiValue >= rsiOverbought
- isOversold = rsiValue <= rsiOvesold
- // State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
- var laststate = 0
- // Highest and Lowest prices since the last state change
- var hh = low
- var ll = high
- // Labels
- var label labelll = na
- var label labelhh = na
- // Swing lines
- var line line_up = na
- var line line_down = na
- // We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
- if laststate == 1 and isOversold
- ll := low
- labelll := label.new(bar_index, low, style=label.style_label_up, color=color.green, size=size.tiny)
- labelhh_low = label.get_x(labelhh)
- labelhh_pos = label.get_y(labelhh)
- line_down := line.new(bar_index, high, labelhh_low, labelhh_pos, width=2)
- line_down
- // We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
- if laststate == 2 and isOverbought
- hh := high
- labelhh := label.new(bar_index, high, style=label.style_label_down, color=color.red, size=size.tiny)
- labelll_low = label.get_x(labelll)
- labelll_pos = label.get_y(labelll)
- line_up := line.new(bar_index, high, labelll_low, labelll_pos, width=2)
- line_up
- // If we are overbought
- if isOverbought
- if high >= hh
- hh := high
- label.set_x(labelhh, bar_index)
- label.set_y(labelhh, high)
- line.set_x1(line_up, bar_index)
- line.set_y1(line_up, high)
- laststate := 1
- laststate
- // If we are oversold
- if isOversold
- if low <= ll
- ll := low
- label.set_x(labelll, bar_index)
- label.set_y(labelll, low)
- line.set_x1(line_down, bar_index)
- line.set_y1(line_down, low)
- laststate := 2
- laststate
- // If last state was overbought and we are overbought
- if laststate == 1 and isOverbought
- if hh <= high
- hh := high
- label.set_x(labelhh, bar_index)
- label.set_y(labelhh, high)
- line.set_x1(line_up, bar_index)
- line.set_y1(line_up, high)
- //If we are oversold and the last state was oversold, move the drawings to the lowest price
- if laststate == 2 and isOversold
- if low <= ll
- ll := low
- label.set_x(labelll, bar_index)
- label.set_y(labelll, low)
- line.set_x1(line_down, bar_index)
- line.set_y1(line_down, low)
- // If last state was overbought
- if laststate == 1
- if hh <= high
- hh := high
- label.set_x(labelhh, bar_index)
- label.set_y(labelhh, high)
- line.set_x1(line_up, bar_index)
- line.set_y1(line_up, high)
- // If last stare was oversold
- if laststate == 2
- if ll >= low
- ll := low
- label.set_x(labelll, bar_index)
- label.set_y(labelll, low)
- line.set_x1(line_down, bar_index)
- line.set_y1(line_down, low)
- //end of this part
- //study("momentum zigzag", overlay = true)
- lengthZZZ = input(10, title='High/Low length')
- hZZZ = ta.highest(high, lengthZZZ * 2 + 1)
- lZZZ = ta.lowest(low, lengthZZZ * 2 + 1)
- f_isMin(len) =>
- lZZZ == low[len]
- f_isMax(len) =>
- hZZZ == high[len]
- var dirUp = false
- var lastLow = high * 100
- var lastHigh = 0.0
- var timeLow = bar_index
- var timeHigh = bar_index
- var line li = na
- f_drawLine() =>
- _li_color = dirUp ? color.gray : color.gray
- line.new(timeHigh - lengthZZZ, lastHigh, timeLow - lengthZZZ, lastLow, xloc.bar_index, color=_li_color, width=1)
- if dirUp
- if f_isMin(lengthZZZ) and low[lengthZZZ] < lastLow
- lastLow := low[lengthZZZ]
- timeLow := bar_index
- line.delete(li)
- li := f_drawLine()
- li
- if f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow
- lastHigh := high[lengthZZZ]
- timeHigh := bar_index
- dirUp := false
- li := f_drawLine()
- li
- if not dirUp
- if f_isMax(lengthZZZ) and high[lengthZZZ] > lastHigh
- lastHigh := high[lengthZZZ]
- timeHigh := bar_index
- line.delete(li)
- li := f_drawLine()
- li
- if f_isMin(lengthZZZ) and low[lengthZZZ] < lastHigh
- lastLow := low[lengthZZZ]
- timeLow := bar_index
- dirUp := true
- li := f_drawLine()
- if f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow
- lastHigh := high[lengthZZZ]
- timeHigh := bar_index
- dirUp := false
- li := f_drawLine()
- li
- //end of this part
- use_alt_series = input(defval=false, title='Use alternative source?')
- alt_src = input(defval=close, title='Alternative source:')
- hSR = use_alt_series ? alt_src : high
- lSR = use_alt_series ? alt_src : low
- window = input(defval=14, title='lookback window :')
- percent_of_range_for_trade_zone = input(defval=15.0, title='Percent of the range to use for trade zone') * 0.01
- short_term_top = ta.valuewhen(hSR >= ta.highest(hSR, window), hSR, 0)
- short_term_bot = ta.valuewhen(lSR <= ta.lowest(lSR, window), lSR, 0)
- short_term_resist = ta.change(short_term_top) != 0 ? na : short_term_top
- short_term_suport = ta.change(short_term_bot) != 0 ? na : short_term_bot
- short_term_resist_plot = plot(series=short_term_resist, title='STR', color=color.new(color.fuchsia, 0), linewidth=2, style=plot.style_linebr)
- short_term_suport_plot = plot(series=short_term_suport, title='STS', color=color.new(color.aqua, 0), linewidth=2, style=plot.style_linebr)
- fill(short_term_suport_plot, short_term_resist_plot, color=color.new(color.aqua, 95), title=' Trade Zone ')
- // Calculate entry zone:
- float short_term_resist_trade_limit = na
- float short_term_suport_trade_limit = na
- range_1 = fixnan(short_term_resist) - fixnan(short_term_suport)
- if not na(short_term_resist)
- if not na(short_term_resist_trade_limit[1])
- short_term_resist_trade_limit := short_term_resist_trade_limit[1]
- short_term_resist_trade_limit
- else
- short_term_resist_trade_limit := short_term_resist - range_1 * percent_of_range_for_trade_zone
- short_term_resist_trade_limit
- if not na(short_term_suport)
- if not na(short_term_suport_trade_limit[1])
- short_term_suport_trade_limit := short_term_suport_trade_limit[1]
- short_term_suport_trade_limit
- else
- short_term_suport_trade_limit := short_term_suport + range_1 * percent_of_range_for_trade_zone
- short_term_suport_trade_limit
- short_term_resist_trade_limit_plot = plot(series=short_term_resist_trade_limit, title='', color=color.new(color.red, 0), linewidth=1, style=plot.style_linebr)
- short_term_suport_trade_limit_plot = plot(series=short_term_suport_trade_limit, title='', color=color.new(color.yellow, 0), linewidth=1, style=plot.style_linebr)
- //end of this part
- lookback = input(defval=20, title='# of Candles to Look Back')
- srcAA = 'Close'
- pivothigh_1 = ta.pivothigh(high, lookback, lookback)
- pivothigh_2 = ta.pivothigh(high, lookback, lookback)
- pivot_high = srcAA == 'Close' ? pivothigh_1 : pivothigh_2
- pivotlow_1 = ta.pivotlow(low, lookback, lookback)
- pivotlow_2 = ta.pivotlow(low, lookback, lookback)
- pivot_low = srcAA == 'Close' ? pivotlow_1 : pivotlow_2
- valuewhen_9 = ta.valuewhen(pivot_high, high[lookback], 0)
- valuewhen_10 = ta.valuewhen(pivot_high, high[lookback], 0)
- plot_high = srcAA == 'Close' ? valuewhen_9 : valuewhen_10
- valuewhen_11 = ta.valuewhen(pivot_low, low[lookback], 0)
- valuewhen_12 = ta.valuewhen(pivot_low, low[lookback], 0)
- plot_low = srcAA == 'Close' ? valuewhen_11 : valuewhen_12
- resistance = plot(plot_high, style=plot.style_line, title='Resistance Line', color=color.new(color.orange, 0), show_last=1, linewidth=2, trackprice=true)
- support = plot(plot_low, style=plot.style_line, title='Support Line', color=color.new(color.orange, 0), show_last=1, linewidth=2, trackprice=true)
- //end of this part
- // - INPUTS
- ShowPivots = input(true, title='Show Pivot Points')
- ShowHHLL = input(true, title='Show HH,LL,LH,HL markers on Pivots Points')
- left = input.int(5, minval=1, title='Pivot Length Left Hand Side')
- right = input.int(5, minval=1, title='Pivot Length Right Hand Side')
- //
- var barCounter = 0
- barCounter := barCounter + 1
- f_draw_infopanel(_x, _y, _line, _text) =>
- _rep_text = ''
- if barstate.islast
- for _l = 0 to _line by 1
- _rep_text := _rep_text + '\n'
- _rep_text
- _rep_text := _rep_text + _text
- var label _la = na
- //a = label.get_text(_la)
- label.delete(_la)
- _la := label.new(x=_x, y=_y, text=_rep_text, xloc=xloc.bar_time, yloc=yloc.price, color=color.black, style=label.style_label_up, textcolor=color.silver, size=size.small)
- _la
- // Determine pivots
- pvtLenL = left
- pvtLenR = right
- // Get High and Low Pivot Points
- pvthi_ = ta.pivothigh(high, pvtLenL, pvtLenR)
- pvtlo_ = ta.pivotlow(low, pvtLenL, pvtLenR)
- // Force Pivot completion before plotting.
- pvthi = pvthi_
- pvtlo = pvtlo_
- // ||-----------------------------------------------------------------------------------------------------||
- // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
- valuewhen_1 = ta.valuewhen(pvthi, high[pvtLenR], 1)
- valuewhen_2 = ta.valuewhen(pvthi, high[pvtLenR], 0)
- higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
- valuewhen_3 = ta.valuewhen(pvthi, high[pvtLenR], 1)
- valuewhen_4 = ta.valuewhen(pvthi, high[pvtLenR], 0)
- lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
- valuewhen_5 = ta.valuewhen(pvtlo, low[pvtLenR], 1)
- valuewhen_6 = ta.valuewhen(pvtlo, low[pvtLenR], 0)
- higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
- valuewhen_7 = ta.valuewhen(pvtlo, low[pvtLenR], 1)
- valuewhen_8 = ta.valuewhen(pvtlo, low[pvtLenR], 0)
- lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na
- // If selected Display the HH/LL above/below candle.
- plotshape(ShowHHLL ? higherhigh : na, title='HH', location=location.abovebar, color=color.new(color.green, 0), text='HH', offset=-pvtLenR)
- plotshape(ShowHHLL ? higherlow : na, title='HL', location=location.belowbar, color=color.new(color.green, 0), text='HL', offset=-pvtLenR)
- plotshape(ShowHHLL ? lowerhigh : na, title='LH', location=location.abovebar, color=color.new(color.red, 0), text='LH', offset=-pvtLenR)
- plotshape(ShowHHLL ? lowerlow : na, title='LL', location=location.belowbar, color=color.new(color.red, 0), text='LL', offset=-pvtLenR)
- useColors = input(title='Fill with colors?', defval=true)
- isess = session.regular
- t = ticker.new(syminfo.prefix, syminfo.ticker, session=isess)
- igaps = barmerge.gaps_off
- yesterdayHigh = request.security(t, 'D', high[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
- yesterdayClose = request.security(t, 'D', close[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
- yesterdayLow = request.security(t, 'D', low[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
- // Plot the other time frame's data
- aH = timeframe.isintraday ? yesterdayHigh : na
- cL = timeframe.isintraday ? yesterdayLow : na
- up5on = input(true, title='5 Minute Opening Range High')
- down5on = input(true, title='5 Minute Opening Range Low')
- is_newbar(res) =>
- ta.change(time(res)) != 0
- adopt(r, s) =>
- request.security(syminfo.ticker, r, s)
- high_range = ta.valuewhen(is_newbar('D'), high, 0)
- low_range = ta.valuewhen(is_newbar('D'), low, 0)
- high_rangeL = ta.valuewhen(is_newbar('D'), high, 0)
- low_rangeL = ta.valuewhen(is_newbar('D'), low, 0)
- up5 = up5on ? adopt('5', high_rangeL) : na
- down5 = down5on ? adopt('5', low_rangeL) : na
- bColor = #000000
- rColor = #ff0a02
- sColor = #008f0e
- pColor = #0900ff
- mColor = color.maroon
- myWidthMainLevels = input.int(title='Line width for Main levels', defval=1, minval=1)
- myStyle = plot.style_circles
- //plot(aH, title="H", color=#008f0e, linewidth=myWidthMainLevels, style=myStyle)
- //plot(cL, title="L", color=#ff0a02, linewidth=myWidthMainLevels, style=myStyle)
- //plot(up5, title="UP", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
- //plot(down5, title="DOWN", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
- //end of this part
- //----- User inputs ---------------------
- Lookback1 = input.int(title='Lookback Left', defval=200, minval=1)
- Lookback2 = input.int(title='Lookback Right', defval=0, minval=0)
- VertLR = input(title='Show Vertical Left/Right', defval=true)
- VertHL = input(title='Show Vertical Highest/Lowest', defval=true)
- Count = input(title='Show Counts', defval=true)
- FullCount = input(title='Count All Bars', defval=false)
- Fibs = input(title='Show Fib Retrace Lines', defval=false)
- FibsExtHigh = input(title='Show Fib Ext Highs', defval=false)
- FibsExtLow = input(title='Show Fib Ext Lows', defval=false)
- //----- Main ---------------------
- // Get left and right endpoints. Though user input says "left" and "right", they are interchangeable.
- // The larger number is left, smaller number right.
- leftHL = math.max(Lookback1, Lookback2)
- rightHL = math.min(Lookback1, Lookback2)
- // Total num bars. Must be > 0 for highest() and lowest() to work. Add 1 to left bar, if needed.
- leftHL := leftHL - rightHL == 0 ? leftHL + 1 : leftHL
- lengthHL = leftHL - rightHL
- // Highest price, looking back between the left/right endpoints
- highBack = ta.highest(high[rightHL], lengthHL)
- // Get # of bars back from present bar (offset).
- // NOTE: highestbars() returns a negative integer. Thus, subtract the right endpoint to get
- // offset from present (right-edge) bar
- highOffset = ta.highestbars(high[rightHL], lengthHL) - rightHL
- // Lowest price, looking back
- lowBack = ta.lowest(low[rightHL], lengthHL)
- lowOffset = ta.lowestbars(low[rightHL], lengthHL) - rightHL
- // Create a series of timestamps per bar. Needed to determine which bars are at the right edge,
- // While "n" starts at zero (left-edge bar) and counts up to the right-edge bar, this timestamp
- // (or tick) series counts the other way: max value at the left-edge, counting down to zero
- // at the right-edge.
- // This tick series is only valid while the indicator loads because "timenow" is the timestamp
- // of loading and "time" is the timestamp of a bar. The difference between the two timestamps
- // shrinks to zero as the righ-edge bar is processed. After loading, "timenow" and "time" are
- // the same value. Thus, "tick" always equals zero as new bars appear. But, for this indicator
- // this is sufficient behavior...
- tick = math.round((timenow - time) / ta.change(time)) // Each bar is a tick (float) in the timeline
- // Make a boolean mask for bars between left and right endpoints
- mask = FullCount ? true : tick < left and tick >= rightHL ? true : false
- // Determine the value of n at the left endpoint, used for visual counts of bars in mask
- nOffset = float(na)
- nOffset := FullCount ? 0 : tick == leftHL ? bar_index : nz(nOffset[1])
- // Note: It would be nice to count between the highest/lowest bars, instead of left/right bars,
- // but this isn't possible because highOffset and lowOffset are moving around as the
- // indicator loads. Thus, "mask" isn't accurate...
- //---- Plotting ---------------------
- // Horizontal Lines: Highest, Lowest dynamic lines
- // Params trackprice and offset make the horizontal line dynamic, adjusting to new highs/lows
- plot(highBack, title='Highest', color=color.new(color.red, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(lowBack, title='Lowest', color=color.new(color.green, 0), linewidth=2, trackprice=true, offset=-9999)
- // Veritcal Lines
- // Use barstate to paint/re-paint vertical lines, as new bars come into the data set.
- // islast - True for right most bar in data set. Use this to paint vertical bar, then push it back
- // in time with the offset parameter.
- // isrealtime - False while indicator loads. True for the right most bar, after loading.
- // isconfirmed - False while bar is not closed. True when close price appears.
- // isrealtime and isconfirmed - While indicator loads, ignore isconfirmed. After loading, isconfirmed
- // turns off the vertical line, as the bar closes. The next (new) bar is painted. This keeps
- // the vertical bar moving forward, as new bars appear, erasing the old (previous) vertical bar.
- VertLRShow = VertLR ? barstate.isrealtime and barstate.isconfirmed ? false : barstate.islast ? true : false : false
- // Can't use plot() with histogram/column because histbase can't accept "series" values
- bgcolor(VertLRShow ? color.gray : na, title='Vertical Left', offset=-leftHL + 1, transp=60)
- bgcolor(VertLRShow ? color.gray : na, title='Vertical Right', offset=-rightHL, transp=60)
- // Show vertical highest/lowest lines?
- VertHLShow = VertHL ? barstate.isrealtime and barstate.isconfirmed ? false : barstate.islast ? true : false : false
- bgcolor(VertHLShow ? color.red : na, title='Vertical Highest', offset=highOffset, transp=60)
- bgcolor(VertHLShow ? color.green : na, title='Vertical Lowest', offset=lowOffset, transp=60)
- // Fib levels extension and retracement
- priceRange = highBack - lowBack
- plot(FibsExtHigh ? lowBack + 3.618 * priceRange : na, title='3.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtHigh ? lowBack + 2.618 * priceRange : na, title='2.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtHigh ? lowBack + 1.618 * priceRange : na, title='1.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtHigh ? lowBack + 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
- plot(Fibs ? lowBack + 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
- plot(Fibs ? lowBack + 0.786 * priceRange : na, title='0.786', color=color.new(color.aqua, 0), linewidth=1, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.618 * priceRange : na, title='0.618', color=color.new(color.orange, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.50 * priceRange : na, title='0.5', color=color.new(color.yellow, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.382 * priceRange : na, title='0.382', color=color.new(color.orange, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.236 * priceRange : na, title='0.236', color=color.new(color.aqua, 0), linewidth=1, trackprice=true, offset=-9999)
- plot(Fibs ? highBack - 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
- plot(FibsExtLow ? highBack - 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
- plot(FibsExtLow ? highBack - 1.618 * priceRange : na, title='1.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtLow ? highBack - 2.618 * priceRange : na, title='2.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtLow ? highBack - 3.618 * priceRange : na, title='3.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
- // Lookback bar count
- countMod = mask ? (bar_index - nOffset) % 10 : na
- countInt = mask ? math.floor((bar_index - nOffset) / 10) % 10 : na
- plotshape(Count and countMod != 0 ? true : na, style=shape.circle, text='-', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 0 ? true : na, style=shape.circle, text='0', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 1 ? true : na, style=shape.circle, text='1', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 2 ? true : na, style=shape.circle, text='2', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 3 ? true : na, style=shape.circle, text='3', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 4 ? true : na, style=shape.circle, text='4', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 5 ? true : na, style=shape.circle, text='5', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 6 ? true : na, style=shape.circle, text='6', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 7 ? true : na, style=shape.circle, text='7', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 8 ? true : na, style=shape.circle, text='8', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- plotshape(Count and countMod == 0 and countInt == 9 ? true : na, style=shape.circle, text='9', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
- //end of this part
- //
- // @author LonesomeTheBlue
- //
- //study("Pivot High Low Points", overlay=true)
- lb = input(6, title='Left Bars')
- rb = input(6, title='Right Bars')
- mb = lb + rb + 1
- highestbars_1 = ta.highestbars(mb)
- iff_1 = highestbars_1 == -lb ? high[lb] : na
- plot(not na(high[mb]) ? iff_1 : na, style=plot.style_cross, linewidth=3, color=color.new(color.blue, 0), offset=-lb)
- lowestbars_1 = ta.lowestbars(mb)
- iff_2 = lowestbars_1 == -lb ? low[lb] : na
- plot(not na(low[mb]) ? iff_2 : na, style=plot.style_cross, linewidth=3, color=color.new(color.blue, 0), offset=-lb)
- //end of this part
- //end of this part
- //study("VJ - Killer BS", overlay=true)
- //======================================================================
- //Jurij
- h_left = input(title='h left', defval=10)
- h_right = input(title='h right', defval=10)
- show_ptz = input(title='Show PTZ', defval=true)
- show_channel = input(title='Show channel', defval=true)
- //barCount = nz(barCount[1]) + 1
- //check history and realtime PTZ
- h_left_low = ta.lowest(h_left)
- h_left_high = ta.highest(h_left)
- newlow = low <= h_left_low
- newhigh = high >= h_left_high
- //channel_high = plot(show_channel ? h_left_low : 0, color=silver)
- //channel_low = plot (show_channel ? h_left_high : 0, color=silver)
- central_bar_low = low[h_right + 1]
- central_bar_high = high[h_right + 1]
- full_zone_low = ta.lowest(h_left + h_right + 1)
- full_zone_high = ta.highest(h_left + h_right + 1)
- central_bar_is_highest = central_bar_high >= full_zone_high
- central_bar_is_lowest = central_bar_low <= full_zone_low
- plotchar(central_bar_is_highest ? -1 : 0, offset=-h_right - 1, color=color.new(color.red, 0), text='Sell')
- plotchar(central_bar_is_lowest ? 1 : 0, offset=-h_right - 1, location=location.belowbar, color=color.new(color.green, 0), text='Buy')
- //plot(close)
- //end of this part
- //study(title="Peaks&Valleys", shorttitle="P&V", overlay=true)
- width = input(9)
- p = 0
- vc = 0
- for i = 0 to width * 2 by 1
- p := p + (i == width ? 0 : high[i] < high[width] ? 1 : 0)
- v := vc + (i == width ? 0 : low[i] > low[width] ? 1 : 0)
- v
- plotshape(p == width * 2, offset=-width, style=shape.labeldown)
- plotshape(vc == width * 2, offset=-width, style=shape.labelup, location=location.belowbar)
- //end of this part
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © LonesomeTheBlue
- //study("Double Zig Zag with HHLL", overlay = true, max_bars_back = 500)
- prdx1 = input.int(defval=8, title='ZigZag Period 1', minval=2, maxval=20)
- prdx2 = input.int(defval=20, title='ZigZag Period 2', minval=2, maxval=50)
- showzz = input.string(defval='Show Both', title='Show Zig Zags', options=['Show Zig Zag 1', 'Show Zig Zag 2', 'Show Both', 'Show None'])
- showhhll = input.string(defval='Show Both', title='Show HHLL', options=['Show HHLL 1', 'Show HHLL 2', 'Show Both', 'Show None'])
- upcol1 = input(defval=color.lime, title='Zig Zag 1 Up Color')
- dncol1 = input(defval=color.red, title='Zig Zag 1 Down Color')
- upcol2 = input(defval=color.blue, title='Zig Zag 2 Up Color')
- dncol2 = input(defval=color.purple, title='Zig Zag 2 Down Color')
- txtcol = input(defval=color.black, title='Text Color')
- zz1style = input.string(defval='Dashed', title='Zig Zag 1 Line Style', options=['Dashed', 'Dotted'])
- zz1width = input.int(defval=2, title='Zig zag 1 Line Width', minval=1, maxval=4)
- zz2width = input.int(defval=3, title='Zig zag 2 Line Width', minval=1, maxval=6)
- float ph1x = ta.highestbars(high, prdx1) == 0 ? high : na
- float pl1x = ta.lowestbars(low, prdx1) == 0 ? low : na
- float ph2x = ta.highestbars(high, prdx2) == 0 ? high : na
- float pl2x = ta.lowestbars(low, prdx2) == 0 ? low : na
- var dir1 = 0
- var dir2 = 0
- iff_3 = pl1x and na(ph1x) ? -1 : dir1
- dir1 := ph1x and na(pl1x) ? 1 : iff_3
- iff_4 = pl2x and na(ph2x) ? -1 : dir2
- dir2 := ph2x and na(pl2x) ? 1 : iff_4
- var max_array_sizex = 10 // [5, 2] matrix
- var zigzag1 = array.new_float(0)
- var zigzag2 = array.new_float(0)
- add_to_zigzagx(pointer, value, bindex) =>
- array.unshift(pointer, bindex)
- array.unshift(pointer, value)
- if array.size(pointer) > max_array_sizex
- array.pop(pointer)
- array.pop(pointer)
- update_zigzagx(pointer, value, bindex, dir) =>
- if array.size(pointer) == 0
- add_to_zigzagx(pointer, value, bindex)
- else
- if dir == 1 and value > array.get(pointer, 0) or dir == -1 and value < array.get(pointer, 0)
- array.set(pointer, 0, value)
- array.set(pointer, 1, bindex)
- 0.
- dir1changed = ta.change(dir1)
- if ph1x or pl1x
- if dir1changed
- add_to_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index)
- else
- update_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index, dir1)
- dir2changed = ta.change(dir2)
- if ph2x or pl2x
- if dir2changed
- add_to_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index)
- else
- update_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index, dir2)
- if array.size(zigzag1) >= 6
- var line zzline1 = na
- var label zzlabel1 = na
- float val = array.get(zigzag1, 0)
- int point = math.round(array.get(zigzag1, 1))
- if ta.change(val) or ta.change(point)
- float val1 = array.get(zigzag1, 2)
- int point1 = math.round(array.get(zigzag1, 3))
- if ta.change(val1) == 0 and ta.change(point1) == 0
- line.delete(zzline1)
- label.delete(zzlabel1)
- if showzz == 'Show Zig Zag 1' or showzz == 'Show Both'
- zzline1 := line.new(x1=point, y1=val, x2=point1, y2=val1, color=dir1 == 1 ? upcol1 : dncol1, width=zz1width, style=zz1style == 'Dashed' ? line.style_dashed : line.style_dotted)
- zzline1
- if showhhll == 'Show HHLL 1' or showhhll == 'Show Both'
- hhlltxt = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? 'HH' : 'LH' : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? 'LL' : 'HL'
- labelcol = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? upcol1 : dncol1 : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? dncol1 : upcol1
- zzlabel1 := label.new(x=point, y=val, text=hhlltxt, color=labelcol, textcolor=txtcol, style=dir1 == 1 ? label.style_label_down : label.style_label_up)
- zzlabel1
- if array.size(zigzag2) >= 6
- var line zzline2 = na
- var label zzlabel2 = na
- float val = array.get(zigzag2, 0)
- int point = math.round(array.get(zigzag2, 1))
- if ta.change(val) or ta.change(point)
- float val1 = array.get(zigzag2, 2)
- int point1 = math.round(array.get(zigzag2, 3))
- if ta.change(val1) == 0 and ta.change(point1) == 0
- line.delete(zzline2)
- label.delete(zzlabel2)
- if showzz == 'Show Zig Zag 2' or showzz == 'Show Both'
- zzline2 := line.new(x1=point, y1=val, x2=point1, y2=val1, color=dir2 == 1 ? upcol2 : dncol2, width=zz2width)
- zzline2
- if showhhll == 'Show HHLL 2' or showhhll == 'Show Both'
- hhlltxt = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? 'HH' : 'LH' : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? 'LL' : 'HL'
- labelcol = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? upcol2 : dncol2 : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? dncol2 : upcol2
- zzlabel2 := label.new(x=point, y=val, text=hhlltxt, color=labelcol, textcolor=txtcol, style=dir2 == 1 ? label.style_label_down : label.style_label_up)
- zzlabel2
- //end of this part
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © GokhanGoksin
- //study("ENGUL",shorttitle="engulf",overlay=true)
- x = input(title='çizgi/sağ uzat', defval=5)
- z = input(title='kaynak/seç/üst çizgi', defval=open)
- y = input(title='kaynak/seç/alt çizgi', defval=close)
- //****************************************************
- en = close[1] < open[1] and close > open[1] and low[1] > low
- plotshape(en, style=shape.arrowup, location=location.belowbar)
- //****************************************************** enguluf destek
- if en
- li = line.new(time[1], y[1], time + x * (time - time[1]), y[1], xloc=xloc.bar_time, color=color.red, width=2)
- li
- if en
- label.new(time + x * (time - time[1]), y[1], text='\n' + str.tostring(y[1]), xloc=xloc.bar_time, style=label.style_none, size=size.normal, textcolor=color.white, yloc=yloc.price)
- //********************************************************************** direnç
- if en
- line.new(time[1], z[1], time + x * (time - time[1]), z[1], xloc=xloc.bar_time, color=color.blue, width=2)
- if en
- l = label.new(time + x * (time - time[1]), z[1], text='\n' + str.tostring(z[1]), xloc=xloc.bar_time, style=label.style_none, size=size.normal, textcolor=color.white, yloc=yloc.price)
- l
- //end of this part
- // © weeklystockcharts
- // Candle Type w/ only 3-1 Pine Script
- //study("Candle Type w/only 3-1", overlay=true, precision=0)
- // check for 3-1 inside + up buy
- buyx = high[3] < high[2] and low[3] > low[2] and high[1] < high[2] and low[1] > low[2] and high > high[1] and high[1] <= high[2] and low[1] >= low[2] and not(low < low[1])
- plotchar(buyx, title='Inside + Up Buy Label', text='Up', location=location.belowbar, color=color.new(#4CAF50, 0))
- // check for 3-1 inside + dn sell
- sellx = high[3] < high[2] and low[3] > low[2] and high[1] < high[2] and low[1] > low[2] and low < low[1] and low[1] >= low[2] and high[1] <= high[2] and not(high > high[1])
- plotchar(sellx, title='Inside + Up Buy Label', text='Down', location=location.abovebar, color=color.new(color.red, 0))
- //end of this part
- //study("The system no.1", shorttitle="System no.1", overlay=true)
- _length = input(title='Length', defval=21)
- _offset = input(title='Offset', defval=0)
- _smooth = input.int(title='WMA Length', defval=8, minval=1)
- _source = close
- _lsma = ta.linreg(_source, _length, _offset)
- _lsmaS = ta.wma(_lsma, _smooth)
- _lsmaC = ta.cross(_lsma, _lsmaS) ? (_lsma + _lsmaS) * 0.5 : na
- //iscross() => _lsmaC
- plot(_lsma, color=color.new(color.white, 0), linewidth=2)
- plot(_lsmaS, color=color.new(#2299CC, 0), linewidth=2)
- plotshape(_lsmaC, color=color.new(color.green, 0), style=shape.xcross)
- //barcolor(iscross() ? yellow : na)
- //coppock
- wmaLength = input(title='WMA Length', defval=10)
- longRoCLength = input(title='Long RoC Length', defval=14)
- shortRoCLength = input(title='Short RoC Length', defval=11)
- _crossoverMA = input.int(title='Crossover WMA Lenth', defval=5, minval=1)
- _histogramMultiplier = input.float(title='Histogram Multiplier', defval=2)
- _sourcec = close
- _curve = ta.wma(ta.roc(_sourcec, longRoCLength) + ta.roc(_sourcec, shortRoCLength), wmaLength)
- _curveWMA = ta.wma(_curve, _crossoverMA)
- _h = (_curve - _curveWMA) * _histogramMultiplier
- _curveWMAx = ta.cross(_curve, _curveWMA) ? (_curve + _curveWMA) * 0.5 : na
- //final decision
- check(x, y) =>
- ta.cross(_curve[x], _curveWMA[x]) and ta.cross(_lsma[y], _lsmaS[y])
- check00 = check(0, 0)
- check01 = check(0, 1)
- check02 = check(0, 2)
- check10 = check(1, 0)
- //check11 = check(1,1)
- //check12 = check(1,2)
- check20 = check(2, 0)
- //check21 = check(2,1)
- check03 = check(0, 3)
- //check13 = check(1,3)
- //check23 = check(2,3)
- check30 = check(3, 0)
- //check22 = check(2,2)
- checkcross = check00 ? true : check01 ? true : check02 ? true : check10 ? true : check30 ? true : check20 ? true : check03 ? true : na
- //checking value
- mathcall = (math.abs(ta.lowest(_curve, 50)) + math.abs(ta.highest(_curve, 50))) * 0.3
- highalert = ta.highest(_curve, 50) - mathcall
- lowalert = ta.lowest(_curve, 50) + mathcall
- // sell position
- sellcheck = _curveWMA > _curve ? true : false
- sellcheck1 = _lsma < _lsmaS ? true : false
- sellcheck2 = _curve > highalert
- SELLSIGNAL = checkcross and sellcheck and sellcheck1 and sellcheck2
- barcolor(SELLSIGNAL ? color.yellow : na)
- // buy position
- buycheck = _curveWMA < _curve ? true : false
- buycheck1 = _lsma > _lsmaS ? true : false
- buycheck2 = _curve < lowalert
- BUYSIGNAL = checkcross and buycheck and buycheck1 and buycheck2
- barcolor(BUYSIGNAL ? color.blue : na)
- //end of this part
- //
- //@author BillionaireLau
- //
- //study("Key price levels", overlay=true)
- lbc = input.int(15, title='Number of bars searching backward', minval=1)
- rbc = input.int(15, title='Number of bars searching forward', minval=1)
- showsupres = input(true, title='Show Support/Resistance')
- changebarcol = input(true, title='Change Bar Color')
- mbc = lbc + rbc + 1
- highestbars_2 = ta.highestbars(high, mbc) // Pivot High
- iff_5 = highestbars_2 == -lbc ? high[lbc] : na
- phc = not na(high[mbc]) ? iff_5 : na
- lowestbars_2 = ta.lowestbars(low, mbc) // Pivot Low
- iff_6 = lowestbars_2 == -lbc ? low[lbc] : na
- plc = not na(low[mbc]) ? iff_6 : na
- hlc = int(na)
- iff_7 = plc ? -1 : na // Trend direction
- hlc := phc ? 1 : iff_7
- zz = float(na)
- iff_8 = plc ? plc : na // similar to zigzag but may have multiple highs/lows
- zz := phc ? phc : iff_8
- valuewhen_13 = ta.valuewhen(hlc, hlc, 1)
- valuewhen_14 = ta.valuewhen(zz, zz, 1)
- zz := plc and hlc == -1 and valuewhen_13 == -1 and plc > valuewhen_14 ? na : zz
- valuewhen_15 = ta.valuewhen(hlc, hlc, 1)
- valuewhen_16 = ta.valuewhen(zz, zz, 1)
- zz := phc and hlc == 1 and valuewhen_15 == 1 and phc < valuewhen_16 ? na : zz
- valuewhen_17 = ta.valuewhen(hlc, hlc, 1)
- valuewhen_18 = ta.valuewhen(zz, zz, 1)
- hlc := hlc == -1 and valuewhen_17 == 1 and zz > valuewhen_18 ? na : hlc
- valuewhen_19 = ta.valuewhen(hlc, hlc, 1)
- valuewhen_20 = ta.valuewhen(zz, zz, 1)
- hlc := hlc == 1 and valuewhen_19 == -1 and zz < valuewhen_20 ? na : hlc
- zz := na(hlc) ? na : zz
- findprevious() => // finds previous three points (b, c, d, e)
- ehl = hlc == 1 ? -1 : 1
- loc1 = 0.0
- loc2 = 0.0
- loc3 = 0.0
- loc4 = 0.0
- xx = 0
- for x = 1 to 1000 by 1
- if hlc[x] == ehl and not na(zz[x])
- loc1 := zz[x]
- xx := x + 1
- break
- ehl := hlc
- for x = xx to 1000 by 1
- if hlc[x] == ehl and not na(zz[x])
- loc2 := zz[x]
- xx := x + 1
- break
- ehl := hlc == 1 ? -1 : 1
- for x = xx to 1000 by 1
- if hlc[x] == ehl and not na(zz[x])
- loc3 := zz[x]
- xx := x + 1
- break
- ehl := hlc
- for x = xx to 1000 by 1
- if hlc[x] == ehl and not na(zz[x])
- loc4 := zz[x]
- break
- [loc1, loc2, loc3, loc4]
- axx = float(na)
- bxx = float(na)
- cxx = float(na)
- dxx = float(na)
- exx = float(na)
- if not na(hlc)
- [loc1, loc2, loc3, loc4] = findprevious()
- axx := zz
- bxx := loc1
- cxx := loc2
- dxx := loc3
- exx := loc4
- exx
- _hh = zz and axx > bxx and axx > cxx and cxx > bxx and cxx > dxx
- _ll = zz and axx < bxx and axx < cxx and cxx < bxx and cxx < dxx
- _hl = zz and (axx >= cxx and bxx > cxx and bxx > dxx and dxx > cxx and dxx > exx or axx < bxx and axx > cxx and bxx < dxx)
- _lh = zz and (axx <= cxx and bxx < cxx and bxx < dxx and dxx < cxx and dxx < exx or axx > bxx and axx < cxx and bxx > dxx)
- //Lows
- if _ll
- label.new(bar_index[lbc], na, str.tostring(low[lbc], '####.##'), color=color.lime, textcolor=color.lime, style=label.style_none, yloc=yloc.belowbar)
- if _hl
- label.new(bar_index[lbc], na, str.tostring(low[lbc], '####.##'), color=color.lime, textcolor=color.lime, style=label.style_none, yloc=yloc.belowbar)
- //Highs
- if _lh
- label.new(bar_index[lbc], na, str.tostring(high[lbc], '####.##'), color=color.red, textcolor=color.red, style=label.style_none, yloc=yloc.abovebar)
- if _hh
- label.new(bar_index[lbc], na, str.tostring(high[lbc], '####.##'), color=color.red, textcolor=color.red, style=label.style_none, yloc=yloc.abovebar)
- res = float(na)
- sup = float(na)
- res := _lh ? zz : res[1]
- sup := _hl ? zz : sup[1]
- trend = int(na)
- iff_9 = close < sup ? -1 : nz(trend[1])
- trend := close > res ? 1 : iff_9
- res := trend == 1 and _hh or trend == -1 and _lh ? zz : res
- sup := trend == 1 and _hl or trend == -1 and _ll ? zz : sup
- //plot(showsupres ? res : na, title="Resistance", color=na(res) ? na : color.red, linewidth=2, style=plot.style_circles, offset=-lb)
- //plot(showsupres ? sup : na, title="Support", color=na(sup) ? na : color.blue, linewidth=2, style=plot.style_circles, offset=-lb)
- //end of this part
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement