When counting up, sq-last is based on i-1
when counting down, sq_last is based on i+1
kitgain: the result are not the same,
buf1[i]=iMA(NULL,timeframe,EMA_fast,0,MODE_EMA,PRICE_CLOSE,i); buf2[i]=iMA(NULL,timeframe,EMA_slow,0,MODE_EMA,PRICE_CLOSE,i); RSI_signal = iRSI(NULL,timeframe,RSI_parameter,PRICE_CLOSE, i);
You look back is the maximum of EMA_fast, EMA_slow, RSI_parameters, and 1 (buff5[i+1]).Handle it properly No need for the decrement. int limit=Bars-counted_bars; if(counted_bars==0)limit--; if(counted_bars>0) limit++; //---- main loop for(int i=limit; i>=0; i--)
int lookback = MathMax( MathMax(EMA_fast, EMA_slow), MathMax(RSI_parameter, 1) ); for(int i=Bars - 1 - MathMax(lookback, counted_bars); i>=0; i--)
Contradictory information on IndicatorCounted() - MQL4 forumif(NewBar() || i>0)sg_last=sg_now;
You can't do this. NewBar is not indicating a change but i is changing in your loop and so must sg_last. When a new bar does occur, your loop recalculates bar one, sg_last must not be changed there but must be for bar zero. sg_now must be saved in a buffer so you can set sg_last=buffer[i+1]- Of course the results are not the same. If you are counting up, you are using future bars values (sig_last) to determine previous bar arrows. That's called repainting and is useless for trading.
WHRoeder:
- You look back is the maximum of EMA_fast, EMA_slow, RSI_parameters, and 1 (buff5[i+1]).
Handle it properly No need for the decrement. Contradictory information on IndicatorCounted() - MQL4 forum - You can't do this. NewBar is not indicating a change but i is changing in your loop and so must sg_last. When a new bar does occur, your loop recalculates bar one, sg_last must not be changed there but must be for bar zero. sg_now must be saved in a buffer so you can set sg_last=buffer[i+1]
- Of course the results are not the same. If you are counting up, you are using future bars values (sig_last) to determine previous bar arrows. That's called repainting and is useless for trading.
Dear Uncle William,
Thank you very much for your answer.I will study it.
I have sent a private message to you but I'm not sure whether it is done ok.
If not, could you PM me or give me your email?
Thank you again!
wlonghai@sohu.com
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
Hi Gentleman,
I am confused when I change the direction of for recycle from {i=0;i<limit ;i++} to {i=limit;i>=0;i--} or {i=limit-1;i>=0;i--}in a indicator main loop, the result are not the same, while the last indicator show more late than the previous one.
Here are the codes,
The previous one source code can be found here:https://www.mql5.com/en/code/viewcode/8633/46617/sidus_v_2.mq4
The last one which I changed is,
The result are the attached pictures,
We can see the right one are more late than the left one.
Could you know the reasion? And Could you help me to modify and complete this indicator?
Thank you very much in advance!