//@version=4 study("Gann medians", overlay = true, 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 //@version=4 //study(title="HiLo Activator", overlay=true) length = input(3, minval=1) displace = input(0, minval=0) highsma = sma(high, length) lowsma = sma(low, length) swing = iff(close > highsma[displace], 1, iff(close < lowsma[displace], -1, 0)) mah = highest(high, length) mal = lowest(low, length) var stop = 0.0 stop := iff(swing==1, mal, iff(swing==-1, mah, stop[1])) linecolor = iff(stop < low, color.green, color.red) plot(stop) //end of this part //study(title="TrapTrading (Study)", overlay=true) // input counterTrend = input(defval=false, title="Trade Mode (ON: Counter Trend OFF: Trend Following)", type=input.bool) len1 = input(defval=20, title="Period (1-200)", type=input.integer, minval=1, maxval=200) multiple = input(defval=0.7, title="Multiple", type=input.float) m1 = close - close[len1] lowest_1 = lowest(abs(m1), len1) highest_1 = highest(abs(m1), len1) controlPoint = counterTrend ? lowest_1 == abs(m1) : highest_1 == abs(m1) baseLine = valuewhen(controlPoint, avg(close, close[len1]), 0) // trap line atr = valuewhen(controlPoint, highest(max(max(atr(len1), atr(len1 * 2)), atr(len1 * 3)), len1), 0) line1Up = baseLine + atr * multiple line2Up = baseLine + atr * 2 * multiple line3Up = baseLine + atr * 3 * multiple line4Up = baseLine + atr * 4 * multiple line5Up = baseLine + atr * 5 * multiple line6Up = baseLine + atr * 6 * multiple line7Up = baseLine + atr * 7 * multiple line8Up = baseLine + atr * 8 * multiple line9Up = baseLine + atr * 9 * multiple line10Up = baseLine + atr * 10 * multiple line1Down = baseLine - atr * multiple line2Down = baseLine - atr * 2 * multiple line3Down = baseLine - atr * 3 * multiple line4Down = baseLine - atr * 4 * multiple line5Down = baseLine - atr * 5 * multiple line6Down = baseLine - atr * 6 * multiple line7Down = baseLine - atr * 7 * multiple line8Down = baseLine - atr * 8 * multiple line9Down = baseLine - atr * 9 * multiple line10Down = baseLine - atr * 10 * multiple // draw //barcolor(controlPoint ? color.yellow : close >= baseLine ? color.teal : color.red, title="Candle Color") // find which bar is 5 days away from the current time milliseconds_in_5days = 1000 * 60 * 60 * 24 * 1 // millisecs * secs * min * hours * days leftborder = (timenow - time) < milliseconds_in_5days // true or na when false rightborder = barstate.islast plot(baseLine, title="Base Line", color=color.purple, linewidth=1, style=plot.style_stepline, transp=0, trackprice=true) //plot(leftborder?line1Up:na, title="1Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line2Up:na, title="2Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line3Up:na, title="3Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line4Up:na, title="4Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line5Up:na, title="5Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line6Up:na, title="6Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line7Up:na, title="7Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line8Up:na, title="8Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line9Up:na, title="9Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line10Up:na, title="10Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line1Down:na, title="1Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line2Down:na, title="2Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line3Down:na, title="3Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line4Down:na, title="4Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line5Down:na, title="5Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line6Down:na, title="6Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line7Down:na, title="7Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line8Down:na, title="8Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line9Down:na, title="9Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //plot(leftborder?line10Down:na, title="10Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0) //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 // 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("Candlestick Reversal System", overlay = true) pivotlbar = input(defval = 5, title ="Length to Highest/Lowest") highleftempty = pivothigh(pivotlbar, 0) lowleftempty = pivotlow(pivotlbar, 0) // Wick Reversal System l01 = input(true, title = "Enable Wick Reversal System") wick_multiplier = input(title = "Wick Multiplier", defval = 2.5, step = 0.5, maxval = 20) body_percentage = input(title = "Body Percentage", defval = 0.25, step = 0.1, maxval = 1) O = open C = close H = high L = low Wlongsignal = (C > O) and (O - L) >= ((C - O) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or (C < O) and (C - L) >= ((O - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or (C == O and C != H) and (H - L) >= ((H - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or (O == H and C == H) and (H - L) >= sma((H - L), 50) Wshortsignal = (C < O) and (H - O) >= ((O - C) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or (C > O) and (H - C) >= ((C - O) * wick_multiplier) and (C - L) <= ((H -L) * body_percentage) or (C == O and C != L) and (H - L) >= ((C - L) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or (O == L and C == L) and (H - L) >= sma((H - L), 50) // Exteme Reversal System l02 = input(true, title = "Enable Exteme Reversal System") bodysize = input(title = "Body Size", defval = 0.525, step = 0.05, maxval = 1) barsback = input(title = "Bars Back", defval = 50, maxval = 50) bodymultiplier = input(title = "Body Multiplier", defval = 2, step = 0.25, maxval = 5) mybodysize = abs(C - O) AverageBody = sma(mybodysize, barsback) mycandlesize = (H - L) AverageCandle = sma(mycandlesize, barsback) Elongsignal = ((O[1] - C[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((O[1] - C[1]) > AverageBody) and (C > O) Eshortsignal = ((C[1] - O[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((C[1] - O[1]) > AverageBody) and (O > C) // outside Reversal System l03 = input(true, title = "Enable Outside Reversal System") BarMultiplier = input(title = "Body Multiplier", defval = 1.25, step = 0.05, maxval = 3.5) BarsBack = input(title = "Bars Back", defval = 50, maxval = 250) AverageCandle1 = sma(mycandlesize, BarsBack) Olongsignal = L < L[1] and C > H[1] and (H - L) >= AverageCandle1 * BarMultiplier Oshortsignal = H > H[1] and C < L[1] and (H - L) >= AverageCandle1 * BarMultiplier // Doji Reversal System l04 = input(true, title = "Enable Doji Reversal System") percentage = input(title = "Body Percentage", defval = 0.10, step = 0.1, minval = 0.1) frangehl = H[1] - L[1] frangeco = abs(C[1] - O[1]) sma10 = sma(close, 10) Dshortsignal = (frangeco <= frangehl * percentage and C < L[1] and L[1] > sma10 and C < O) or (C < L[2] and C[1] >= L[2] and frangeco <= frangeco * percentage and C < O and L[2] > sma10) Dlongsignal = (frangeco <= frangehl * percentage and C > H[1] and H[1] < sma10 and C > O) or (C > H[2] and C[1] <= H[2] and frangeco <= frangeco * percentage and C > O and H[2] < sma10) longsignal = lowleftempty and ((l01 and Wlongsignal) or (l02 and Elongsignal) or (l03 and Olongsignal) or (l04 and Dlongsignal)) shortsignal = highleftempty and ((l01 and Wlongsignal) or (l02 and Eshortsignal) or (l03 and Oshortsignal) or (l04 and Dshortsignal)) plotshape(longsignal, color = color.blue, location = location.belowbar, style = shape.triangleup, size = size.small) plotshape(shortsignal, color = color.red, location = location.abovebar, style = shape.triangledown, size = size.small) //end of this part //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 //@version=4 //study("Fork Handles by @treypeng", overlay=true) // modify / use / steal this script in any way you like idc // user customisation input showarrows = input(title="Show single pivot/swing arrows", type=input.bool, defval=true) showcols = input(title="Show double pivot/swing bar colours", type=input.bool, defval=true) // First determine which palette of hues we're going for // if downcandle=true then we want reds, pinks, browns etc // if updcandle=true then we want greens, blues, turqoise etc etc downcandle = close[2] < open[2] upcandle = close[2] > open[2] // Do we have a double (five) candle swing? ispivotlow = not na(pivotlow(low, 2, 2)) ispivothigh = not na(pivothigh(high, 2, 2)) // simple candle swings pivotlow_1 = pivotlow(low, 1, 1) pl2 = showarrows ? pivotlow_1 : na pivothigh_1 = pivothigh(high, 1, 1) ph2 = showarrows ? pivothigh_1 : na // draw the simple swings plotshape(pl2, style=shape.triangleup, location=location.belowbar, color=color.gray, size=size.tiny, offset=-1) plotshape(ph2, style=shape.triangledown, location=location.abovebar, color=color.gray, size=size.tiny, offset=-1) // add this line back in for cool text so your charts look confusing and professional to n00bs //plotchar(pl2, title='CR', char='△', location=location.belowbar, color=gray, offset=-2, text='CR', textcolor=gray, size=size.tiny) ispivotboth = ispivothigh and ispivotlow ispivothighup = ispivothigh and upcandle ispivothighdown = ispivothigh and downcandle ispivotlowup = ispivotlow and upcandle ispivotlowdown = ispivotlow and downcandle ispivotbothup = ispivotboth and upcandle ispivotbothdown = ispivotboth and downcandle col = ispivotbothup ? color.white : ispivotbothdown ? color.gray : ispivothighup ? color.lime : ispivothighdown ? color.red : ispivotlowup ? color.blue : ispivotlowdown ? #D2691E : na barcolor(showcols ? col : na, -2) //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 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]) //end of this part //@version=4 // ══════════════════════════════════════════════════════════════════════════════════════════════════ // //# * ══════════════════════════════════════════════════════════════════════════════════════════════ //# * //# * Study : Price Action - Support & Resistance //# * - Support & Resistance based on Volume //# * - Volume Weighted Colored Bars and Sign of Exhaustion Indication Add-On //# * Author : @MCK //# * //# * Revision History //# * Release : Jan 25, 2021 //# * Update : Jan 26, 2021 : User Request : Add price option for intruments with no volume data //# * Update : Mar 18, 2021 : Ability to draw lines and cofigure alerts when volume spikes detected //# * Update : Mar 21, 2021 : Ability to draw lines and cofigure alerts when high volatility detected //# * - line customization abaility //# * //# * ══════════════════════════════════════════════════════════════════════════════════════════════ // ══════════════════════════════════════════════════════════════════════════════════════════════════ // //study("Price Action - Support & Resistance by MCK", "S&R ʙʏ MCK", true, max_lines_count = 500) // -Inputs ══════════════════════════════════════════════════════════════════════════════════════ // // ---------------------------------------------------------------------------------------------- // // Definitions ---------------------------------------------------------------------------------- // group_support_and_resistance = "Consecutively Increasing Volume / Price" tooltip_support_and_resistance = "Moments where\n" + "- price is bullish or bearish consecutively for minimum 3 bars and on increasing volume with at least one bar's volume is above volume moving average\n" + "or\n" + "- price is bullish or bearish consecutively on increasing/decreasing price for minimum 3 bars" group_volume_spike_sign_of_exhaustion = "Volume Spike - Sign of Exhaustion" tooltip_volume_spike_sign_of_exhaustion = "Moments where\n" + "huge volume detected : current volume is grater than the product of the theshold value and volume moving average\n" + "presents idea : huge volume may be a sign of exhaustion and may lead to sharp reversals" group_high_volatility = "High Volatility" tooltip_high_volatility = "Moments where\n" + "price range of the current bar is grater than the product of the theshold value and average true range value of defined period" group_volume_weighted_colored_bars = "Volume Weighted Colored Bars" tooltip_volume_weighted_colored_bars = "Colors bars based on the bar's volume relative to volume moving average\n" + "trading tip : a potential breakout trading opportunity may occur when price moves above a resistance level or moves below a support level on increasing volume" tooltip_volume_moving_average = "Volume simple moving average, serves as reference to\n" + "- Support and Resistance,\n" + "- Volume Weighted Colored Bars,\n" + "- Volume Spike - Sign of Exhaustion\n" + "calculations" // User Input Declarations ---------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- // // Volume Spike - Sign of Exhaustion ------------------------------------------------------------ // i_vSpikeThresh = input(3 , "Volume Spike Theshold", minval = .1, step = .1 , inline = "SRS1", group = group_volume_spike_sign_of_exhaustion) i_isSnRSpike = input(true , "S & R Lines" , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion) i_spLnColor = input(#ab47bc, "" , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion) i_spLnWidth = input(2 , "" , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion) i_spLnStyle = input("Solid" , "", options = ["Dashed", "Dotted", "Solid"] , inline = "SRS2", group = group_volume_spike_sign_of_exhaustion) i_spLnBullLevel = input("High" , "Levels : Bullish", options = ["High", "Close", "Both"], inline = "SRS3", group = group_volume_spike_sign_of_exhaustion) i_spLnBearLevel = input("Low" , " Bearish", options = ["Low" , "Close", "Both"] , inline = "SRS3", group = group_volume_spike_sign_of_exhaustion) // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- // // Volume Moving Average : Base ----------------------------------------------------------------- // i_vSMA = sma(nz(volume), input(90, "Volume Moving Average Length", group = "General Settings", tooltip = tooltip_volume_moving_average)) // -Calculations ════════════════════════════════════════════════════════════════════════════════ // // ---------------------------------------------------------------------------------------------- // // Definitions ---------------------------------------------------------------------------------- // nzVolume = nz(volume) risingVol = nzVolume >= nzVolume[1] bullCandle = close > open bearCandle = close < open risingPrice = close > close[1] fallingPrice = close < close[1] lwstPrice = lowest (low , 3) hstPrice = highest(high, 3) ranged = abs(high - low) x2 = timenow // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- // // Volume Spike - Sign of Exhaustion ------------------------------------------------------------ // exhaustVol = nzVolume > i_vSpikeThresh * i_vSMA x1V = valuewhen(exhaustVol, time, 0) // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- // // -Plotting ════════════════════════════════════════════════════════════════════════════════════ // f_getStyle(_s) => _s == "Solid" ? line.style_solid : _s == "Dotted" ? line.style_dotted : line.style_dashed // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- // // Volume Spike - Sign of Exhaustion ------------------------------------------------------------ // var line spikeLine = na var line spikeLine1 = na var line spikeLine2 = na var line spikeLine3 = na if i_isSnRSpike and exhaustVol if bullCandle if i_spLnBullLevel == "High" if exhaustVol == exhaustVol[1] and not bearCandle[1] line.delete(spikeLine[1]) spikeLine := line.new(x1V, high , x2, high , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) else if i_spLnBullLevel == "Close" if exhaustVol == exhaustVol[1] and not bearCandle[1] line.delete(spikeLine[1]) spikeLine := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) else if exhaustVol == exhaustVol[1] and not bearCandle[1] line.delete(spikeLine1[1]) line.delete(spikeLine2[1]) line.delete(spikeLine3[1]) spikeLine1 := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) spikeLine2 := line.new(x1V, avg(high, close), x2, avg(high, close), xloc.bar_time, extend.none, i_spLnColor, f_getStyle("Dotted") , i_spLnWidth - 1) spikeLine3 := line.new(x1V, high , x2, high , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) if bearCandle if i_spLnBearLevel == "Low" if exhaustVol == exhaustVol[1] and not bullCandle[1] line.delete(spikeLine[1]) spikeLine := line.new(x1V, low , x2, low , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) else if i_spLnBearLevel == "Close" if exhaustVol == exhaustVol[1] and not bullCandle[1] line.delete(spikeLine[1]) spikeLine := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) else if exhaustVol == exhaustVol[1] and not bullCandle[1] line.delete(spikeLine1[1]) line.delete(spikeLine2[1]) line.delete(spikeLine3[1]) spikeLine1 := line.new(x1V, low , x2, low , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) spikeLine2 := line.new(x1V, avg(low, close) , x2, avg(low, close) , xloc.bar_time, extend.none, i_spLnColor, f_getStyle("Dotted") , i_spLnWidth - 1) spikeLine3 := line.new(x1V, close , x2, close , xloc.bar_time, extend.none, i_spLnColor, f_getStyle(i_spLnStyle), i_spLnWidth) alertcondition(crossover(nzVolume, i_vSMA * i_vSpikeThresh), "Volume Spikes", "sign of exhaustion, huge volume increase detected\n{{exchange}}:{{ticker}}->\nOpen = {{open}}, Current = {{close}},\nTime = {{time}}") // ---------------------------------------------------------------------------------------------- /