9:1Trading
New member
Ok, so what I'm trying to do may seem self evident, but I'll explain anyway.
I'm trying to add chart labels for when the EMA 8 is above the EMA 50 on the following Time Frames;
Month
Week
Day
4 Hr
1 Hr
The following code works, but it's either all green or all red. I know that's not right, but I can't figure out how to fix it.
I'd also like to add a chart indicator (arrow up) when the 4 hr is false and crosses to true.
I'm sorry if that's not explained well. Any assistance would be amazing. Thanks in advance!
I'm trying to add chart labels for when the EMA 8 is above the EMA 50 on the following Time Frames;
Month
Week
Day
4 Hr
1 Hr
The following code works, but it's either all green or all red. I know that's not right, but I can't figure out how to fix it.
I'd also like to add a chart indicator (arrow up) when the 4 hr is false and crosses to true.
I'm sorry if that's not explained well. Any assistance would be amazing. Thanks in advance!
Code:
def monthlytrend = if (expAverage(close, 8) * aggregationPeriod.MONTH > expaverage(close, 50) * aggregationPeriod.MONTH)then 1 else 0;
def weeklytrend = if(MovAvgExponential(close, 8) * aggregationPeriod.WEEK > expaverage (close, 50) * aggregationPeriod.WEEK)then 1 else 0;
def dailytrend = if (MovAvgExponential(close, 8) * aggregationPeriod.DAY > expaverage (close, 50) * aggregationPeriod.DAY) then 1 else 0;
def trend4 = if (MovAvgExponential(close, 8) * aggregationPeriod.FOUR_hours > expaverage (close, 50) * aggregationPeriod.FOUR_hours) then 1 else 0;
def trend1 = if (MovAvgExponential(close, 8) * aggregationPeriod.hour > expaverage (close, 50) * aggregationPeriod.HOUR) then 1 else 0;
AddLabel(yes, if monthlytrend is true then "M" else "", if monthlytrend is true then Color.dark_Green else color.DARK_RED);
AddLabel(yes, if weeklytrend is true then "W" else "", if weeklytrend is true then Color.dark_Green else Color.dark_Red);
AddLabel(yes, if dailytrend is true then "D" else "", if dailytrend is true then Color.dark_Green else Color.dark_Red);
AddLabel(yes, if trend4 is true then "4" else "", if trend4 is true then Color.dark_Green else Color.dark_Red);
AddLabel(yes, if trend1 is true then "1" else "", if trend1 is true then Color.dark_Green else Color.dark_Red);
Last edited by a moderator: