Normalizing Values for an Add to Composite

I am trying to learn arrays as well as the ATC function so I was using a simple normalization calculation to range bound a set of values in this case an Advance/Decline Ratio using Norgate Data. I obviously don't have the concepts down as I keep getting zeros for values when trying to normalize the data. The code below is what I have been experimenting with for this issue... Any pointers or clarifications would be greatly appreciated.

/* Normalization:
Normalizing Values
A = Smallest Data Value = LoVaL
B = Largest Data Value  = HiVaL
a = Small Scale number	= LS 
b = Large Scale number	= HS
X = Value
X = a+(X-A)*(b-a)/(B-A)
*/

//#SP1500ADR (S&P 1500 Advance/Decline Ratio)
Syma = "~Test Normalized CompositeS"; 
Sym1  = Foreign("#SP1500ADR","C");

HiValADR=0;
LoValADR=0;
HSADR = 0;
LSADR = 0;

HiValADR == Highest(Sym1);
LoValADR == Lowest(Sym1);
HSADR ==100;
LSADR == 0;
ADR = LSADR + (Sym1 - LoValADR)*(HSADR-LSADR)/(HiValADR-LoValADR);


AddToComposite(ADR,syma,"x");

You can use remap function

// Normalize entire array to 0..100 range
normalized = Remap( input, LastValue( Lowest( input ) ), LastValue( Highest( input ) ), 0, 100 );

As to your own code, note = is assignment, == is EQUALITY CHECK. To assign, use =

Tomasz,

Thank you for the answer and example. I did not know about the Remap function that is so much simpler and efficient. Thank you again.

1 Like

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