Need help with creating labels for Macd with parameters that I want

kingkunta

New member
I have the following code down which gives me the value of the value line in the macd study. It looks at the previous candles value and color codes the label based on if the value is higher or lower and above 0 or below 0. What i want to do (but dont know how to ) is create a 3rd color which will turn yellow whenever the current candles value is inbetween .5 and -.5. so it will be like this

Above .5 = green
between .5 to -.5 = yellow
below -.5 = red

for both the previous and the current labels.
Any help would be appreciated. thank you!

Code:
input Period1 = AggregationPeriod.FOUR_HOURS;


#MACD Primer Cloud
#==============================================================================================
def c1 = close(period = Period1);
def c2 = close(period = Period1)[1];

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

def Value1 = MovingAverage(averageType, c1, fastLength) - MovingAverage(averageType, c1, slowLength);
def Value2 = MovingAverage(averageType, c2, fastLength) - MovingAverage(averageType, c2, slowLength);


input MacdLabel4h = yes;
input MacdLabelPrev4h = yes;
#AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= Value2 then Color.DARK_GREEN else Color.DARK_RED);
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= 0 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);



#AddLabel(MacdLabelPrev4h, “Value 4H[1]: " + Value2, color = if Value2 >= Value1 then Color.Dark_Green else Color.DARK_Red);
#AddLabel(MacdLabel4h, "MACD 4hr: " + Diff1, color = if Diff1 >= 0 then if Diff1 > Diff1[1] then Color.GREEN else Color.#DARK_GREEN else if  Diff1 < Diff1[1] then Color.RED else Color.DARK_RED);

AddLabel(MacdLabelPrev4h, “Value 4H[1]: " + Value2, color = if Value2 >= 0 then if Value2 > Value1 then Color.GREEN else Color.DARK_GREEN else if  Value2 < Value1 then Color.RED else Color.DARK_RED);

############################
 

generic

Active member
@kingkunta Not sure what needs to be above and below .5 and -.5 but the logic should be correct so change MACD? to whatever you need.
Code:
if MACD? > .5 then color.GREEN else if MACD? < -.5 then color.RED else color.YELLOW
 

generic

Active member
@kingkunta I would if I knew what you wanted. Your post uses value for everything and I'm not sure what needs to be compared with .5 and -.5. Also sounds like you already have color code for >.5 and <-.5 so changing that logic should do.
 

Pensar

Well-known member
VIP
@kingkunta It would be easier to help if you posted a screenshot with an explanation - a picture is worth a thousand words. Perhaps this is coloring you're looking for?

Code:
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 > -.5 or Value1 < 0.5 then color.yellow else if Value1 >= 0 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);

AddLabel(MacdLabelPrev4h, “Value 4H[1]: " + Value2, color = if Value2 > -.5 or Value2 < 0.5 then color.yellow else if Value2 >= 0 then if Value2 > Value1 then Color.GREEN else Color.DARK_GREEN else if  Value2 < Value1 then Color.RED else Color.DARK_RED);
 

3AMBH

Member
2019 Donor
I have the following code down which gives me the value of the value line in the macd study. It looks at the previous candles value and color codes the label based on if the value is higher or lower and above 0 or below 0. What i want to do (but dont know how to ) is create a 3rd color which will turn yellow whenever the current candles value is inbetween .5 and -.5. so it will be like this

Above .5 = green
between .5 to -.5 = yellow
below -.5 = red

for both the previous and the current labels.
Any help would be appreciated. thank you!

Code:
input Period1 = AggregationPeriod.FOUR_HOURS;


#MACD Primer Cloud
#==============================================================================================
def c1 = close(period = Period1);
def c2 = close(period = Period1)[1];

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

def Value1 = MovingAverage(averageType, c1, fastLength) - MovingAverage(averageType, c1, slowLength);
def Value2 = MovingAverage(averageType, c2, fastLength) - MovingAverage(averageType, c2, slowLength);


input MacdLabel4h = yes;
input MacdLabelPrev4h = yes;
#AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= Value2 then Color.DARK_GREEN else Color.DARK_RED);
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= 0 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);



#AddLabel(MacdLabelPrev4h, “Value 4H[1]: " + Value2, color = if Value2 >= Value1 then Color.Dark_Green else Color.DARK_Red);
#AddLabel(MacdLabel4h, "MACD 4hr: " + Diff1, color = if Diff1 >= 0 then if Diff1 > Diff1[1] then Color.GREEN else Color.#DARK_GREEN else if  Diff1 < Diff1[1] then Color.RED else Color.DARK_RED);

AddLabel(MacdLabelPrev4h, “Value 4H[1]: " + Value2, color = if Value2 >= 0 then if Value2 > Value1 then Color.GREEN else Color.DARK_GREEN else if  Value2 < Value1 then Color.RED else Color.DARK_RED);

############################
Hi King, Please post the final code when you get it the way you want it. I like what you are doing. Thanks
 

kingkunta

New member
@kingkunta It would be easier to help if you posted a screenshot with an explanation - a picture is worth a thousand words. Perhaps this is coloring you're looking for?

Code:
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 > -.5 or Value1 < 0.5 then color.yellow else if Value1 >= 0 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);

AddLabel(MacdLabelPrev4h, “Value 4H[1]: " + Value2, color = if Value2 > -.5 or Value2 < 0.5 then color.yellow else if Value2 >= 0 then if Value2 > Value1 then Color.GREEN else Color.DARK_GREEN else if  Value2 < Value1 then Color.RED else Color.DARK_RED);
Hey i think this is close to what I need however it makes all the labels yellow no matter what the value is. Do you know what could be missing? The idea that you posted is exactly what I want but just the labels seem to all be yellow with this
Code:
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= -.5 or Value1 <= 0.5 then color.yellow else if Value1 >= .5 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);
 

Pensar

Well-known member
VIP
Hey i think this is close to what I need however it makes all the labels yellow no matter what the value is. Do you know what could be missing? The idea that you posted is exactly what I want but just the labels seem to all be yellow with this
Code:
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= -.5 or Value1 <= 0.5 then color.yellow else if Value1 >= .5 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);
@kingkunta My original snippet had a mistake - I think this is better, I used "and" instead of "or" in the code for defining what area to color yellow. Check it, let me know if it solves the issue or if I'll have to dig deeper.
Code:
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= -.5 and Value1 <= 0.5 then color.yellow else if Value1 >= .5 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);
 

kingkunta

New member
@kingkunta My original snippet had a mistake - I think this is better, I used "and" instead of "or" in the code for defining what area to color yellow. Check it, let me know if it solves the issue or if I'll have to dig deeper.
Code:
AddLabel(MacdLabel4h, “Value 4H: " + Value1, color = if Value1 >= -.5 and Value1 <= 0.5 then color.yellow else if Value1 >= .5 then if Value1 > Value2 then Color.GREEN else Color.DARK_GREEN else if  Value1 < Value2 then Color.RED else Color.DARK_RED);
hey man thank u so much. Seems to be working fine. Ill post the entire code when i fix it up later.
 

Similar threads

Top