add some new indicator/oscillators ...
This commit is contained in:
@@ -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 ...
|
||||
//
|
||||
Reference in New Issue
Block a user