Determine the position of the close in a CS

Hi guys,

This is really noob, but Im not having any sucess coding this concept.

I want to be able to determine the closing price position in the candle stick.
For example:
Is the close within 30% from the high?
Is the close within 30% from the low?
Is the candle within the middle 40% of the candlestick?

Much thanks for you helping out a complete noob!


Starting point:

ClosePosition = Remap( Close, Low, High, 0, 100 );

It's always useful to have some code to talk about. So if you have a failed attempt, show it here inside code tags and someone can help you out.

That said:

// total size of candle
candleSize = High - Low;

// distance from high to closing price
candleHighToClose = High - Close;

// high to closing as ratio of size of candle
candleWithin30pctOfHigh = candleHighToClose / candleSize <= 0.3;

// some plots to see your results
Plot(C, "Candle", colorGreen, styleCandle);
PlotShapes( candleWithin30pctOfHigh * shapeDownArrow, colorRed);

Thank you Mordrax. i will try this out tomorrow.
My attempted solution looks almost the same, the results I was getting didnt seem to make sense.
With your code I can now compare.

I appreciate your help, thank you.

Also take a look at @JohnHT 's hint. It's actually a very elegant way of doing it.

Remap looks like it's doing linear interpolation from source to destination so the first parameter ( in this case the Close) can be directly compared to 70 for 70%, 30 for 30%.


Thanks Mordrax and JohnHT.

Im posting this update for anyone else interested in understanding this more.

JohnHT solution to use the remap function is really elegant and simple. However, there is one thing that you need to know to interpret the results correctly. I will use my case as an example

Aim: Identify the ratio between the closeprice and High/Low of a candlestick. i.e; Is the close within 30% of the high or 30% of the low

The results given by the remap function work this way.
It measures the distance of the close from the low to the high

for example. If remap returns a result of 75.00, this means the close is 75% up from the low, meaning it's 25% from the high. If remap returns a value of 23.00, this means the close is 23% up from the low or 77% from the high. If it remap returns 100, then the close = High and when it returns 0, the close = Low.

Secondly, remap returns results in full numbers. What I mean is 75.00 is 75%, rather than 0.75.

Once you wrap your head around these two points, using remap() function is easy

A big thanks to Mordax and JohnHT. I wouldnt have figured this out without you both. :grin:

1 Like

Remap returns whatever you want. The output range is definable by the user. If you write

ClosePosition = Remap( Close, Low, High, 0, 1 ); // note last argument changed to 1

it will produce output 0..1 (and in your example 0.75)


Thanks for the clarification Tomasz