All we need to keep from the original code are the style statements:
MA1.SetDefaultColor(GetColor(4));
MA1.SetLineWeight(2);
MA1.SetStyle(Curve.FIRM);
MA1.DefineColor(“Up”, GetColor(6));
MA1.DefineColor(“Down”, GetColor(5));
MA1.AssignValueColor(if MA1 > MA1[1] then MA1.color(“Up” ) else MA1.color(“Down” ));
Then we create a new plot based on the MovAvgTriangular study:
input price = close;
input length = 9;
input displace = 0;
plot avgTriangular = MovAvgTriangular(price, length, displace).AvgTri;
All we need to complete this is to replace every occurrence of MA1
with the new plot, avgTriangular
Here is the entire code, completed:
input price = close;
input length = 9;
input displace = 0;
plot avgTriangular = MovAvgTriangular(price, length, displace).AvgTri;
avgTriangular.SetDefaultColor(GetColor(4));
avgTriangular.SetLineWeight(2);
avgTriangular.SetStyle(Curve.FIRM);
avgTriangular.DefineColor(“Up”, GetColor(6));
avgTriangular.DefineColor(“Down”, GetColor(5));
avgTriangular.AssignValueColor(if avgTriangular > avgTriangular[1] then avgTriangular.color(“Up” ) else avgTriangular.color(“Down” ));
Attached screenshot shows the end result.
Excellent work Pete. I was trying to add reversal alerts to it for when the MA line color changes from up to down & down to up. I was trying to come up with one. How could I add this feature? Will something like this work?
def bullReversal = upTrend and downTrend[1] == yes;
Alert(bullReversal, “Bullish Trend”, Alert.BAR, Sound.RING);
def bearReversal = downTrend and upTrend[1] == yes;
Alert(bearReversal, “Bearish Trend”, Alert.BAR, Sound.RING);
Where have you defined the upTrend and downTrend variables? Need to define those or you will get errors. And you don’t need the “== yes” at the end. They should already evaluate to a true/false condition.
Not quite sure…just messing around trying to figure it out with my limited coding skillz. If you figure it out I’ll be glad to make a contribution. thx
“….if you figure it out…”. Well that is already given. I have already demonstrated this in dozens of posts on this Q&A forum. So yes, I have already figured it out. The question is, did you want to take some time to work it out? Hint: You may want to search in the “Alerts and Notifications” topics for examples….
I don’t do this for contributions. I do this to serve the audience. I monetize the site with adds. But voluntary contributions are always appreciated.