AddCloud when EMAs are stacked


Category:
0
0

Hello,

I am having a tough time mimicking code that a group of traders I am thankful to be a part of use on NinjaTrader; I posted a picture for reference. So when the 8, 20, 50, 100 & 200EMAs are stacked in an uptrend, the background of portion is green. When the 8, 20, 50, 100 & 200EMAs are stacked in a downtrend, the background of that portion is red. Else, the background has no color. I am also trying to figure out how to have AddCloud portion in red for when ADX is 40 and above, else background has no color.

Attachments:
RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on February 26, 2023 2:21 pm
157 views
0
Private answer

Keep in mind that our terms and conditions state we do not attempt to reverse engineer or copy the behavior of proprietary indicators on this website. But we can certainly build solutions based on your own description (specifications). And stacked EMA's is a pretty common request so I don't see any issues providing the solutions you requested.

Here is the code for the stacked ema's. I have only included three ema's in this solution due to time constraints for free solutions I provide in this forum. You can add additional ema's to this solution after you read the code and understand how the patterns are computed.

input maLengthOne = 8;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 20;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
input maLengthThree = 50;
input maTypeThree = AverageType.EXPONENTIAL;
input maPriceThree = close;
plot maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
plot maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
plot maThree = MovingAverage(maTypeThree, maPriceThree, maLengthThree);
def stackBullish = maOne > maTwo and maTwo > maThree;
def stackBearish = maOne < maTwo and maTwo < maThree;
AddCloud(if stackBullish then Double.POSITIVE_INFINITY else Double.NaN, if stackBullish then Double.NEGATIVE_INFINITY else Double.NaN, Color.GREEN, Color.CURRENT);
AddCloud(if stackBearish then Double.POSITIVE_INFINITY else Double.NaN, if stackBearish then Double.NEGATIVE_INFINITY else Double.NaN, Color.RED, Color.CURRENT);

And here is the solution for the ADX indicator with red background when ADX is above 40:

input length = 14;
input averageType = AverageType.WILDERS;
plot adx = DMI(length, averageType).adx;
adx.setDefaultColor(GetColor(5));
AddCloud(if adx > 40 then Double.POSITIVE_INFINITY else Double.NaN, if adx > 40 then Double.NEGATIVE_INFINITY else Double.NaN, Color.RED, Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on February 26, 2023 3:07 pm
0
You are a life saver! I was trying to figure it out for the life of me!
( at February 26, 2023 4:19 pm)