/PRC_ATR Adaptive EMA with Counter and a watchlist

Platform
  1. 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
 
Error in code;; change the value{6} of line 33 and 34 to Value {1] should look like this

plot UpTrend = if (Value > Value[1]) then 1 else 0;#-1;#
plot DownTrend = if (Value[1] > Value) then 1 else 0;#-1;#crosses below
 
Watchlist for the PRC_ATR Adaptive EMA Indicator


#//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
#Mod By Gatekeeper
#NOTE: time frames must match the chart. Watchlist respond are slower than the charts, and matter of interpretation is to user.

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]);
DEF value = val;#P


#cos251 And SuryaKirnaC Orginal for the RSM Pg7
#modified/count from by Gatekeeper


plot UpTrend = if (Value > Value[1]) then 1 else 0;
plot DownTrend = if (Value[1] > Value) then 1 else 0;



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 "+" + UpTrendBarCount else if GetTrend == -1 then "-" + DownTrendBarCount else "", if GetTrend == 1 then Color.GREEN else if GetTrend == -1 then Color.RED else Color.GRAY);
 
Hello gang.. a quick question.. it is possible to color paint the candles using this indicator? will be very helpfull. thanks in advance
 

barbaros

Administrator
Staff member
Hello gang.. a quick question.. it is possible to color paint the candles using this indicator? will be very helpfull. thanks in advance
Try the following line at the end of the script.

AssignPriceColor(if GetTrend == 1 then Color.GREEN else if GetTrend == -1 then Color.RED else Color.GRAY);
 
Top