Crossing SMAs Change Arrow direction and Colors


Category:
0
0

Hey Pete!

How would I make a SMA line to be all “Arrow_up”s when its above a different SMA, and all “Arrow_down”s once it crosses below? Oh and change the color of the arrows from green to red. Thanks so much!

Marked as spam
Posted by (Questions: 10, Answers: 14)
Asked on May 11, 2017 10:53 pm
152 views
0
Private answer

You did not specify the length of your moving average so I’ll provide an input parameter to adjust it.

input lengthOne = 50;
input lengthTwo = 200;
def smaOne = Average(close, lengthOne);
def smaTwo = Average(close, lengthTwo);
plot arrowsUp = if smaOne >= smaTwo then smaOne else Double.NaN;
arrowsUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowsUp.SetDefaultColor(Color.GREEN);
plot arrowsDown = if smaOne < smaTwo then smaOne else Double.NaN;
arrowsDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrowsDown.SetDefaultColor(Color.RED);

The screenshot below show how it plots on a chart. I have included two simple moving averages on the chart that plot normally so you can see that the arrows change direction and color based on their relative position. This code is not set to plot smaTwo, only the arrows based on smaOne. If you want this study to plot either smaOne or smaTwo in their normal fashion you can change the def to plot for each of the sma’s.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 12, 2017 8:19 am