Tradingrobot2718 #: I am sorry but I think I'm lazy.
That doesn't exactly connote a serious desire to be successful in the business of trading. Let's just say that you want to be "efficient" instead.
Tradingrobot2718 #: If only the prices starting at index "begin" are relevant, then why isn't the first "begin" prices of the array removed and the "rates_total" parameter adjusted ?
Whether you use the simple form of OnCalculate() or the long form of OnCalculate(), you still need to write a main loop to iterate through the bars of the chart:
intOnCalculate(constint rates_total, // price[] array size constint prev_calculated, // number of previously handled barsconstint begin, // where significant data start from constdouble &price[]) // value array for handling
{
//--- initial position for calculationsint StartCalcPosition=(IntPeriod-1)+begin;
//---- if calculation data is insufficientif(rates_total<StartCalcPosition)
return(0); // exit with a zero value - the indicator is not calculated//--- correct draw beginif(begin>0)
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartCalcPosition+(IntPeriod-1));
//--- start calculations, define the starting positionint pos=prev_calculated-1;
if(pos<StartCalcPosition)
pos=begin+IntPeriod;
//--- main calculation loopfor(int i=pos;i<rates_total && !IsStopped();i++)
MomentumBuffer[i]=price[i]*100/price[i-IntPeriod];
//--- OnCalculate execution is complete. Return the new prev_calculated value for the subsequent callreturn(rates_total);
}
I am sorry but I think I'm lazy. I will write the code that deals with the "begin" parameter of the simplified version of OnCalculate and then use it with every custom indicator. To me, this parameter is useless. If only the prices starting at index "begin" are relevant, then why isn't the first "begin" prices of the array removed and the "rates_total" parameter adjusted ?
The current approach ensures that all timeseries in the chart have the same indexing. If some buffers would start from some hidden "beginning" you should require to read this settings from other place anyway in case you need synchronized data from several indicators or built-in timeseries.
I've just fallen into another trap. When a moving average has a non-zero time shift parameter, than its buffer is smaller. The following access causes an "array out of range error":
MovingAverageBuffer[rates_total-1] //Array out of range error !
Tradingrobot2718 #: When a moving average has a non-zero time shift parameter, than its buffer is smaller. The following access causes an "array out of range error"...
If you want to take that shortcut without a main loop, you have to return rates_total - 1 following OnCalculate().
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I am sorry but I think I'm lazy.
That doesn't exactly connote a serious desire to be successful in the business of trading. Let's just say that you want to be "efficient" instead.
If only the prices starting at index "begin" are relevant, then why isn't the first "begin" prices of the array removed and the "rates_total" parameter adjusted ?
Whether you use the simple form of OnCalculate() or the long form of OnCalculate(), you still need to write a main loop to iterate through the bars of the chart:
I am sorry but I think I'm lazy. I will write the code that deals with the "begin" parameter of the simplified version of OnCalculate and then use it with every custom indicator. To me, this parameter is useless. If only the prices starting at index "begin" are relevant, then why isn't the first "begin" prices of the array removed and the "rates_total" parameter adjusted ?
I've just fallen into another trap. When a moving average has a non-zero time shift parameter, than its buffer is smaller. The following access causes an "array out of range error":
This one is ok:
When a moving average has a non-zero time shift parameter, than its buffer is smaller. The following access causes an "array out of range error"...