Hello, I'm wondering if anyone would know how to add a stop line to a moving average, so it looks like what I have drawn in the chart? Thanks!
Announcement
Collapse
No announcement yet.
Moving Average with stop line, help?
Collapse
X
-
Re: Moving Average with stop line, help?
bugscoe
Add the following line of code above your return statement
Alex
PHP Code:drawLineRelative(0, vMA.getValue(MAStudy.MA),10, vMA.getValue(MAStudy.MA), PS_SOLID, 2, Color.blue,"line");
Originally posted by bugscoe
Hello, I'm wondering if anyone would know how to add a stop line to a moving average, so it looks like what I have drawn in the chart? Thanks!
-
bugscoe
You need to do the following. In your conditions instead of setting the color of the plot you assign a color to a variable which you then you use to color both the plot and the stop line eg
if(myFirstCondition)
var myColor = Color.name_of_color (eg Color.black)
if(mySecondCondition)
var myColor = Color.name_of_color
then following that you set the color of the plot using the setBarFgColor() function eg
setBarFgColor(myColor);
and then use myColor also as the color parameter of the drawLineRelative() function
Alex
Originally posted by bugscoe
Thank you Alex!
Could you please advise on what code I need to add so that the line changes to BLUE when price closes above and RED when price closes below?
Comment
-
EMA w/Stop changes color
Looking for some programming help.
I have this EMA which changes color as price is above or below. I then added a stop, a horizontal line extending off of the EMA and would also like that to change color when price is above or below.
I've not been able to figure this out. Anyone know how to do it?
Thanks!Attached Files
Comment
-
if (vMA.getValue(MAStudy.MA) > close(0))
setBarFgColor(Color.red);
if (vMA.getValue(MAStudy.MA) < close(0))
setBarFgColor(Color.blue);
if (vMA.getValue(MAStudy.MA) > close(0))
drawLineRelative(0, vMA.getValue(MAStudy.MA),13, vMA.getValue(MAStudy.MA), PS_SOLID, 2, Color.red,"line");
if (vMA.getValue(MAStudy.MA) < close(0))
drawLineRelative(0, vMA.getValue(MAStudy.MA),13, vMA.getValue(MAStudy.MA), PS_SOLID, 2, Color.blue,"line");
return vMA.getValue(MAStudy.MA);
Comment
Comment