MTF Labels and a Question

Shows labels for:

Current chart:
RSI
Macd
TMO
Heiken Ashi
and labels for
daily, weekly

If I switch to the daily chart, it shows them twice.

I added an ,

input ShowDailyLabels = yes;

but wasn't sure how to incorporate into the addlabel section

also, I tried to use Heiken Ashi with NO Upper or Lower wick but it wouldn't display the label (any fix?)

Thanks and hope you find it useful
wy6TD5T.png






Code:
input Time1 = AggregationPeriod.DAY;
input Time2 = AggregationPeriod.WEEK;
#==============END TIME==================

input ShowDailyLabels = yes;

#===============HEIKENAshI===========
#Part of code submitted by Welkin
def o1 = open(Period = Time1);
def h1 = high(Period = Time1);
def l1 = low(Period = Time1);
def c1 = close(Period = Time1);

def o2 = open(Period = Time2);
def h2 = high(Period = Time2);
def l2 = low(Period = Time2);
def c2 = close(Period = Time2);

def HAopen1;
def HAhigh1;
def HAlow1;
def HAclose1;

def HAopen2;
def HAhigh2;
def HAlow2;
def HAclose2;

HAopen1 = CompoundValue(1, (HAopen1[1] + HAclose1[1]) / 2, (o1[1] + c1[1]) / 2);
HAopen2 = CompoundValue(1, (HAopen2[1] + HAclose2[1]) / 2, (o2[1] + c2[1]) / 2);

HAhigh1 = Max(Max(h1, HAopen1), HAclose1[1]);
HAlow1 = Min(Min(l1, HAopen1), HAclose1[1]);
HAclose1 = (o1 + h1 + l1 + c1) / 4;

HAhigh2 = Max(Max(h2, HAopen2), HAclose2[1]);
HAlow2 = Min(Min(l2, HAopen2), HAclose2[1]);
HAclose2 = (o2 + h2 + l2 + c2) / 4;


def HAGreen1 = HAclose1 > HAopen1;
def haGreen2 = HAclose2 > HAopen2;

def haRed1 = HAclose1 < HAopen1;
def haRed2 = HAclose2 < HAopen2;

#def newHAgreen1 = HAGreen1 and haRed1[1];
#def newHAgreen2 = haGreen2 and haRed2[1];
#def newHAgreen3 = haGreen3 and haRed3[1];
#def newHared1 = haRed1 and HAGreen1[1];
#def newHared2 = haRed2 and haGreen2[1];
#def newHared3 = haRed3 and haGreen3[1];
def noLowerWickGreen1 = HAclose1 > HAopen1 and HAopen1 == HAlow1;
def noLowerWickGreen2 = HAclose2 > HAopen2 and HAopen2 == HAlow2;

def noUpperWickRed1 = HAclose1 < HAopen1 and HAopen1 == HAhigh1;
def noUpperWickRed2 = HAclose2 < HAopen2 and HAopen2 == HAhigh2;



#==============END HA===================================

#=========MACD==================

input fastLengthMACD = 8;
input slowLengthMACD = 21;
input MACDLength = 5;
input averageTypeMACD = AverageType.WEIGHTED;
input showBreakoutSignals = no;

def FastMacD = MovingAverage(averageTypeMACD, close, fastLengthMACD) - MovingAverage(averageTypeMACD,close, slowLengthMACD);

def FastMacD1 = MovingAverage(averageTypeMACD, close(PERIOD = Time1), fastLengthMACD) - MovingAverage(averageTypeMACD, close(period = Time1), slowLengthMACD);

def FastMacD2 = MovingAverage(averageTypeMACD, close(PERIOD = Time2), fastLengthMACD) - MovingAverage(averageTypeMACD, close(period = Time2), slowLengthMACD);

def SlowMacd = MovingAverage(averageTypeMACD, FastMacD, MACDLength);
def SlowMacd1 = MovingAverage(averageTypeMACD, FastMacD1, MACDLength);
def SlowMacd2 = MovingAverage(averageTypeMACD, FastMacD2, MACDLength);

