- Custom Indicators parameters from an expert.
- Indicator without chart
- iCustom for Legacy Indicator
Hi, I have created an indicator that makes multiple calls (50+) to iCustom. I am pretty new to coding but feel maybe this isn't an optimal way to do it. Is there a better way?
50 calls in one tick?
If so, can't you copy the buffer with all the bars that you need in one go?
50 calls in one tick?
If so, can't you copy the buffer with all the bars that you need in one go?
Thanks Keith for the reply.
A function which has the CopyBuffer() function and error checking is called 50+ times at the start of OnCalculate. The iCustom calls are in the OnInit.
Here is an short example of my amatuer code if you would't mind having a look.
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- number of values copied int values_to_copy; int limit=0; limit = prev_calculated-1; if (limit<0) limit = 0; values_to_copy = rates_total; // + ----------------------------------- + //--- fill the arrays with values of the CALC indicator //--- if FillArraysFromBuffer returns false, it means the information is nor ready yet, quit operation if(!FillArrayFromBuffer(IndCalc_A,IndCalc_B,Calc1_handle,values_to_copy)) return(0); //--- form the message string comm1=StringFormat("%s ==> Updated value in the indicator Calc1: %d", TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS), values_to_copy); //--- if FillArraysFromBuffer returns false, it means the information is nor ready yet, quit operation if(!FillArrayFromBuffer(IndCalc_C,IndCalc_D,Calc2_handle,values_to_copy)) return(0); //--- form the message string comm2=StringFormat("%s ==> Updated value in the indicator Calc2: %d", TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS), values_to_copy); //... int lookback=MathMax(2, limit); //for(int i = 0; i < MathMax(values_to_copy,55); ++i) //for(int iBar = MathMax(lookback, prev_calculated; iBar < Bars; ++iBar){ //for(int i = Bars(_Symbol,_Period)-1-MathMax(lookback, prev_calculated); i >= 0; --i) //for(int i=limit; i<rates_total;i++) int counted_bars= Bars(_Symbol,_Period)-1-MathMax(lookback, prev_calculated); for(int i = counted_bars+1; i >= 0 && !IsStopped(); i--) { //... return rates_total-1; }
Something is slowing the indicator down and I thought that it might be the way I was using iCustom and the buffers.
values_to_copy = rates_total;
if(!FillArrayFromBuffer(IndCalc_A,IndCalc_B,Calc1_handle,values_to_copy))
Why are you reading in all bars, when your lookback is only two?
Why are you reading in all bars, when your lookback is only two?
Thanks for the reply and that's a good question. That explains why I had slowdowns.
It's good to have the person whos code I used for the lookbacks tell me what I have done wrong. Thank you for pointing me in the right direction.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use