Gatekeeper
Member
- Platform
-
- Thinkorswim
#//PRC_ATR Adaptive EMA
#https://www.prorealcode.com/prorealtime-indicators/atr-adaptive-ema/
#//31.08.2018
#//Nicolas @ www.prorealcode.com
#//Sharing ProRealTime knowledge
#//converted from Metatrader5 version
#Translated to tS - amalia - 11.10.2018
# Modified by Gatekeeper with counter
def NA = Double.NaN;
def bar = BarNumber();
#settings
input EmaPeriod = 20;
#end of settings
input price = OHLC4;
def atr = ATR(EmaPeriod);
def start = (EmaPeriod+1);
def mmax = highest(atr, start);
def mmin = lowest(atr, start);
def coeff = 1-(atr-mmin)/(mmax-mmin);
def alpha = 2.0 / (1+EmaPeriod*(coeff+1.0)/2.0);
def val = val[1]+alpha*(price-val[1]);
plot value = val;
#EndCo
value.AssignValueColor( if Value > Value[1] then COLOR.GREEN else COLOR.RED);
#cos251 And SuryaKirnaC Orginal for the RSM Pg7
#modified/cut from by Gatekeeper
plot UpTrend = if (Value > Value[6]) then 1 else 0;#-1;#
plot DownTrend = if (Value[6] > Value) then 1 else 0;#-1;#crosses below
###plot DownTrend = if (MACDBB_Midline < 50 and SlowK < 50 and Value < Avg then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
#plot upArrow = if UpTrend == 1 and UpTrend[1] == 0 and (tradetype == tradetype.long or tradetype == tradetype.both) then low else Double.NaN;
#upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#upArrow.SetDefaultColor(Color.GREEN);
#upArrow.SetLineWeight(4);
#plot downArrow = if DownTrend == 1 and DownTrend[1] == 0 and (tradetype == tradetype.short or tradetype == tradetype.both) then high else Double.NaN;
#downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#downArrow.SetDefaultColor(Color.RED);
#downArrow.SetLineWeight(4);
def bnumUp;
def bnumDown;
def closeUpTrendStart;
def closeDownTrendStart;
def UpTrendBarCount;
def DownTrendBarCount;
if UpTrend and (!UpTrend[1] or DownTrend[1]) {
bnumUp = BarNumber();
bnumDown = 0;
closeUpTrendStart = close;
closeDownTrendStart = 0;
UpTrendBarCount = 1;
DownTrendBarCount = 0;
} else if UpTrend {
bnumUp = bnumUp[1];
bnumDown = 0;
closeUpTrendStart = closeUpTrendStart[1];
closeDownTrendStart = 0;
UpTrendBarCount = UpTrendBarCount[1] + 1;
DownTrendBarCount = 0;
} else if DownTrend and (!DownTrend[1] or UpTrend[1]) {
bnumUp = 0;
bnumDown = BarNumber();
closeDownTrendStart = close;
closeUpTrendStart = 0;
UpTrendBarCount = 0;
DownTrendBarCount = 1;
} else if DownTrend {
bnumDown = bnumDown[1];
closeDownTrendStart = closeDownTrendStart[1];
DownTrendBarCount = DownTrendBarCount[1] + 1;
bnumUp = 0;
closeUpTrendStart = 0;
UpTrendBarCount = 0;
} else {
bnumUp = 0;
bnumDown = 0;
closeUpTrendStart = 0;
closeDownTrendStart = 0;
UpTrendBarCount = 0;
DownTrendBarCount = 0;
}
###XXX Basic
def GetTrend = if Uptrend then 1 else if DownTrend then -1 else 0;
AddLabel (yes, if GetTrend == 1 then "P+" + UpTrendBarCount else if GetTrend == -1 then "P-" + DownTrendBarCount else "", if GetTrend == 1 then Color.GREEN else if GetTrend == -1 then Color.RED else Color.GRAY);
#Note; the bar changes color it will count the candles above or below the bar until the next change in bar color
#https://www.prorealcode.com/prorealtime-indicators/atr-adaptive-ema/
#//31.08.2018
#//Nicolas @ www.prorealcode.com
#//Sharing ProRealTime knowledge
#//converted from Metatrader5 version
#Translated to tS - amalia - 11.10.2018
# Modified by Gatekeeper with counter
def NA = Double.NaN;
def bar = BarNumber();
#settings
input EmaPeriod = 20;
#end of settings
input price = OHLC4;
def atr = ATR(EmaPeriod);
def start = (EmaPeriod+1);
def mmax = highest(atr, start);
def mmin = lowest(atr, start);
def coeff = 1-(atr-mmin)/(mmax-mmin);
def alpha = 2.0 / (1+EmaPeriod*(coeff+1.0)/2.0);
def val = val[1]+alpha*(price-val[1]);
plot value = val;
#EndCo
value.AssignValueColor( if Value > Value[1] then COLOR.GREEN else COLOR.RED);
#cos251 And SuryaKirnaC Orginal for the RSM Pg7
#modified/cut from by Gatekeeper
plot UpTrend = if (Value > Value[6]) then 1 else 0;#-1;#
plot DownTrend = if (Value[6] > Value) then 1 else 0;#-1;#crosses below
###plot DownTrend = if (MACDBB_Midline < 50 and SlowK < 50 and Value < Avg then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
#plot upArrow = if UpTrend == 1 and UpTrend[1] == 0 and (tradetype == tradetype.long or tradetype == tradetype.both) then low else Double.NaN;
#upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#upArrow.SetDefaultColor(Color.GREEN);
#upArrow.SetLineWeight(4);
#plot downArrow = if DownTrend == 1 and DownTrend[1] == 0 and (tradetype == tradetype.short or tradetype == tradetype.both) then high else Double.NaN;
#downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#downArrow.SetDefaultColor(Color.RED);
#downArrow.SetLineWeight(4);
def bnumUp;
def bnumDown;
def closeUpTrendStart;
def closeDownTrendStart;
def UpTrendBarCount;
def DownTrendBarCount;
if UpTrend and (!UpTrend[1] or DownTrend[1]) {
bnumUp = BarNumber();
bnumDown = 0;
closeUpTrendStart = close;
closeDownTrendStart = 0;
UpTrendBarCount = 1;
DownTrendBarCount = 0;
} else if UpTrend {
bnumUp = bnumUp[1];
bnumDown = 0;
closeUpTrendStart = closeUpTrendStart[1];
closeDownTrendStart = 0;
UpTrendBarCount = UpTrendBarCount[1] + 1;
DownTrendBarCount = 0;
} else if DownTrend and (!DownTrend[1] or UpTrend[1]) {
bnumUp = 0;
bnumDown = BarNumber();
closeDownTrendStart = close;
closeUpTrendStart = 0;
UpTrendBarCount = 0;
DownTrendBarCount = 1;
} else if DownTrend {
bnumDown = bnumDown[1];
closeDownTrendStart = closeDownTrendStart[1];
DownTrendBarCount = DownTrendBarCount[1] + 1;
bnumUp = 0;
closeUpTrendStart = 0;
UpTrendBarCount = 0;
} else {
bnumUp = 0;
bnumDown = 0;
closeUpTrendStart = 0;
closeDownTrendStart = 0;
UpTrendBarCount = 0;
DownTrendBarCount = 0;
}
###XXX Basic
def GetTrend = if Uptrend then 1 else if DownTrend then -1 else 0;
AddLabel (yes, if GetTrend == 1 then "P+" + UpTrendBarCount else if GetTrend == -1 then "P-" + DownTrendBarCount else "", if GetTrend == 1 then Color.GREEN else if GetTrend == -1 then Color.RED else Color.GRAY);
#Note; the bar changes color it will count the candles above or below the bar until the next change in bar color