#def Diff = FastMacD1 - SlowMacd1;

def MacDSlowGreen = SlowMacd > SlowMacd[1];
def MacDSlowGreen1 = SlowMacd1 > SlowMacd1[1];
def MacDSlowGreen2 = SlowMacd2 > SlowMacd2[1];

def MacDSlowRed = SlowMacd < SlowMacd[1];
def MacDSlowRed1 = SlowMacd1 < SlowMacd1[1];
def MacDSlowRed2 = SlowMacd2 < SlowMacd2[1];

def MacdFastGreen = FastMacD > FastMacD[1];
def MacdFastGreen1 = FastMacD1 > FastMacD1[1];
def MacdFastGreen2 = FastMacD2 > FastMacD2[1];

def MacdFastRed = FastMacD < FastMacD[1];
def MacdFastRed1 = FastMacD1 < FastMacD1[1];
def MacdFastRed2 = FastMacD2 < FastMacD2[1];

#==========END MACD==================


#==========STOCHASTIC======================

#input top = 100;
#input bottom = 0;
#input over_boughtStoch = 80;
#input over_soldStoch = 20;
#input KPeriod = 14;
#input DPeriod = 3;
#input KPeriodDay = 36;
#input DPeriodDay = 21;
#input averageTypeStoch = AverageType.SIMPLE;
#def priceH1 = high(period = time1);
#def priceL1 = low(period = time1);
#def priceC1 = close(period = time1);
#def priceH2 = high(period = time2);
#def priceL2 = low(period = time2);
#def priceC2 = close(period = time2);

#def StochFastK1 = reference StochasticFull(over_boughtStoch, over_soldStoch, KPeriod,
#DPeriod, priceH1, priceL1, priceC1, 3, averageTypeStoch).FullK;

#def StochFastK2 = reference StochasticFull(over_boughtStoch, over_soldStoch, KPeriod,
#DPeriod, priceH2, priceL2, priceC2, 3, averageTypeStoch).FullK;

#def StochSlowD1 = reference StochasticFull(over_boughtStoch, over_soldStoch, KPeriod, DPeriod, priceH1, priceL1, priceC1, 3, averageTypeStoch).FullD;

#def StochSlowD2 = reference StochasticFull(over_boughtStoch, over_soldStoch, KPeriod, DPeriod, priceH2, priceL2, priceC2, 3, averageTypeStoch).FullD;


#def StochFastkGreen1 = StochFastK1 > StochFastK1[1];
#def StochFastkGreen2 = StochFastK2 > StochFastK2[1];

#def StochFastkRed1 = StochFastK1 < StochFastK1[1];
#def StochFastkRed2 = StochFastK2 < StochFastK2[1];

#def StochSlowDGreen1 = StochSlowD1 > StochSlowD1[1];
#def StochSlowDGreen2 = StochSlowD2 > StochSlowD2[1];

#def StochSlowDRed1 = StochSlowD1 < StochSlowD1[1];
#def StochSlowDRed2 = StochSlowD2 < StochSlowD2[1];

#======TRUE MOMENTUM==============================
# TMO ((T)rue (M)omentum (O)scilator)========AGG2==========
# Mobius
# V01.05.2018
#hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.

input lengthmom =  14;
input calcLength = 5;
input smoothLength = 3;

def TMO = open;
def TMO1 = open(Period = Time1);
def TMO2 = open(Period = Time2);

def TMC = close;
def TMC1 = close(period = Time1);
def TMC2 = close(period = Time2);

def data = fold i = 0 to lengthmom
           with s
           do s + (if TMC > GetValue(TMO, i)
                   then 1
                   else if TMC < GetValue(TMO, i)
                        then - 1
                        else 0);
def data1 = fold i1 = 0 to lengthmom
           with s1
           do s1 + (if TMC1 > GetValue(TMO1, i1)
                   then 1
                   else if TMC1 < GetValue(TMO1, i1)
                        then - 1
                        else 0);
