It is really not possible to say without seeing the rest of the indicator code.
The indicator (MY_INDICATOR) that feed to the trading EA is
int limit=rates_total-prev_calculated; if(limit<0) limit=2; if(prev_calculated>0) limit++; //----------------------------------------------------------------------------------------- //BUY SECTION for(int i=1;i<limit;i++) { cobom4roc[i]= iCustom(NULL,0,"H_roc",H_roc_windowshort,200,0,i) + iCustom(NULL,0,"H_roc",H_roc_windowshort,200,0,i) ;
if(combo4roc[i]>0.01) feedbuffer[i]=2;}
And the original H_roc indicator is:
int limit=rates_total-prev_calculated; if(limit<0) limit=2; if(prev_calculated>0) limit++; for(int i=1;i<=limit && (i+shortwindow)<rates_total;i++) { roc_short=Close[i]/Close[i+shortwindow]-1; }
scfx: I find that this trading will run correctly if in my indicator there is an EQUAL sign on limit condition
int limit=rates_total-prev_calculated;
if(limit<0) limit=2;
I'd recommend ignoring those (and open[],close[],etc.) and just set buffers as series and count down (using Open[], Close[], etc) using the simpler: int ic = IndicatorCounted(); if(ic < LOOKBACK) ic = LOOKBACK; for(iBar = Bars - 1 - ic; iBar >= 0; iBar--){ ...
- When you count up useing rates_total and prev_calculated ... return(rates_total) there are two possibilities. If prev_calculated==0 you must loop [0..rates_total-1] (pos<rates_total or all bars) but if prev_calculated != 0 you loop from [prev_calculated-1 .. rates_total - 1] (recalculating the previously forming bar next time.) You have to check in calculating limit. You can NOT use rates_total - prev_calculated. That is your "EQUAL sign on limit condition" problem.
- If you return(rates_total-1) than you can just use [prev_calculated .. rates_total -1] for both cases.
Thank you, WHRoeder.
I will study your note.
SCFX
WHRoeder:
3) I dont think the return value of OnCalculate does anything. You can return(0) and it still functions the same as return(rates_total).
-
I'd recommend ignoring those (and open[],close[],etc.) and just set buffers as series and count down (using Open[], Close[], etc) using the simpler:
- When you count up useing rates_total and prev_calculated ... return(rates_total) there are two possibilities. If prev_calculated==0 you must loop [0..rates_total-1] (pos<rates_total or all bars) but if prev_calculated != 0 you loop from [prev_calculated-1 .. rates_total - 1] (recalculating the previously forming bar next time.) You have to check in calculating limit. You can NOT use rates_total - prev_calculated. That is your "EQUAL sign on limit condition" problem.
- If you return(rates_total-1) than you can just use [prev_calculated .. rates_total -1] for both cases.
SDC: 3) I dont think the return value of OnCalculate does anything. You can return(0) and it still functions the same as return(rates_total).
| Then it needs to be reported as broken. as OnCalculate says: During the function call, the prev_calculated parameter contains a value
returned by OnCalculate() during previous call. |

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
Good morning,
I write a simple EA below to run my indicator
I find that this trading will run correctly if in my indicator there is an EQUAL sign on limit condition
int limit=rates_total-prev_calculated; if(limit<0) limit=2;
......
Without that EQUAL sign, it still trade but the entry is wrong in many occasion.
Can you tell me why it is like that?
Many thanks,
SCFX