How to get Ratio of 2 Moving averages
How do I code and get the ratio of 2 moving averages ? Anyone kindly shed some light please. I need to calculate the ratio of 2 Moving averages .
What does "ratio" mean? Show formula...
The ratio just means how many times one value contains another. Like 4:3, 2:1 and so on.
Take the Difference Two iMA indicator and instead of the line
for(int i=limit; i<rates_total; i++) { Diff_Two_iMABuffer[i]=FastBuffer[i]-SlowBuffer[i]; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Filling indicator buffers from the MA indicator | //+------------------------------------------------------------------+
put
for(int i=limit; i<rates_total; i++) { Diff_Two_iMABuffer[i]=FastBuffer[i]/SlowBuffer[i]; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Filling indicator buffers from the MA indicator | //+------------------------------------------------------------------+
There is no difference: at least apply the "-" sign, at least apply the "/" sign, at least apply the "ratio" - the final form of the indicator will remain the SAME. See the example below: three windows - each with its own formula
- fast-slow
- fast/slow
- (Fast-Slow)/Slow
Tried using StringTodouble function but it just won't work.
Thanks for this. Incorporated it into my code and it works. I owe you one.
Tried using StringTodouble function but it just won't work.
You can get the corrected indicator here: Two iMA Formula
The first indicator works well also. Can you kindly show me how to get real time values of the indicator and use it in a way to close trades . Something like if ( "slow/fast" > 0){trade.PositionClose(symbol());}
I can recommend two steps: step #1 - Creating an iMA indicator handle, getting indicator values
Step #2 will be after studying lesson #1.
- 2020.03.05
- www.mql5.com
The first indicator works well also. Can you kindly show me how to get real time values of the indicator and use it in a way to close trades . Something like if ( "slow/fast" > 0){trade.PositionClose(symbol());}
- 2022.04.07
- www.mql5.com
