Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Gaann medians MA targets", overlay=true, max_bars_back=500, max_lines_count=500, max_labels_count=500)
- // Inputs
- method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length1 = input(56)
- mult1 = input.int(1, minval=0, maxval=1)
- method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length2 = input(100)
- mult2 = input.int(1, minval=0, maxval=1)
- method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
- length3 = input(200)
- mult3 = input.int(1, minval=0, maxval=1)
- // Calculation of medians
- Avg(x, length, method) =>
- sma_1 = ta.sma(x, length)
- ema_1 = ta.ema(x, length)
- percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
- method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
- a1 = ta.highest(length1) - math.max(close, open)
- b1 = math.min(close, open) - ta.lowest(length1)
- c1 = math.max(close, open) + a1 * mult1
- d1 = math.min(close, open) - b1 * mult1
- a2 = ta.highest(length2) - math.max(close, open)
- b2 = math.min(close, open) - ta.lowest(length2)
- c2 = math.max(close, open) + a2 * mult2
- d2 = math.min(close, open) - b2 * mult2
- a3 = ta.highest(length3) - math.max(close, open)
- b3 = math.min(close, open) - ta.lowest(length3)
- c3 = math.max(close, open) + a3 * mult3
- d3 = math.min(close, open) - b3 * mult3
- // Calculation of volume
- volLength = input.int(20, minval=1, title='Volume Length')
- volMultiplier = input.float(1.0, title='Volume Multiplier')
- volAvg = ta.sma(volume, volLength) * volMultiplier
- // Calculation of signals and liquidity levels
- e1 = Avg(c1, length1, method1)
- f1 = Avg(d1, length1, method1)
- gx1 = 0
- cross_1 = ta.cross(close, f1)
- gx1 := ta.cross(close, e1) ? 1 : cross_1 ? 0 : nz(gx1[1])
- e2 = Avg(c2, length2, method2)
- f2 = Avg(d2, length2, method2)
- gx2 = 0
- cross_2 = ta.cross(close, f2)
- gx2 := ta.cross(close, e2) ? 1 : cross_2 ? 0 : nz(gx2[1])
- e3 = Avg(c3, length3, method3)
- f3 = Avg(d3, length3, method3)
- gx3 = 0
- cross_3 = ta.cross(close, f3)
- gx3 := ta.cross(close, e3) ? 1 : cross_3 ? 0 : nz(gx3[1])
- // Calculation of liquidity levels with volume
- hilo1 = gx1 * f1 + (1 - gx1) * e1
- css1 = gx1 == 1 ? color.green : color.red
- plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- hilo2 = gx2 * f2 + (1 - gx2) * e2
- css2 = gx2 == 1 ? color.green : color.red
- plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- hilo3 = gx3 * f3 + (1 - gx3) * e3
- css3 = gx3 == 1 ? color.green : color.red
- plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
- //end of the code
- //@version=5
- //indicator(title='HiLo Activator', overlay=true)
- length = input.int(3, minval=1)
- displace = input.int(0, minval=0)
- highsma = ta.sma(high, length)
- lowsma = ta.sma(low, length)
- iff_1 = close < lowsma[displace] ? -1 : 0
- swing = close > highsma[displace] ? 1 : iff_1
- mah = ta.highest(high, length)
- mal = ta.lowest(low, length)
- var stop = 0.0
- iff_2 = swing == -1 ? mah : stop[1]
- stop := swing == 1 ? mal : iff_2
- linecolor = stop < low ? color.green : color.red
- plot(stop, show_last=1, linewidth=1, trackprice=true, transp=0)
- //end of this part
- //study(title="TrapTrading (Study)", overlay=true)
- // input
- counterTrend = input(defval=false, title='Trade Mode (ON: Counter Trend OFF: Trend Following)')
- len1 = input.int(defval=20, title='Period (1-200)', minval=1, maxval=200)
- multiple = input(defval=0.7, title='Multiple')
- m1 = close - close[len1]
- lowest_1 = ta.lowest(math.abs(m1), len1)
- highest_1 = ta.highest(math.abs(m1), len1)
- controlPoint = counterTrend ? lowest_1 == math.abs(m1) : highest_1 == math.abs(m1)
- baseLine = ta.valuewhen(controlPoint, math.avg(close, close[len1]), 0)
- // trap line
- atr = ta.valuewhen(controlPoint, ta.highest(math.max(math.max(ta.atr(len1), ta.atr(len1 * 2)), ta.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.new(color.purple, 0), linewidth=1, style=plot.style_stepline, show_last=1, linewidth=1, trackprice=true, transp=0)
- //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 by 1
- val = src[i]
- per = i + 1.0
- sumX += per
- sumY += val
- sumXSqr += per * per
- sumXY += val * per
- sumXY
- 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)
- baseLineLR
- 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 by 1
- price = high[i] - val
- if price > upDev
- upDev := price
- upDev
- price := val - low[i]
- if price > dnDev
- dnDev := price
- dnDev
- price := src[i]
- dxt = price - average
- dyt = val - daY
- price -= val
- stdDevAcc += price * price
- dsxx += dxt * dxt
- dsyy += dyt * dyt
- dsxy += dxt * dyt
- val += slope
- val
- stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
- pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.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)
- upper
- 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)
- lower
- 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, str.tostring(pearsonR, '#.################'), color=transparent, textcolor=#0000ff, size=size.normal, style=label.style_label_up)
- r
- //end of this part
- //@version=5
- //indicator("MTF SR with Angle, Square of 9, Phi, Golden Ratio, and Pi", overlay=true)
- // Define input variables
- //src = input(close, title="Source")
- res = input("D", title="Resolution")
- // Define time frames
- tf1 = res == "1D" ? "D" : res == "1W" ? "W" : res == "1M" ? "M" : na
- tf2 = res == "1D" ? "W" : res == "1W" ? "M" : res == "1M" ? "3M" : na
- tf3 = res == "1D" ? "M" : res == "1W" ? "3M" : res == "1M" ? "6M" : na
- tf4 = res == "1D" ? "3M" : res == "1W" ? "6M" : res == "1M" ? "12M" : na
- // Define support and resistance levels
- sr1 = request.security(syminfo.tickerid, tf1, high[1])
- sr2 = request.security(syminfo.tickerid, tf2, high[1])
- sr3 = request.security(syminfo.tickerid, tf3, high[1])
- sr4 = request.security(syminfo.tickerid, tf4, high[1])
- sup1 = request.security(syminfo.tickerid, tf1, low[1])
- sup2 = request.security(syminfo.tickerid, tf2, low[1])
- sup3 = request.security(syminfo.tickerid, tf3, low[1])
- sup4 = request.security(syminfo.tickerid, tf4, low[1])
- // Draw support and resistance levels
- plot(sr1, color=color.yellow, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(sr2, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(sr3, color=color.red, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(sr4, color=color.maroon, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(sup1, color=color.yellow, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(sup2, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(sup3, color=color.red, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(sup4, color=color.maroon, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- // Calculate 45 degree angle from lowest low
- lowestLow = ta.lowest(low, 100)
- angle = math.atan((lowestLow - lowestLow[1]) / (time - time[1])) * 180 / math.acos(-1)
- plot(lowestLow, color=color.green, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(lowestLow + (ta.highest(high, 100) - lowestLow) * math.tan(angle), color=color.green, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- // Calculate Square of 9 levels
- squareOf9 = 1.414 * math.sqrt(math.abs(close - close[1])) + close[1]
- plot(squareOf9, color=color.blue, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- // Calculate Phi, Golden Ratio, and Pi levels
- phi = close * 0.618 + close[1] * 0.382
- goldenRatio = close * 1.618 - close[1] * 0.618
- pi = close * 3.14 / 100
- plot(phi, color=color.purple, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(goldenRatio, color=color.fuchsia, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(pi, color=color.aqua, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- // Calculate 3, 6, 9 algo levels
- three = close * 1.03
- six = close * 1.06
- nine = close * 1.09
- plot(three, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(six, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- plot(nine, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
- //end of this part
- // © Julien_Eche
- //@version=5
- //indicator(title="Ultimate Trend Channel", shorttitle="Ultimate Trend Channel", overlay=true)
- // User inputs for defining length of each group
- len_group1 = input(title="Length 1", defval=220)
- len_group2 = input(title="Length 2", defval=252)
- len_group3 = input(title="Length 3", defval=315)
- len_group4 = input(title="Length 4", defval=378)
- len_group5 = input(title="Length 5", defval=441)
- len_group6 = input(title="Length 6", defval=504)
- len_group7 = input(title="Length 7", defval=567)
- len_group8 = input(title="Length 8", defval=630)
- len_group9 = input(title="Length 9", defval=693)
- len_group10 = input(title="Length 10", defval=756)
- len_group11 = input(title="Length 11", defval=882)
- len_group12 = input(title="Length 12", defval=1008)
- len_group13 = input(title="Length 13", defval=1134)
- len_group14 = input(title="Length 14", defval=1260)
- len_group15 = input(title="Length 15", defval=1449)
- len_group16 = input(title="Length 16", defval=1638)
- len_group17 = input(title="Length 17", defval=1827)
- len_group18 = input(title="Length 18", defval=2016)
- len_group19 = input(title="Length 19", defval=2331)
- len_group20 = input(title="Length 20", defval=2646)
- len_group21 = input(title="Length 21", defval=2961)
- mult = 1.0
- //src = close
- // Function for calculating upper band
- upperBand(src, length) =>
- ta.linreg(src, length, 0) + mult * ta.stdev(src, length)
- // Function for calculating lower band
- lowerBand(src, length) =>
- ta.linreg(src, length, 0) - mult * ta.stdev(src, length)
- // Calculation of upper and lower bands for each group
- upperband1 = upperBand(src, len_group1)
- lowerband1 = lowerBand(src, len_group1)
- upperband2 = upperBand(src, len_group2)
- lowerband2 = lowerBand(src, len_group2)
- upperband3 = upperBand(src, len_group3)
- lowerband3 = lowerBand(src, len_group3)
- upperband4 = upperBand(src, len_group4)
- lowerband4 = lowerBand(src, len_group4)
- upperband5 = upperBand(src, len_group5)
- lowerband5 = lowerBand(src, len_group5)
- upperband6 = upperBand(src, len_group6)
- lowerband6 = lowerBand(src, len_group6)
- upperband7 = upperBand(src, len_group7)
- lowerband7 = lowerBand(src, len_group7)
- upperband8 = upperBand(src, len_group8)
- lowerband8 = lowerBand(src, len_group8)
- upperband9 = upperBand(src, len_group9)
- lowerband9 = lowerBand(src, len_group9)
- upperband10 = upperBand(src, len_group10)
- lowerband10 = lowerBand(src, len_group10)
- upperband11 = upperBand(src, len_group11)
- lowerband11 = lowerBand(src, len_group11)
- upperband12 = upperBand(src, len_group12)
- lowerband12 = lowerBand(src, len_group12)
- upperband13 = upperBand(src, len_group13)
- lowerband13 = lowerBand(src, len_group13)
- upperband14 = upperBand(src, len_group14)
- lowerband14 = lowerBand(src, len_group14)
- upperband15 = upperBand(src, len_group15)
- lowerband15 = lowerBand(src, len_group15)
- upperband16 = upperBand(src, len_group16)
- lowerband16 = lowerBand(src, len_group16)
- upperband17 = upperBand(src, len_group17)
- lowerband17 = lowerBand(src, len_group17)
- upperband18 = upperBand(src, len_group18)
- lowerband18 = lowerBand(src, len_group18)
- upperband19 = upperBand(src, len_group19)
- lowerband19 = lowerBand(src, len_group19)
- upperband20 = upperBand(src, len_group20)
- lowerband20 = lowerBand(src, len_group20)
- upperband21 = upperBand(src, len_group21)
- lowerband21 = lowerBand(src, len_group21)
- // Calculate average of all upper and lower bands
- averageBand = (upperband1 + lowerband1 + upperband2 + lowerband2 + upperband3 + lowerband3 + upperband4 + lowerband4 + upperband5 + lowerband5 + upperband6 + lowerband6 + upperband7 + lowerband7 + upperband8 + lowerband8 + upperband9 + lowerband9 + upperband10 + lowerband10 + upperband11 + lowerband11 + upperband12 + lowerband12 + upperband13 + lowerband13 + upperband14 + lowerband14 + upperband15 + lowerband15 + upperband16 + lowerband16 + upperband17 + lowerband17 + upperband18 + lowerband18 + upperband19 + lowerband19 + upperband20 + lowerband20 + upperband21 + lowerband21) / 42
- // Calculate average of all upper bands
- averageUpperBand = (upperband1 + upperband2 + upperband3 + upperband4 + upperband5 + upperband6 + upperband7 + upperband8 + upperband9 + upperband10 + upperband11 + upperband12 + upperband13 + upperband14 + upperband15 + upperband16 + upperband17 + upperband18 + upperband19 + upperband20 + upperband21) / 21
- // Calculate average of all lower bands
- averageLowerBand = (lowerband1 + lowerband2 + lowerband3 + lowerband4 + lowerband5 + lowerband6 + lowerband7 + lowerband8 + lowerband9 + lowerband10 + lowerband11 + lowerband12 + lowerband13 + lowerband14 + lowerband15 + lowerband16 + lowerband17 + lowerband18 + lowerband19 + lowerband20 + lowerband21) / 21
- // Define fill color for the area between upper and lower bands
- fillcolor = color.rgb(0, 191, 255, 95)
- // Plot upper and lower bands and fill the area between them
- fill(plot(averageUpperBand, title="Average Upper Band", color=color.rgb(14, 116, 212), linewidth=1), plot(averageLowerBand, title="Average Lower Band", color=color.rgb(14, 116, 212), linewidth=1), color=fillcolor)
- // Plot average band
- plot(averageBand, title="Ultimate Trend Line", color=color.rgb(243, 128, 33), linewidth=1)
Advertisement
Add Comment
Please, Sign In to add comment