Plotting arrows on your chart with indicators


Category:
0
0

Hey Hahn, I have a lower study indicator that plots a positive or negative value. I need to add so that when the slow stochastics give a buy signal (the two lines cross, red over pink) a green up arrow is plotted where the number value is on the lower study. And when the slow stochastics give a sell signal (two lines cross, pink over red) a red down arrow is plotted where the number value is on the lower study. What I mean when I say “where the number value is on the lower study” is, for example, my lower study value is at -1.8 right now and a buy signal is given on the slow stochastics then the green up arrow will be plotted at -1.8 on the lower study.

Thank you!

Marked as spam
Posted by (Questions: 34, Answers: 56)
Asked on June 22, 2017 9:55 am
3767 views
0
Private answer

Since you did not provide the code for your lower study I am going to create a plot on this example, fixed at -1.8, called myLowerStudy. To make this work with your own lower study you will take the plot for that study and use it to replace the value of -1.8 in the sample code I am providing here. We have done numerous examples of line crossings, particularly using the Stochastic. So I am surprised you have not tried to hash this out on your own and post the code for us to review. If you want to learn something, be sure to make an attempt and post your code. But learning is optional.

The code is listed below and I have included a screenshot showing this plotted in the lower subgraph of a chart.
declare lower;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
plot myLowerStudy = -1.8;
def crossesAbove
def slowKCrossesAboveSlowD = slowK[1] < slowD[1] and slowK > slowD;
def slowKCrossesBelowSlowD = slowK[1] > slowD[1] and slowK < slowD;
plot greenArrow = if slowKCrossesAboveSlowD then myLowerStudy else Double.NaN;
greenArrow.SetDefaultColor(Color.GREEN);
greenArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plot redArrow = if slowKCrossesBelowSlowD then myLowerStudy else Double.NaN;
redArrow.SetDefaultColor(Color.RED);
redArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on June 22, 2017 11:06 am