Download MetaTrader 5
To add comments, please log in or register
Unable to find the right application? Order it!
Felipe Villegas
31
Felipe Villegas 2014.08.12 21:07 

Hello,

I'm trying to make an indicator that takes 4 entry values (Stochastic Oscillator, Stochastic Oscillator Slow, RSI(9) and RSI(14)), powers them to some set weights (w11 to w14) and then multiplies the result to store it in a variable (S1). Then, this variable is multiplied by another set weight (c1) and adds it to the same calculation (S2) but with different weights (w21 to w24 & c2). The result of the sum is stored in the variable ExtOutput[]. If I draw ExtOutput[], the indicator works fine but the range of the result is meant to be between 0 and 100 (similar to the Stochastic Oscillator) but because of the calculations, it varies between 0.2 and 1.4. 

 

I've tried to normalize the results using a standard formula:

 

Buf_0[i] = (ExtOutput[] -  ExtOutput[ArrayMinimum(ExtOutput,WHOLE_ARRAY,0)])*100/(ExtOutput[ArrayMaximum(ExtOutput,WHOLE_ARRAY,0)] - ExtOutput[ArrayMinimum(ExtOutput,WHOLE_ARRAY,0)]);

 

When I enter this code, the indicator stops working and it does not draw. Trying to figure out the error, I found out that the maximum value I get with ArrayMaximum() is 2147483647 (EMPTY_VALUE) so the normalization formula gives values close to 0 due to the high number in the denominator. 

 

Does anyone know how to fix this issue?. I need the output of ExtOutput[] to be ranged from 0 to 100 so I can draw it in the chart. Code is down below, thanks in advance! 

Alain Verleyen
Moderator
28561
Alain Verleyen 2014.08.13 13:27  
ArriVM:

Hello,

I'm trying to make an indicator that takes 4 entry values (Stochastic Oscillator, Stochastic Oscillator Slow, RSI(9) and RSI(14)), powers them to some set weights (w11 to w14) and then multiplies the result to store it in a variable (S1). Then, this variable is multiplied by another set weight (c1) and adds it to the same calculation (S2) but with different weights (w21 to w24 & c2). The result of the sum is stored in the variable ExtOutput[]. If I draw ExtOutput[], the indicator works fine but the range of the result is meant to be between 0 and 100 (similar to the Stochastic Oscillator) but because of the calculations, it varies between 0.2 and 1.4. 

 

I've tried to normalize the results using a standard formula:

 

Buf_0[i] = (ExtOutput[] -  ExtOutput[ArrayMinimum(ExtOutput,WHOLE_ARRAY,0)])*100/(ExtOutput[ArrayMaximum(ExtOutput,WHOLE_ARRAY,0)] - ExtOutput[ArrayMinimum(ExtOutput,WHOLE_ARRAY,0)]);

 

When I enter this code, the indicator stops working and it does not draw. Trying to figure out the error, I found out that the maximum value I get with ArrayMaximum() is 2147483647 (EMPTY_VALUE) so the normalization formula gives values close to 0 due to the high number in the denominator. 

 

Does anyone know how to fix this issue?. I need the output of ExtOutput[] to be ranged from 0 to 100 so I can draw it in the chart. Code is down below, thanks in advance! 

 

 

You don't need ArrayMaximum or ArrayMinimum, are applying this on each tick ? Simply get a global/static variable to get the max and compare your current value with this max. Same  for min. Manage the EMPTY_VALUE exception.

What is the value of ExtOutput[] ?

Felipe Villegas
31
Felipe Villegas 2014.08.13 22:38  
Hey, I over complicated the problem! Following your advice on the global variable I was able to get the max and the min easily. Thanks a lot!!
Alain Verleyen
Moderator
28561
Alain Verleyen 2014.08.14 09:58  
ArriVM:
Hey, I over complicated the problem! Following your advice on the global variable I was able to get the max and the min easily. Thanks a lot!!
You are welcome.
/
To add comments, please log in or register