AddLabel box to display MA cross on different TF?

H

hashy

Member
I'd love to have a text box in the upper left of my chart that shows what direction the last cross was for two EMAs on a particular time frame. If anyone gets bored and would be kind enough to code it I would be grateful. I've tried, but I've come to the conclusion I suck at scripting.

Something like... 10EMA and 20EMA on 1H time frame. If 10 is above 20 it says "bullish" in the text box. If 10 is below 20 it says "bearish". TIA!
 
T

tomsk

Well-known member
VIP
@hashy Here is your moving average direction label, works on any timeframe. I have color coded it up for you. Cross Up = GREEN, Cross down = RED

Code:
# Moving Average Cross Direction Label
# tomsk
# 1.5.2020

input price = close;
input length1 = 10;
input length2 = 20;

def MA1 = Average(price, length1);
def MA2 = Average(price, length2);

AddLabel(1, "Moving Average " + length1 + "/" + length2 + " Cross Direction = " + if MA1 > MA2 then "UP" else "DOWN", if MA1 > MA2 then Color.GREEN else Color.RED);
# End Moving Average Cross Direction Label
 
Last edited:
Billions

Billions

Active member
2019 Donor
VIP
@hashy Here is your moving average direction label, works on any timeframe. I have color coded it up for you. Cross Up = GREEN, Cross down = RED

Code:
# Moving Average Cross Direction Label
# tomsk
# 1.5.2020

input price = close;
input length1 = 10;
input length2 = 20;

def MA1 = Average(price, length1);
def MA2 = Average(price, length2);

AddLabel(1, "Moving Average " + length1 + "/" + length2 + " Cross Direction = " + if MA1 > MA2 then "UP" else "DOWN", if MA1 > MA2 then Color.GREEN else Color.RED);
# End Moving Average Cross Direction Label
Can you add an alert to this
 

Similar threads

Top