diff --git a/xIndicators/x-saherelm.ut.indicator.pine b/xIndicators/x-saherelm.ut.indicator.pine new file mode 100644 index 0000000..db9e600 --- /dev/null +++ b/xIndicators/x-saherelm.ut.indicator.pine @@ -0,0 +1,113 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XUT Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// + +// +//@version=5 +indicator(title="SaherElm XUT Indicator", shorttitle = "XUT_IND", overlay = true) + +// +// START Inputs .... +// +sensitivity = input(2, title = "Key Vaule. 'This changes the sensitivity'") +atrPeriod = input(10, title = "ATR Period") +maPeriod = input.int(50, minval=1, title="MA Period") +// +// END Inputs .... +// + +// +// START Functions .... +// +ma(source, length, type) => + switch type + "SMA" => ta.sma(source, length) + "EMA" => ta.ema(source, length) + "SMMA (RMA)" => ta.rma(source, length) + "WMA" => ta.wma(source, length) + "VWMA" => ta.vwma(source, length) +// +// END Functions .... +// + +// +// START Calculations .... +// +// +src = close +maMethod = "SMA" +maSmoothingLength = 5 + +// +// Ma Calculations ... +out = ta.sma(src, maPeriod) +maSmoothingLine = ma(out, maSmoothingLength, maMethod) + +// +xATR = ta.atr(atrPeriod) +nLoss = sensitivity * xATR + +// +xATRTrailingStop = 0.0 +xATRTrailingStop := (src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0)) ? math.max(nz(xATRTrailingStop[1]) , src - nLoss) : (src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0)) ? math.min(nz(xATRTrailingStop[1]), src + nLoss) : (src > nz(xATRTrailingStop[1], 0)) ? src - nLoss : src + nLoss + +// +pos = 0 +pos := (src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0)) ? 1 : (src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0)) ? -1 : nz(pos[1], 0) + +// +xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue + +// +ema = ta.ema(src,1) +above = ta.crossover(ema, xATRTrailingStop) +below = ta.crossover(xATRTrailingStop, ema) + +// +buy = src > xATRTrailingStop and above +sell = src < xATRTrailingStop and below + +// +barbuy = src > xATRTrailingStop +barsell = src < xATRTrailingStop +// +// END Calculations .... +// + +// +// START Plots .... +// +// +// MA Plots ... +plot(out, color=color.blue, title="MA", offset=0) +plot(maSmoothingLine, title="Smoothing Line", color=#f37f20, offset=0, display=display.none) + +// +// UT Plots ... +plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, size = size.tiny) +plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, size = size.tiny) + +// +barcolor(barbuy ? color.green : na) +barcolor(barsell ? color.red : na) + +// +alertcondition(buy, "UT Long", "UT Long") +alertcondition(sell, "UT Short", "UT Short") +// +// END Plots .... +// + +// +// START Alerts ... +// +// END Alerts ... +// diff --git a/xOscillators/x-saherelm.stc.pine b/xOscillators/x-saherelm.stc.pine new file mode 100644 index 0000000..8371bee --- /dev/null +++ b/xOscillators/x-saherelm.stc.pine @@ -0,0 +1,93 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center STC Histogram +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// + +// +//@version=5 +indicator(title="SaherElm STC Histogram", shorttitle = "XSTC_OSC", overlay = false) + +// +// START Inputs .... +// +length = input(12, 'Length') +fastPeriod = input(26, 'FastLength') +slowPeriod = input(50, 'SlowLength') +// +// END Inputs .... +// + +// +// START Functions .... +// +AAAA(BBB, BBBB, BBBBB) => + fastMA = ta.ema(BBB, BBBB) + slowMA = ta.ema(BBB, BBBBB) + AAAA = fastMA - slowMA + AAAA + +AAAAA(EEEEEE, BBBB, BBBBB) => + AAA = input(0.5) + var CCCCC = 0.0 + var DDD = 0.0 + var DDDDDD = 0.0 + var EEEEE = 0.0 + BBBBBB = AAAA(close, BBBB, BBBBB) + CCC = ta.lowest(BBBBBB, EEEEEE) + CCCC = ta.highest(BBBBBB, EEEEEE) - CCC + CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1]) + DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1]) + DDDD = ta.lowest(DDD, EEEEEE) + DDDDD = ta.highest(DDD, EEEEEE) - DDDD + DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1]) + EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1]) + EEEEE +// +// END Functions .... +// + +// +// START Calculations .... +// +maValue = AAAAA(length, fastPeriod, slowPeriod) +mColor = maValue > maValue[1] ? color.new(color.green, 20) : color.new(color.red, 20) + +// +// +// END Calculations .... +// + +// +// START Plots .... +// +// +plot(maValue, color = mColor, title = 'XSTC', linewidth = 2) + +// +ul = plot(25, color=color.new(color.gray, 70)) +ll = plot(75, color=color.new(color.gray, 70)) +fill(ul, ll, color=color.new(color.gray, 96)) +// +// END Plots .... +// + +// +// START Alerts ... +// +// +if maValue[3] <= maValue[2] and maValue[2] > maValue[1] and maValue > 75 + alert("Red", alert.freq_once_per_bar) + +// +if maValue[3] >= maValue[2] and maValue[2] < maValue[1] and maValue < 25 + alert("Green", alert.freq_once_per_bar) +// +// END Alerts ... +// diff --git a/xSamples/indicators/UT-Bot-Alerts.pine b/xSamples/indicators/UT-Bot-Alerts.pine new file mode 100644 index 0000000..3dfe41b --- /dev/null +++ b/xSamples/indicators/UT-Bot-Alerts.pine @@ -0,0 +1,42 @@ +//@version=4 +study(title="UT Bot Alerts", overlay = true) + +// Inputs +a = input(1, title = "Key Vaule. 'This changes the sensitivity'") +c = input(10, title = "ATR Period") +h = input(false, title = "Signals from Heikin Ashi Candles") + +xATR = atr(c) +nLoss = a * xATR + +src = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : close + +xATRTrailingStop = 0.0 +xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss), + iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss), + iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss))) + +pos = 0 +pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1, + iff(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) + +xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue + +ema = ema(src,1) +above = crossover(ema, xATRTrailingStop) +below = crossover(xATRTrailingStop, ema) + +buy = src > xATRTrailingStop and above +sell = src < xATRTrailingStop and below + +barbuy = src > xATRTrailingStop +barsell = src < xATRTrailingStop + +plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny) +plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny) + +barcolor(barbuy ? color.green : na) +barcolor(barsell ? color.red : na) + +alertcondition(buy, "UT Long", "UT Long") +alertcondition(sell, "UT Short", "UT Short") \ No newline at end of file diff --git a/xSamples/indicators/sma.pine b/xSamples/indicators/sma.pine new file mode 100644 index 0000000..6272fae --- /dev/null +++ b/xSamples/indicators/sma.pine @@ -0,0 +1,21 @@ +//@version=5 +indicator(title="Moving Average Simple", shorttitle="SMA", overlay=true, timeframe="", timeframe_gaps=true) +len = input.int(9, minval=1, title="Length") +src = input(close, title="Source") +offset = input.int(title="Offset", defval=0, minval=-500, maxval=500, display = display.data_window) +out = ta.sma(src, len) +plot(out, color=color.blue, title="MA", offset=offset) + +ma(source, length, type) => + switch type + "SMA" => ta.sma(source, length) + "EMA" => ta.ema(source, length) + "SMMA (RMA)" => ta.rma(source, length) + "WMA" => ta.wma(source, length) + "VWMA" => ta.vwma(source, length) + +typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Smoothing", display = display.data_window) +smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing", display = display.data_window) + +smoothingLine = ma(out, smoothingLength, typeMA) +plot(smoothingLine, title="Smoothing Line", color=#f37f20, offset=offset, display=display.none) diff --git a/xSamples/oscillators/STC.pine b/xSamples/oscillators/STC.pine new file mode 100644 index 0000000..960ced3 --- /dev/null +++ b/xSamples/oscillators/STC.pine @@ -0,0 +1,49 @@ +//@version=5 +//[SHK] STC colored indicator +//https://www.tradingview.com/u/shayankm/ + +indicator(title='[SHK] Schaff Trend Cycle (STC)', shorttitle='STC', overlay=false) +EEEEEE = input(12, 'Length') +BBBB = input(26, 'FastLength') +BBBBB = input(50, 'SlowLength') + +AAAA(BBB, BBBB, BBBBB) => + fastMA = ta.ema(BBB, BBBB) + slowMA = ta.ema(BBB, BBBBB) + AAAA = fastMA - slowMA + AAAA + +AAAAA(EEEEEE, BBBB, BBBBB) => + AAA = input(0.5) + var CCCCC = 0.0 + var DDD = 0.0 + var DDDDDD = 0.0 + var EEEEE = 0.0 + BBBBBB = AAAA(close, BBBB, BBBBB) + CCC = ta.lowest(BBBBBB, EEEEEE) + CCCC = ta.highest(BBBBBB, EEEEEE) - CCC + CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1]) + DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1]) + DDDD = ta.lowest(DDD, EEEEEE) + DDDDD = ta.highest(DDD, EEEEEE) - DDDD + DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1]) + EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1]) + EEEEE + +mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB) +mColor = mAAAAA > mAAAAA[1] ? color.new(color.green, 20) : color.new(color.red, 20) + + + +if mAAAAA[3] <= mAAAAA[2] and mAAAAA[2] > mAAAAA[1] and mAAAAA > 75 + alert("Red", alert.freq_once_per_bar) +if mAAAAA[3] >= mAAAAA[2] and mAAAAA[2] < mAAAAA[1] and mAAAAA < 25 + alert("Green", alert.freq_once_per_bar) + + +plot(mAAAAA, color=mColor, title='STC', linewidth=2) + +ul = plot(25, color=color.new(color.gray, 70)) +ll = plot(75, color=color.new(color.gray, 70)) +fill(ul, ll, color=color.new(color.gray, 96)) +