How NOT to Hack MQL4 - page 2

 

Ok, so I have tested Uzben’s iCustom method against the ArrayCopyRates method.

I have had to create a dummy indicator which does as little work as possible in order to test the Uzben’s method.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

double buffer[];

int init(){

   SetIndexStyle( 0,DRAW_LINE);
   SetIndexBuffer(0,buffer);

   return(0);
}

int start(){
   int counted_bars=IndicatorCounted();
   
   for( int n= Bars-counted_bars; n>=0; n-- )
      buffer[n]= Close[n];

   return(0);
}

I have also tweaked Uzben’s code to use the new indicator and to suit my own aesthetic preferences.

int i=0;
int timeFrames[]= {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1};

void init(){
   int size = ArraySize(timeFrames);
   
   for( i=0; i<size; i++ ){
      iCustom( "USDCHF", timeFrames[i], "dummy", 0, 1 );
      Sleep(5000);
   }
    
   for( i=0; i<size; i++ )
      Print( "USDCHF" + "_Bars_Period_" + timeFrames[i] + "=" + iBars("USDCHF",timeFrames[i]) );
}

void start(){
}

If the history is deleted then both methods produce the same number of bars in the history and the right click Refresh does not increase the history length. However, if there is an existing history both methods still give the same amount of bars but the Refresh method then works harder to fill in gaps in the history, making the bars length longer.

I conclude that either method works for recent data, although the ArrayCopyRates method seems simpler and computationally less expensive. Neither method gives the fullest possible history data but if used sufficiently often there should be no missing data. (This becomes problematic on the lowest timeframes).

 

The iShow indicator is a dummy indicator. Well mostly it draws a histogram of values I pass to it via globalvariableset(), so it's useless for analysis before the point of attached. I was not sure if this method would have worked. I know it worked in the back-tester for getting data for other Symbols/Timeframes when I wanted to test an EA which was influenced by events happening in other Pairs.

Anyways good job on all the tests and results. Tho I don't play around much with creating Indicators and PostMessageA features, it's never too late to learn and I appreciate your examples.

Reason: