HuyTitan:
My code work correctly with:
Momentum_Buffer [ Momentum_Position ] = Close [ Momentum_Position ] * 100 / Close [ Momentum_Position + Momentum_Period ] ;
But with:
Momentum_Buffer [ Momentum_Position ] = ( iRSI ( Symbol () , Period () , Momentum_Period , PRICE_MEDIAN , Momentum_Position ) * 100 ) / iRSI ( Symbol () , Period () , Momentum_Period , PRICE_MEDIAN , Momentum_Position + Momentum_Period ) ;
It doesn't work. I don't know why. Please help me fix it.
This probably returned zero... so you should check for that, and skip the division if it's zero:
iRSI ( Symbol () , Period () , Momentum_Period , PRICE_MEDIAN , Momentum_Position + Momentum_Period )
But logically, RSI of previous bar isn't zero.
HuyTitan:
But logically, RSI of previous bar isn't zero.
But logically, RSI of previous bar isn't zero.
Your RSI period is 7, and you call iRSI() right up to Bars-1...
-
Why did you post your MT4
question in the Root / MT5 Indicators
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - The lookback of RSI is Momentum_Period - 1. You lookback Momentum_Position + Momentum_Period - 1
bars. Therefor your maximum lookback is the sum of those.
How to do your lookbacks correctly. -
You should stop using the old event handlers
and IndicatorCounted() and start using new event handlers.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
How to do your lookbacks correctly.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
My code work correctly with:
Momentum_Buffer [ Momentum_Position ] = Close [ Momentum_Position ] * 100 / Close [ Momentum_Position + Momentum_Period ] ;
But with:
Momentum_Buffer [ Momentum_Position ] = ( iRSI ( Symbol () , Period () , Momentum_Period , PRICE_MEDIAN , Momentum_Position ) * 100 ) / iRSI ( Symbol () , Period () , Momentum_Period , PRICE_MEDIAN , Momentum_Position + Momentum_Period ) ;
It doesn't work. I don't know why. Please help me fix it.