Hossein Zandi: , it's because of the loop it should be from the right to the left not from the left to the right
- Wrong. Direction of the loop changes nothing (except breaking your iMAOnArray.)
for(int i=rates_total-prev_calculated-1; i>=0; i--){ : Comment(AAA[i+1]);
When prev_calculated was zero, i becomes rates_total - 1. but your comment access one past that, thus array exceeded.- After that, prev_calculated equals rate_total so your loop becomes i=-1; i>=0, and thus does not update bar zero on new ticks.
RSIBuf[i]=iRSI(NULL,0,RSIPeriod,PRICE_WEIGHTED,i); ma[i]=iMAOnArray(RSIBuf,0,20,0,MODE_SMA,i);
You can't start getting RSI values until you have RSIPeriod bars. You can't start computing SMA until you have 20 RSI values.
How to do your lookbacks correctly.
Thanks a lot, problem solved.
I changed it to below if someone is interested.
int lookback = movingaverageperiod // as maximum look bak for(int i = Bars - 1 - MathMax(lookback, counted); i >= 0; i--)

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
Hello,
Please take a look at this code and tell me why I can't access to previous candle's rsi RSIBuf[i+1] ,
I tried this AAA[] Array but still not working when I try to comment (AAA[i+1]) in the strategy tester I get array out of range error please help me how can i use previous candle's data into my calculations