Chart label for EMA crossover of alternate ticker symbol


Category:
0
0

Hey Pete, i am trying to develop a chart label that shows when the 3ema crosses the 5 Ema in the /es regardless of what ticker I’m looking at. I would also like for the label to switch to green when that happens. Thanks so much for what you do✌

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on August 16, 2020 11:49 pm
95 views
0
First thing I will do is update the title of this question to better suit the solution I will provide. I'm thinking something along the lines of "Chart label for EMA crossover of alternate ticker symbol". Before I do that I want to make sure I understand how you want the colors to change. If we only change the color for the bar that crosses, the label will be gray until a crossover occurs. When the crossover occurs to the upside the label will change green and then revert back to gray as soon as the next bar opens. Likewise for the cross below except the color will change from gray to red. Is that really what you intended for this?
( at August 17, 2020 10:34 am)
0
Yes, thats it exactly, thanks!
( at August 17, 2020 1:46 pm)
0
Private answer

Be sure to read the comments section above to get the clarifications required to complete this request.

Here is code to display the label as described:

input alternateTickerSymbol = "/ES";
input maLengthOne = 3;
input maTypeOne = AverageType.EXPONENTIAL;
input maLengthTwo = 5;
input maTypeTwo = AverageType.EXPONENTIAL;
def maOne = MovingAverage(maTypeOne, close(symbol = alternateTickerSymbol), maLengthOne);
def maTwo = MovingAverage(maTypeTwo, close(symbol = alternateTickerSymbol), maLengthTwo);
def crossAbove = maOne[1] < maTwo[1] and maOne > maTwo;
def crossBelow = maOne[1] > maTwo[1] and maOne < maTwo;
AddLabel(yes, Concat(alternateTickerSymbol, Concat(" EMAx: ", Concat(maLengthOne, Concat("/", maLengthTwo)))), if crossAbove then Color.GREEN else if crossBelow then Color.RED else Color.GRAY);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 17, 2020 2:34 pm
0
Soooo dope. Thank you
( at August 17, 2020 7:16 pm)
0
Hey Pete is there a set aggregation period for the code?
( at August 17, 2020 7:25 pm)
0
There is not. I did not find that in the original request so I did not included it. Plenty of examples of that in the forum so you can search and browse for that and modify the solution I provided.
( at August 17, 2020 8:36 pm)
0
Thanks. Will see what I can do.
( at August 19, 2020 12:26 pm)