def data2 = fold i2 = 0 to lengthmom
           with s2
           do s2 + (if TMC2 > GetValue(TMO2, i2)
                   then 1
                   else if TMC2 < GetValue(TMO2, i2)
                        then - 1
                        else 0);

def EMA5 = ExpAverage(data, calcLength);
def EMA51 = ExpAverage(data1, calcLength);
def EMA52 = ExpAverage(data2, calcLength);

def Main = ExpAverage(EMA5, smoothLength);
def Main1 = ExpAverage(EMA51, smoothLength);
def Main2 = ExpAverage(EMA52, smoothLength);

def MainUp2 = Main2 > Main2[1];
def MainDn2 = Main2 < Main2[1];

def Signal = ExpAverage(Main, smoothLength);
def Signal1 = ExpAverage(Main1, smoothLength);
def Signal2 = ExpAverage(Main2, smoothLength);


#def zero = if IsNaN(TMC1) then Double.NaN else 0;

#def ob1 = if IsNaN(TMC1) then Double.NaN else Round(lengthmom * .7);

#def os1 = if IsNaN(TMC1) then Double.NaN else -Round(lengthmom * .7);
def TMLong = Main > Signal;
def TMLong1 = Main1 > Signal1;
def TMLong2 = Main2 > Signal2 ;

def TMShort = Main < Signal;
def TMShort1 = Main1 < Signal1;
def TMShort2 = Main2 < Signal2;





#====RSI====================================================

input length1rsi = 14;
input over_Bought = 70;
input over_Sold = 30;
input pricersi = close;
input averageTypeRSI = AverageType.WILDERS;

input mid = 50;

def rsi = close;
def rsi1 = close(period = Time1);
def rsi2 = close(period = Time2);

def NetChgAvg = MovingAverage(averageTypeRSI, rsi - rsi[1], length1rsi);
def NetChgAvg1 = MovingAverage(averageTypeRSI, rsi1 - rsi1[1], length1rsi);
def NetChgAvg2 = MovingAverage(averageTypeRSI, rsi2 - rsi2[1], length1rsi);

def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(rsi - rsi[1]), length1rsi);
def TotChgAvg1 = MovingAverage(averageTypeRSI, AbsValue(rsi1 - rsi1[1]), length1rsi);
def TotChgAvg2 = MovingAverage(averageTypeRSI, AbsValue(rsi2 - rsi2[1]), length1rsi);

def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def ChgRatio1 = if TotChgAvg1 != 0 then NetChgAvg1 / TotChgAvg1 else 0;
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;
def RSI_ = 50 * (ChgRatio + 1);
def RSI_1 = 50 * (ChgRatio1 + 1);
def RSI_2 = 50 * (ChgRatio2 + 1);


def OverSold = over_Sold;
def OverBought = over_Bought;


def rsiAbove50 = RSI_ > 50;
def rsiAbove501 = RSI_1 > 50;
def rsiAbove502 = RSI_2 > 50;

def rsiBelow50 = RSI_ < 50;
def rsiBelow501 = RSI_1 < 50;
def rsiBelow502 = RSI_2 < 50;


#plot MCD3 = if rsi50up then low else double.NaN;
#mcd3.setPaintingStrategy(paintingStrategy.ARROW_UP);
#mcd3.setDefaultColor(color.MAGENTA);

#=======================================================================


def Time1Long =  rsiAbove501  and HAGreen1 and TMLong1 and MacdFastGreen1 and MacDSlowGreen1;
def Time1Short =  rsiBelow501 and haRed1 and TMShort1 and MacdFastRed1 and MacDSlowRed1;

def Time2Long =  RSI_2 > 50 and MacdFastGreen2  and haGreen2 and TMLong2;
def Time2Short = RSI_2 < 50 and MacdFastRed2 and haRed2 and TMShort2;


