An Indicator for Closing Price at Top/Bottom of Price Bar


Category:
0
0

Hello Pete,

Could you please code a green arrow that shows below the price bar when the price closes on the top 30% (have the ability to change the number) of the bar (based on a time chart – 1min – Monthly) AND it is above the 50 simple moving average (have the option to change the type of moving average and how it is calculated – like in TOS).

Also, a red arrow that shows above the price bar when the price closes on the bottom 30% of the bar AND it is below the 50 simple moving average.

Thank you.

John

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on August 25, 2018 3:50 pm
68 views
0
Private answer

I’m going to steal some code from a previous post for this. Then adapt it just a tad bit to fit your request.

Here is a link to the previous post: https://www.hahn-tech.com/ans/candle-closes-lower-half-compute-percent-total/

Here is that base code with a few items added to include your additional specifications:

input percentUpper = 30.0;
input percentLower = 30.0;
input length = 50;
input averageType = AverageType.SIMPLE;
plot ma = MovingAverage(averageType, close, length);
def percentCloseWithinRange = if (high – low) <> 0 then (close – low) / (high – low) else 0;
plot closeUpper = close > ma and 100 - (percentCloseWithinRange * 100) <= percentUpper;
closeUpper.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
closeUpper.SetDefaultColor(Color.CYAN);
plot closeLower = close < ma and percentCloseWithinRange * 100 <= percentLower;
closeLower.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
closeLower.SetDefaultColor(Color.MAGENTA);

Screenshot below shows the result.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on August 25, 2018 5:04 pm
0

Thanks Pete! Works very well. Funny thing is that I was looking at the post you referred to before asking for your help. But I couldn’t figure in how to do it.

( at August 25, 2018 5:58 pm)