Remap function

Greetings !!!!

This is my first post / query.

Apologies for any errors in asking or posting.

I am designing a trading system which has Price Momentum Scores , Volume Surge scores etc that would sum to a Total Score of all.

I further take this Total Score to Backtest with Entry Condition to select the top 5 of the Total Scores.

Well but while using Remap I stumbled upon NaN when the High Low and Close are same and this further disrupts the Total Score.

Example

Day Date H L C
D0 04-04-2025 84 80 80
D1 03-07-2025 80 80 80
D2 02-07-2025 81.9 78.3 80.4
/// DCR Daily Closing Range   USING REMAP
DCRDay0 = Remap( Close, Low, High, 0, 100 ) ; // DCR DAILY CLOSING RANGE
DCRDay1 = Ref(DCRDay0,-1);; // DCR DAILY CLOSING RANGE
DCRDay2 = Ref(DCRDay0,-2);
Final DCR_Score = SafeDivide( DCRDay0 + DCRDay1 + DCRDay2, 3 );

Here
DCRDay0 = 0
DCRDay1 = -nan(ind)
DCRDay2 = 58.33
So the Final DCR_Score here is 0

On the contrary if I use this

DCRDay0 = SafeDivide( (C - L), (H - L), 0 ) * 100;  // Default to 0 if zero range
DCRDay1 = Ref(DCRDay0, -1);
DCRDay2 = Ref(DCRDay0, -2);
Final DCR_Score = SafeDivide( DCRDay0 + DCRDay1 + DCRDay2, 3 );

Here
DCRDay0 = 0
DCRDay1 = 0 (default due to division by zero)
DCRDay2 = 58.33
So the Final DCR_Score here = (0 + 0 + 58.33) / 3 = 19.44 Z

This has landed me in a conundrum so my query is am I using Remap correctly or what method is more logical and rational?

As it was explained dozens of times already, NaN is “not a number” and result of 0 / 0 ( zero divided by zero ) which is illegal operation. Min value must be smaller than max.

3 Likes

I know that NaN is not a number Mr. Thomaz.

I already showed what Im trying to derive and also exhibited 2 methods to derive the same. The out put of the Method1 with Remap gives an output different that the Method2. Thats what I wanted to clarify Mr. Thomaz.

Anyways I opted for Method2 which is mathematically accurate. Remap fails mathematically atleast to achieve what I need.

Thanks for your reply Mr. Thomaz.

Im not sure how sensitive your formula is, but instead of remaping the lower end to 0,
either use 1 or some very small positive decimal and see if it sorts your problem.
This is the most popular way to sort divide by 0 issue.

In either case, your Final score is the top 5 largest ones anyway.

1 Like

It makes no sense to use safedivide with constant divisor == 3. SafeDivide makes only sense when divisor is not constant and can be equal 0.

You are using Remap incorrectly as explained already. MIN AND MAX must be different. Mathematically you cannot map single point (min==max) to range 0..100.

Adding small amount as suggested above is one of many possibilities.

5 Likes

Ohh Yess now it got it. Thanks. @Tomasz @nsm51 :heart_suit:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.