#AddLabel(yes, if Time1Long then "***ALL LONG***" else if Time1short then "***ALL SHORT***" else "", if Time1Long then (CreateColor(43, 143, 70)) else if Time1Short then CreateColor(97, 81, 145) else Color.DARK_GRAY);

AddLabel(yes, "**(RSI)**" + RSI_,  if RSI_ > RSI_[1] and RSI_ > 50 then Color.DARK_GREEN else if RSI_ < RSI_[1] and RSI_ > 50 then Color.GREEN else  if RSI_ < RSI_[1] and RSI_ < 50 then (CreateColor(122, 10, 12)) else if RSI_ > RSI_[1] and RSI_ < 50 then Color.RED else Color.DARK_GRAY);

AddLabel(yes, "**(D-RSI)**" + RSI_1,  if RSI_1 > RSI_1[1] and RSI_1 > 50 then Color.DARK_GREEN else if RSI_1 < RSI_1[1] and RSI_1 > 50 then Color.GREEN else  if RSI_1 < RSI_1[1] and RSI_1 < 50 then (CreateColor(122, 10, 12)) else if RSI_1 > RSI_1[1] and RSI_1 < 50 then Color.RED else Color.DARK_GRAY);

AddLabel(yes, "**(W-RSI)**" + RSI_2,  if RSI_2 > RSI_2[1] and RSI_2 > 50 then Color.DARK_GREEN else if RSI_2 < RSI_2[1] and RSI_2 > 50 then Color.GREEN else  if RSI_2 < RSI_2[1] and RSI_2 < 50 then (CreateColor(122, 10, 12)) else if RSI_2 > RSI_2[1] and RSI_2 < 50 then Color.RED else Color.DARK_GRAY);

AddLabel(yes, if MacdFastGreen then "MacD_F" else if MacdFastRed then "Macd_F" else "", if MacdFastGreen then CreateColor(24, 58, 102) else if MacdFastRed then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if MacDSlowGreen then "MacD_S" else if MacDSlowRed then "Macd_S" else "", if MacDSlowGreen then CreateColor(24, 58, 102) else if MacDSlowRed then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if MacdFastGreen1 then "D-MacD_F" else if MacdFastRed1 then "D-Macd_F" else "", if MacdFastGreen1 then CreateColor(24, 58, 102) else if MacdFastRed1 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if MacDSlowGreen1 then "D-MacD_S" else if MacDSlowRed1 then "D-Macd_S" else "", if MacDSlowGreen1 then CreateColor(24, 58, 102) else if MacDSlowRed1 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if MacdFastGreen2 then "W-MacD_F" else if MacdFastRed2 then "W-Macd_F" else "", if MacdFastGreen2 then CreateColor(24, 58, 102) else if MacdFastRed2 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if MacDSlowGreen2 then "W-MacD_S" else if MacDSlowRed2 then "W-Macd_S" else "", if MacDSlowGreen2 then CreateColor(24, 58, 102) else if MacDSlowRed2 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if TMLong then "TMO" else if TMShort then "TMO" else "", if TMLong then CreateColor(24, 58, 102) else if TMShort then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if TMLong1 then "D-TMO" else if TMShort1 then "D-TMO" else "", if TMLong1 then CreateColor(24, 58, 102) else if TMShort1 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if TMLong2 then "W-TMO" else if TMShort2 then "W-TMO" else "", if TMLong2 then CreateColor(24, 58, 102) else if TMShort2 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if MainUp2 then "W-TMO-Main" else if MainDn2 then "W-TMO-Main" else "", if MainUp2 then CreateColor(24, 58, 102) else if MainDn2 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if HaGreen1 then "D-HA" else if HaRed1 then "D-HA" else "", if HaGreen1 then CreateColor(24, 58, 102) else if HaRed1 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );

AddLabel(yes, if HaGreen2 then "W-HA" else if HaRed2 then "W-HA" else "", if HaGreen2 then CreateColor(24, 58, 102) else if HaRed2 then (CreateColor(122, 10, 12)) else Color.DARK_GRAY );
 

Similar threads

Top