Can someone help me clean up this code I pieced together? I am trying to have a label that tell me if the underlying 1 month moving average is above the 10 month moving average. I haven't done that much coding in a long time. I was playing around with labels to help me tell if a stock is on an uptrend or downtrend at a glance. I came across a mobius code for TMO with higher aggregate for using a different time frame that what is displayed. http://tos.mx/ABHh7kw
Code:
#1over 10 month
input length = 10;
input calcLength = 1;
input smoothLength = 1;
input agg = AggregationPeriod.monTH;
def o = open(period = agg);
def c = close(period = agg);
def data = fold i = 0 to length
with s
do s + (if c > GetValue(o, i)
then 1
else if c < GetValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal
then Color.GREEN
else Color.RED);
Signal.AssignValueColor(if Main > Signal
then Color.GREEN
else Color.RED);
Signal.HideBubble();
Signal.HideTitle();
def bullish = simplemovingAvg(1)>simpleMovingAvg(10);
def bearish = simpleMovingAvg(1)<simplemovingAvg(10);
AddLabel(yes, if bullish then "1>10 Monthly" else "1<10 Monthly", if bullish then Color.light_GREEN else Color.red);
Last edited by a moderator: