Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Gann medians", overlay = true, format=format.price, precision=12, max_bars_back=300)
- method1 = input("Median", options=["EMA", "Median", "SMA"])
- length1 = input(12)
- mult1 = input(1, minval=0, maxval=1)
- method2 = input("Median", options=["EMA", "Median", "SMA"])
- length2 = input(27)
- mult2 = input(1, minval=0, maxval=1)
- method3 = input("Median", options=["EMA", "Median", "SMA"])
- length3 = input(56)
- mult3 = input(1, minval=0, maxval=1)
- //----
- Avg(x, length, method) =>
- sma_1 = sma(x, length)
- ema_1 = ema(x, length)
- percentile_linear_interpolation_1 = percentile_linear_interpolation(x, length, 50)
- method == "SMA" ? sma_1 :
- method == "EMA" ? ema_1 : percentile_linear_interpolation_1
- //----
- a1 = highest(length1) - max(close, open)
- b1 = min(close, open) - lowest(length1)
- c1 = max(close, open) + a1 * mult1
- d1 = min(close, open) - b1 * mult1
- a2 = highest(length2) - max(close, open)
- b2 = min(close, open) - lowest(length2)
- c2 = max(close, open) + a2 * mult2
- d2 = min(close, open) - b2 * mult2
- a3 = highest(length3) - max(close, open)
- b3 = min(close, open) - lowest(length3)
- c3 = max(close, open) + a3 * mult3
- d3 = min(close, open) - b3 * mult3
- //----
- e1 = Avg(c1, length1, method1)
- f1 = Avg(d1, length1, method1)
- g1 = 0
- cross_1 = cross(close, f1)
- g1 := cross(close, e1) ? 1 : cross_1 ? 0 : nz(g1[1])
- e2 = Avg(c2, length2, method2)
- f2 = Avg(d2, length2, method2)
- g2 = 0
- cross_2 = cross(close, f2)
- g2 := cross(close, e2) ? 1 : cross_2 ? 0 : nz(g2[1])
- e3 = Avg(c3, length3, method3)
- f3 = Avg(d3, length3, method3)
- g3 = 0
- cross_3 = cross(close, f3)
- g3 := 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, transp=0, trackprice=true)
- 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, transp=0, trackprice=true)
- 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, transp=0, trackprice=true)
- //end of this part
- upperMult = input(title="Upper Deviation", defval=2)
- lowerMult = input(title="Lower Deviation", defval=-2)
- useUpperDev = input(title="Use Upper Deviation", defval=true)
- useLowerDev = input(title="Use Lower Deviation", defval=true)
- showPearson = input(title="Show Pearson's R", defval=true)
- extendLines = input(title="Extend Lines", defval=false)
- len = input(title="Count", defval=100)
- src = input(title="Source", defval=close)
- extend = extendLines ? extend.right : extend.none
- calcSlope(src, len) =>
- if not barstate.islast or len <= 1
- [float(na), float(na), float(na)]
- else
- sumX = 0.0
- sumY = 0.0
- sumXSqr = 0.0
- sumXY = 0.0
- for i = 0 to len - 1
- val = src[i]
- per = i + 1.0
- sumX := sumX + per
- sumY := sumY + val
- sumXSqr := sumXSqr + per * per
- sumXY := sumXY + val * per
- slope = (len * sumXY - sumX * sumY) / (len * sumXSqr - sumX * sumX)
- average = sumY / len
- intercept = average - slope * sumX / len + slope
- [slope, average, intercept]
- [s, aLR, i] = calcSlope(src, len)
- startPrice = i + s * (len - 1)
- endPrice = i
- var line baseLineLR = na
- if na(baseLineLR) and not na(startPrice)
- baseLineLR := line.new(bar_index - len + 1, startPrice, bar_index, endPrice, width=4, extend=extend, color=color.red)
- else
- line.set_xy1(baseLineLR, bar_index - len + 1, startPrice)
- line.set_xy2(baseLineLR, bar_index, endPrice)
- na
- calcDev(src, len, slope, average, intercept) =>
- upDev = 0.0
- dnDev = 0.0
- stdDevAcc = 0.0
- dsxx = 0.0
- dsyy = 0.0
- dsxy = 0.0
- periods = len - 1
- daY = intercept + (slope * periods) / 2
- val = intercept
- for i = 0 to periods
- price = high[i] - val
- if (price > upDev)
- upDev := price
- price := val - low[i]
- if (price > dnDev)
- dnDev := price
- price := src[i]
- dxt = price - average
- dyt = val - daY
- price := price - val
- stdDevAcc := stdDevAcc + price * price
- dsxx := dsxx + dxt * dxt
- dsyy := dsyy + dyt * dyt
- dsxy := dsxy + dxt * dyt
- val := val + slope
- stdDev = sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
- pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / sqrt(dsxx * dsyy)
- [stdDev, pearsonR, upDev, dnDev]
- [stdDev, pearsonR, upDev, dnDev] = calcDev(src, len, s, aLR, i)
- upperStartPrice = startPrice + (useUpperDev ? upperMult * stdDev : upDev)
- upperEndPrice = endPrice + (useUpperDev ? upperMult * stdDev : upDev)
- var line upper = na
- lowerStartPrice = startPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
- lowerEndPrice = endPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
- var line lower = na
- if na(upper) and not na(upperStartPrice)
- upper := line.new(bar_index - len + 1, upperStartPrice, bar_index, upperEndPrice, width=4, extend=extend, color=#0000ff)
- else
- line.set_xy1(upper, bar_index - len + 1, upperStartPrice)
- line.set_xy2(upper, bar_index, upperEndPrice)
- na
- if na(lower) and not na(lowerStartPrice)
- lower := line.new(bar_index - len + 1, lowerStartPrice, bar_index, lowerEndPrice, width=4, extend=extend, color=#0000ff)
- else
- line.set_xy1(lower, bar_index - len + 1, lowerStartPrice)
- line.set_xy2(lower, bar_index, lowerEndPrice)
- na
- // Pearson's R
- var label r = na
- transparent = color.new(color.white, 100)
- label.delete(r[1])
- if showPearson and not na(pearsonR)
- r := label.new(bar_index - len + 1, lowerStartPrice, tostring(pearsonR, "#.################"), color=transparent, textcolor=#0000ff, size=size.normal, style=label.style_labelup)
- //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(title='Length High', type=input.integer, defval=20, minval=1)
- lenL = input(title='Length Low', type=input.integer, defval=20, minval=1)
- fun(src, len, isHigh, _style, _yloc, _color) =>
- p = nz(src[len])
- isFound = true
- for i = 0 to len * 2
- if isHigh and src[i] > p
- isFound := false
- if not isHigh and src[i] < p
- isFound := false
- if isFound and testPeriod()
- label.new(bar_index[len], p, 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_labeldown, yloc.abovebar, color.red)
- fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.green)
- //end of this part
- price = input(type=input.source, 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 = 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
- if m
- v := 0.0
- [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
- if m
- v := 0.0
- [v,lasthigh]
- [v,e] = getLow(lowest(Depth), lastlow, low, Deviation)
- lastlow := e
- zBB = v != 0.0
- [v1,ee1] = getHigh(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
- virtualHigh = zigzagHigh[1] + 1
- if not zSS or (zSS and zigzagDirection == zigzagDirection[1] and high < high[virtualHigh])
- zigzagHigh := nz(zigzagHigh[1]) + 1
- 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_labeldown)
- 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_labelup)
- if (zigzagDirection == zigzagDirection[1])
- label.delete(l_b[1])
- zzPrevHigh = zigzagHigh[1]
- zzPrevLow = zigzagLow[1]
- if not na(zzPrevHigh[1])
- zzPrevHigh := zzPrevHigh[1] + 1
- if not na(zzPrevLow[1])
- zzPrevLow := zzPrevLow[1] + 1
- if zigzagDirection != zigzagDirection[1]
- if zigzagDirection == 1
- zzPrevHigh := zigzagHigh[1] + 1
- if zigzagDirection == 0
- zzPrevLow := zigzagLow[1] + 1
- //end of this part
- // RSI Settings for user
- rsiSource = input(title="RSI Source", type=input.source, defval=close)
- rsiLength = input(title="RSI Length", type=input.integer, defval=7)
- rsiOverbought = input(title="RSI Overbought", type=input.integer, defval=70, minval=50, maxval=100)
- rsiOvesold = input(title="RSI Oversold", type=input.integer, defval=30, minval=1, maxval=50)
- // RSI value based on inbuilt RSI
- rsiValue = 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)
- // 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)
- // 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
- // 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
- // 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
- //@version=4
- //study("momentum zigzag", overlay = true)
- lengthZZZ = input(10, title = "High/Low length")
- hZZZ = highest(high, lengthZZZ * 2 + 1)
- lZZZ = 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()
- if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow)
- lastHigh := high[lengthZZZ]
- timeHigh := bar_index
- dirUp := false
- li := f_drawLine()
- if not dirUp
- if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastHigh)
- lastHigh := high[lengthZZZ]
- timeHigh := bar_index
- line.delete(li)
- li := f_drawLine()
- 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()
- //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 :', type=input.integer)
- percent_of_range_for_trade_zone = input(defval=15.0, title='Percent of the range to use for trade zone', type=input.float) * 0.01
- short_term_top = valuewhen(hSR >= highest(hSR, window), hSR, 0)
- short_term_bot = valuewhen(lSR <= lowest(lSR, window), lSR, 0)
- short_term_resist = change(short_term_top) != 0 ? na : short_term_top
- short_term_suport = change(short_term_bot) != 0 ? na : short_term_bot
- short_term_resist_plot = plot(series=short_term_resist, title='STR', color=color.fuchsia, linewidth=2, style=plot.style_linebr, transp=0)
- short_term_suport_plot = plot(series=short_term_suport, title='STS', color=color.aqua, linewidth=2, style=plot.style_linebr, transp=0)
- fill(short_term_suport_plot,short_term_resist_plot, color=color.aqua, transp=95, title=" Trade Zone ")
- // Calculate entry zone:
- float short_term_resist_trade_limit = na
- float short_term_suport_trade_limit = na
- range = 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]
- else
- short_term_resist_trade_limit := short_term_resist - range * percent_of_range_for_trade_zone
- 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]
- else
- short_term_suport_trade_limit := short_term_suport + range * percent_of_range_for_trade_zone
- short_term_resist_trade_limit_plot = plot(series=short_term_resist_trade_limit, title='', color=color.red, linewidth=1, style=plot.style_linebr, transp=0)
- short_term_suport_trade_limit_plot = plot(series=short_term_suport_trade_limit, title='', color=color.yellow, linewidth=1, style=plot.style_linebr, transp=0)
- //end of this part
- lookback = input(defval=20, title="# of Candles to Look Back", type=input.integer)
- srcAA = "Close"
- pivot_high = iff(srcAA == "Close", pivothigh(high, lookback, lookback), pivothigh(high, lookback, lookback))
- pivot_low = iff(srcAA == "Close", pivotlow(low, lookback, lookback), pivotlow(low, lookback, lookback))
- plot_high = iff(srcAA == "Close", valuewhen(pivot_high, high[lookback], 0), valuewhen(pivot_high, high[lookback], 0))
- plot_low = iff(srcAA == "Close", valuewhen(pivot_low, low[lookback], 0), valuewhen(pivot_low, low[lookback], 0))
- resistance = plot(plot_high, style=plot.style_line, title="Resistance Line", color=color.orange, show_last=1, linewidth=2, trackprice=true)
- support = plot(plot_low, style=plot.style_line, title="Support Line", color=color.orange, 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(5, minval=1, title="Pivot Length Left Hand Side")
- right = input(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
- _rep_text := _rep_text + "\n"
- _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_labelup, textcolor=color.silver, size=size.small)
- // Determine pivots
- pvtLenL = left
- pvtLenR = right
- // Get High and Low Pivot Points
- pvthi_ = pivothigh(high, pvtLenL, pvtLenR)
- pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)
- // Force Pivot completion before plotting.
- pvthi = pvthi_
- pvtlo = pvtlo_
- // ||-----------------------------------------------------------------------------------------------------||
- // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
- valuewhen_1 = valuewhen(pvthi, high[pvtLenR], 1)
- valuewhen_2 = valuewhen(pvthi, high[pvtLenR], 0)
- higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
- valuewhen_3 = valuewhen(pvthi, high[pvtLenR], 1)
- valuewhen_4 = valuewhen(pvthi, high[pvtLenR], 0)
- lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
- valuewhen_5 = valuewhen(pvtlo, low[pvtLenR], 1)
- valuewhen_6 = valuewhen(pvtlo, low[pvtLenR ], 0)
- higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
- valuewhen_7 = valuewhen(pvtlo, low[pvtLenR], 1)
- valuewhen_8 = 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.green, text="HH", offset=-pvtLenR)
- plotshape(ShowHHLL ? higherlow : na, title='HL', location=location.belowbar, color=color.green, text="HL", offset=-pvtLenR)
- plotshape(ShowHHLL ? lowerhigh : na, title='LH', location=location.abovebar, color=color.red, text="LH", offset=-pvtLenR)
- plotshape(ShowHHLL ? lowerlow : na, title='LL', location=location.belowbar, color=color.red, text="LL", offset=-pvtLenR)
- useColors = input(title="Fill with colors?",defval=true)
- isess = session.regular
- t = tickerid(syminfo.prefix, syminfo.ticker, session=isess)
- igaps = barmerge.gaps_off
- yesterdayHigh = security(t,"D",high[1],gaps=igaps, lookahead=barmerge.lookahead_on)
- yesterdayClose = security(t,"D",close[1],gaps=igaps, lookahead=barmerge.lookahead_on)
- yesterdayLow = security(t,"D",low[1],gaps=igaps, 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) => change(time(res)) != 0
- adopt(r, s) => security(syminfo.ticker, r, s)
- high_range = valuewhen(is_newbar('D'),high,0)
- low_range = valuewhen(is_newbar('D'),low,0)
- high_rangeL = valuewhen(is_newbar('D'),high,0)
- low_rangeL = 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(title="Line width for Main levels", type=input.integer, 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(title="Lookback Left", type=input.integer, defval=200, minval=1)
- Lookback2 = input(title="Lookback Right", type=input.integer, defval=0, minval=0)
- VertLR = input(title="Show Vertical Left/Right", type=input.bool, defval=true)
- VertHL = input(title="Show Vertical Highest/Lowest", type=input.bool, defval=true)
- Count = input(title="Show Counts", type=input.bool, defval=true)
- FullCount = input(title="Count All Bars", type=input.bool, defval=false)
- Fibs = input(title="Show Fib Retrace Lines", type=input.bool, defval=false)
- FibsExtHigh = input(title="Show Fib Ext Highs", type=input.bool, defval=false)
- FibsExtLow = input(title="Show Fib Ext Lows", type=input.bool, 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 = max(Lookback1, Lookback2)
- rightHL = 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 = 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 = highestbars(high[rightHL], lengthHL) - rightHL
- // Lowest price, looking back
- lowBack = lowest(low[rightHL], lengthHL)
- lowOffset = 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 = round((timenow - time) / 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.red, linewidth=2, trackprice=true, offset=-9999)
- plot(lowBack, title="Lowest", color=color.green, 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", transp=60, offset=-leftHL + 1)
- bgcolor(VertLRShow ? color.gray : na, title="Vertical Right", transp=60, offset=-rightHL)
- // 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", transp=60, offset=highOffset)
- bgcolor(VertHLShow ? color.green : na, title="Vertical Lowest", transp=60, offset=lowOffset)
- // Fib levels extension and retracement
- priceRange = highBack - lowBack
- plot(FibsExtHigh ? lowBack + 3.618 * priceRange : na, title="3.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtHigh ? lowBack + 2.618 * priceRange : na, title="2.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtHigh ? lowBack + 1.618 * priceRange : na, title="1.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtHigh ? lowBack + 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
- plot(Fibs ? lowBack + 1.1 * priceRange : na, color=#88888800, 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.aqua, linewidth=1, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.618 * priceRange : na, title="0.618", color=color.orange, linewidth=2, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.50 * priceRange : na, title="0.5", color=color.yellow, linewidth=2, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.382 * priceRange : na, title="0.382", color=color.orange, linewidth=2, trackprice=true, offset=-9999)
- plot(Fibs ? lowBack + 0.236 * priceRange : na, title="0.236", color=color.aqua, linewidth=1, trackprice=true, offset=-9999)
- plot(Fibs ? highBack - 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
- plot(FibsExtLow ? highBack - 1.1 * priceRange : na, color=#88888800, 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.fuchsia, linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtLow ? highBack - 2.618 * priceRange : na, title="2.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
- plot(FibsExtLow ? highBack - 3.618 * priceRange : na, title="3.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
- // Lookback bar count
- countMod = mask ? (bar_index - nOffset) % 10 : na
- countInt = mask ? floor((bar_index - nOffset) / 10) % 10 : na
- plotshape(Count and countMod != 0 ? true : na, style=shape.circle, text="-", textcolor=color.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, 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.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
- //end of this part
- //@version=4
- //
- // @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
- plot(iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na), style=plot.style_cross, linewidth=3, color=color.blue, offset=-lb)
- plot(iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na), style=plot.style_cross, linewidth=3, color=color.blue, offset=-lb)
- //end of this part
- //end of this part
- //@version=4
- //study("VJ - Killer BS", overlay=true)
- //======================================================================
- //Jurij
- h_left = input(title="h left", type=input.integer, defval=10)
- h_right = input(title="h right", type=input.integer, defval=10)
- show_ptz = input(title="Show PTZ", type=input.bool, defval=true)
- show_channel = input(title="Show channel", type=input.bool, defval=true)
- //barCount = nz(barCount[1]) + 1
- //check history and realtime PTZ
- h_left_low = lowest(h_left)
- h_left_high = 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 = lowest(h_left + h_right + 1)
- full_zone_high = 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.red, text="Sell")
- plotchar(central_bar_is_lowest ? 1 : 0, offset=-h_right - 1, location=location.belowbar, color=color.green, text="Buy")
- //plot(close)
- //end of this part
- //@version=4
- //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
- //@version=4
- //study("Double Zig Zag with HHLL", overlay = true, max_bars_back = 500)
- prdx1 = input(defval = 8, title="ZigZag Period 1", minval = 2, maxval = 20)
- prdx2 = input(defval = 20, title="ZigZag Period 2", minval = 2, maxval = 50)
- showzz = input(defval = "Show Both", title = "Show Zig Zags", options = ["Show Zig Zag 1", "Show Zig Zag 2", "Show Both", "Show None"])
- showhhll = input(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(defval = "Dashed", title = "Zig Zag 1 Line Style", options = ["Dashed", "Dotted"])
- zz1width = input(defval = 2, title = "Zig zag 1 Line Width", minval = 1, maxval = 4)
- zz2width = input(defval = 3, title = "Zig zag 2 Line Width", minval = 1, maxval = 6)
- float ph1x = highestbars(high, prdx1) == 0 ? high : na
- float pl1x = lowestbars(low, prdx1) == 0 ? low : na
- float ph2x = highestbars(high, prdx2) == 0 ? high : na
- float pl2x = lowestbars(low, prdx2) == 0 ? low : na
- var dir1 = 0
- var dir2 = 0
- dir1 := iff(ph1x and na(pl1x), 1, iff(pl1x and na(ph1x), -1, dir1))
- dir2 := iff(ph2x and na(pl2x), 1, iff(pl2x and na(ph2x), -1, dir2))
- 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 = 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 = 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 = round(array.get(zigzag1, 1))
- if change(val) or change(point)
- float val1 = array.get(zigzag1, 2)
- int point1 = round(array.get(zigzag1, 3))
- if change(val1) == 0 and 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)
- 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)
- if array.size(zigzag2) >= 6
- var line zzline2 = na
- var label zzlabel2 = na
- float val = array.get(zigzag2, 0)
- int point = round(array.get(zigzag2, 1))
- if change(val) or change(point)
- float val1 = array.get(zigzag2, 2)
- int point1 = round(array.get(zigzag2, 3))
- if change(val1) == 0 and 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)
- 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)
- //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
- //@version=4
- //study("ENGUL",shorttitle="engulf",overlay=true)
- x=input(title="çizgi/sağ uzat",type=input.integer,defval=5)
- z=input(title="kaynak/seç/üst çizgi",type=input.source,defval=open)
- y=input(title="kaynak/seç/alt çizgi",type=input.source,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)
- if en
- label.new(time+x*(time-time[1]),y[1],text="\n"+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"+tostring(z[1]),xloc=xloc.bar_time,
- style=label.style_none,size=size.normal,textcolor=color.white,yloc=yloc.price)
- //end of this part
- // © weeklystockcharts
- // @version=4
- // 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=#4CAF50)
- // 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.red)
- //end of this part
- //@version=4
- //study("The system no.1", shorttitle="System no.1", overlay=true)
- _length = input(title="Length", type=input.integer, defval=21)
- _offset = input(title="Offset", type=input.integer, defval=0)
- _smooth = input(title="WMA Length", type=input.integer, defval=8, minval=1)
- _source = close
- _lsma = linreg(_source, _length, _offset)
- _lsmaS = wma(_lsma, _smooth)
- _lsmaC = cross(_lsma, _lsmaS) ? (_lsma + _lsmaS) * 0.5 : na
- //iscross() => _lsmaC
- plot(_lsma, color=color.white, linewidth=2)
- plot(_lsmaS, color=#2299CC, linewidth=2)
- plotshape(_lsmaC, color=color.green, style=shape.xcross)
- //barcolor(iscross() ? yellow : na)
- //coppock
- wmaLength = input(title="WMA Length", type=input.integer, defval=10)
- longRoCLength = input(title="Long RoC Length", type=input.integer, defval=14)
- shortRoCLength = input(title="Short RoC Length", type=input.integer, defval=11)
- _crossoverMA = input(title="Crossover WMA Lenth", defval=5, minval=1)
- _histogramMultiplier = input(title="Histogram Multiplier", defval=2, type=input.float)
- _sourcec = close
- _curve = wma(roc(_sourcec, longRoCLength) + roc(_sourcec, shortRoCLength), wmaLength)
- _curveWMA = wma(_curve, _crossoverMA)
- _h = (_curve - _curveWMA) * _histogramMultiplier
- _curveWMAx = cross(_curve, _curveWMA) ? (_curve + _curveWMA) * 0.5 : na
- //final decision
- check(x, y) =>
- cross(_curve[x], _curveWMA[x]) and 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 = (abs(lowest(_curve, 50)) + abs(highest(_curve, 50))) * 0.3
- highalert = highest(_curve, 50) - mathcall
- lowalert = 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
- //
- //@version=4
- //study("Key price levels", overlay=true)
- lbc = input(15, title="Number of bars searching backward", minval=1)
- rbc = input(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
- phc = iff(not na(high[mbc]), iff(highestbars(high, mbc) == -lbc, high[lbc], na), na) // Pivot High
- plc = iff(not na(low[mbc]), iff(lowestbars(low, mbc) == -lbc, low[lbc], na), na) // Pivot Low
- hlc = int(na)
- hlc := iff(phc, 1, iff(plc, -1, na)) // Trend direction
- zz = float(na)
- zz := iff(phc, phc, iff(plc, plc, na)) // similar to zigzag but may have multiple highs/lows
- zz := iff(plc and hlc == -1 and valuewhen(hlc, hlc, 1) == -1 and plc > valuewhen(zz, zz, 1), na, zz)
- zz := iff(phc and hlc == 1 and valuewhen(hlc, hlc, 1) == 1 and phc < valuewhen(zz, zz, 1), na, zz)
- hlc := iff(hlc == -1 and valuewhen(hlc, hlc, 1) == 1 and zz > valuewhen(zz, zz, 1), na, hlc)
- hlc := iff(hlc == 1 and valuewhen(hlc, hlc, 1) == -1 and zz < valuewhen(zz, zz, 1), na, hlc)
- zz := iff(na(hlc), na, zz)
- findprevious() => // finds previous three points (b, c, d, e)
- ehl = iff(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 := iff(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,tostring(low[lbc], "####.##"),color=color.lime,textcolor=color.lime,style=label.style_none, yloc=yloc.belowbar)
- if _hl
- label.new(bar_index[lbc], na,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, tostring(high[lbc], "####.##"),color=color.red,textcolor=color.red,style=label.style_none, yloc=yloc.abovebar)
- if _hh
- label.new(bar_index[lbc], na, tostring(high[lbc], "####.##"),color=color.red,textcolor=color.red,style=label.style_none, yloc=yloc.abovebar)
- res = float(na)
- sup = float(na)
- res := iff(_lh, zz, res[1])
- sup := iff(_hl, zz, sup[1])
- trend = int(na)
- trend := iff(close > res, 1, iff(close < sup, -1, nz(trend[1])))
- res := iff(trend == 1 and _hh or trend == -1 and _lh, zz, res)
- sup := iff(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
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © ownsov
- //@version=4
- //study(title="OS HiLo Tracking", shorttitle="OS HiLo Tracking", overlay=true, precision=6)
- // HiLo inputs
- high_activate = input(title='Track Previous High', type=input.bool, defval = true)
- high_input = input(title='Days', type=input.integer, defval = 3)
- low_activate = input(title='Track Previous Low', type=input.bool, defval = true)
- low_input = input(title='Days', type=input.integer, defval = 3)
- // HiLo definitions
- daily_hh = nz(highest(high,high_input)[1])
- daily_ll = nz(lowest(low,low_input)[1])
- // HH and LL crossovers
- HHXO=crossover(close, daily_hh)
- LLXO=crossover(daily_ll, close)
- // alerts
- i_HHXO = input(false, "Alert Highest High crossovers")
- i_LLXO = input(false, "Alert Lowest Low crossovers")
- i_repaint = input(true, "Allow Repainting")
- // alert entries only generate entries when allowed in inputs
- enterHHXO = i_HHXO and HHXO and (i_repaint or barstate.isconfirmed)
- enterLLXO = i_LLXO and LLXO and (i_repaint or barstate.isconfirmed)
- // alert plots only when the compound condition is met
- if enterHHXO
- alert("Price crossing up last Highest High (HH is " + tostring(daily_hh, "#.00)"))
- else if enterLLXO
- alert("Price crossing down last Lowest Low (LL is " + tostring(daily_ll, "#.00)"))
- //
- // plot HiLo horizontal line
- plot(high_activate ? daily_hh : na,title = 'Previous Highest High', trackprice=true, offset=-9999, color= color.blue)
- plot(low_activate ? daily_ll : na,title = 'Previous Lowest Low', trackprice=true, offset=-9999, color= color.blue)
- labeltime = time + (time-time[13])
- // previous daily high label
- ldaily_hh = label.new(labeltime, daily_hh, "H (" +tostring(high_input) + ") = " + tostring(daily_hh, "#.##"),
- color = high_activate ? color.new(color.blue,40) : na,
- textcolor = high_activate ? color.white : na,
- textalign = text.align_center,
- style = label.style_label_center,
- xloc = xloc.bar_time)
- label.delete (ldaily_hh[1])
- f_printhh(_texthh) =>
- // Create label on the first bar.
- var _labelhh = label.new(bar_index, na, _texthh, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.normal, text.align_left)
- // On next bars, update the label's x and y position, and the text it displays.
- label.set_xy(_labelhh, bar_index, highest(10)[1])
- label.set_text(_labelhh, _texthh)
- // previous daily low label
- ldaily_ll = label.new(labeltime, daily_ll, "L (" +tostring(low_input) + ") = " + tostring(daily_ll, "#.##"),
- color = low_activate ? color.new(color.blue,40) : na,
- textcolor = low_activate ? color.white : na,
- textalign = text.align_center,
- style = label.style_label_center,
- xloc = xloc.bar_time)
- label.delete (ldaily_ll[1])
- f_printll(_textll) =>
- // Create label on the first bar.
- var _labelll = label.new(bar_index, na, _textll, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.normal, text.align_left)
- // On next bars, update the label's x and y position, and the text it displays.
- label.set_xy(_labelll, bar_index, lowest(10)[1])
- label.set_text(_labelll, _textll)
- //end of this part
Advertisement
Add Comment
Please, Sign In to add comment