Buffer / speed problem with MTF charts display in same window ?

 

Hi All,

See first pic below, which is what I am aiming for- an MTF display for my indi with both tables and charts in the same window, 4TFs in my case given maxBars= 20 latest bar calculation displayed, to fit all the TFs in one screenshot.

[ NOTE: I can get this display by using mql versions running for M1, M5, M15 and H1 TF displays individually, via dropping such 4 mq4's one by one from the Navigator window. But, when I switch TFs on the chart, I can see the charts but only the last table which switches display position to the first TF. ]

What I need is a single mq4 that can display the whole indi at once. The second problem is the lack of proper display on the highest TF, H1.

What I get from the current mq4 is just the display of the last table, H1, in the first display position (M1, leftmost) and the last chart, H1, in its last position(H1, rightmost). See second pic below.

I am a newbie coder, so would very much appreciate actual code snippets and advice !

Check the Start() and main function code snippets below, and the full mq4 attached.

Basically the currency strength calcs are done from calcTMA, getSlope, and calcCSS functions that ultimately depend upon iMA (tf, shift) and iCllose (tf, shift). The main function, DrawChartsTables, then starts with the usual IndicatorCounted lines to avoid recalculations, adjusts for the TF bars size to run the bars loop, then employs shift = iBarshift for all TFs, and does the calculations by calling above functions and uses some additional code (diff section). The 8 currency charts are displayed via Set commands for the 8 buffers; and the CurrencyTable via ObjectCreate.

SUGGESTIONS:

1. Is buffer overflow a problem? How would I use, say, ArrayCopy or ArrayCopySeries here?

(But then why would it display single TF x 4 via Navigator drops in same window?)

2. Should I use Sleep() in Start() after each DrawChartsTables function call to slow down the TF calculation switches?

What are appropriate numbers?

3. Is placement of RefreshRates in DrawChartsTables the problem? Moving around RefreshRates in the function causes the last table vs the first table to be displayed in the first TF display position (leftmost.)

Start() code:

/+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{  
 
   DrawChartsTables (0);
   Sleep(500);
   DrawChartsTables(1);
   Sleep(600);
   DrawChartsTables(2);
   Sleep(700);
   DrawChartsTables(3);
   Sleep(400);
   //Only display: last table in first TF, last chart in last TF. 

}
return(0);

Main Function:

//+------------------------------------------------------------------+
//| DrawCharts&Tables (j); j is TF from 0 (leftmost) to 3(rightmost)                                |
//+------------------------------------------------------------------+

 void DrawChartsTables (int j)
  
{  
   
   int i;
   int tf = GettimeFrameInteger(MTF[j]);
   Print(tf);
   
   int maxBarsTF = maxBars * tf;
   int counted_bars = IndicatorCounted();
   if (counted_bars < 0)  return(-1);
   if (counted_bars > 0)  counted_bars--; 
   int limit= Bars - counted_bars;
   if (limit > maxBarsTF) limit = maxBarsTF;
   
  
   for ( i = limit; i >= 0; i=i-tf )  // Counter decremented by TF proportion, saves calcs
   { 
      for ( int k = 0; k < CURRENCYCOUNT; k++ )
      { SetIndexShift(k, shiftChart[j]);} 
      
     
      // Cannot use shift = i except for Period(), current TF.
   
      int shift= iBarShift(NULL,tf, Time[i], false) ;
      Print (shift); 
      ArrayInitialize(currencyValues, 0.0);

      // Calc Slope into currencyValues[]  
      calcCSS( tf, shift ); 
       
     double diff = 0.0; //check correct init         
     {
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "USD" ) != -1 ) ) || ( !showOnlySymbolOnChart && USD ) )        
      {
         arrUSD[shift] = currencyValues[0];
         if ( diff == 0 ) diff += currencyValues[0]; else diff -= currencyValues[0];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "EUR" ) != -1 ) ) || ( !showOnlySymbolOnChart && EUR ) )        
      {
         arrEUR[shift] = currencyValues[1];
         if ( diff == 0 ) diff += currencyValues[1]; else diff -= currencyValues[1];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "GBP" ) != -1 ) ) || ( !showOnlySymbolOnChart && GBP ) )        
      {
         arrGBP[shift] = currencyValues[2];
         if ( diff == 0 ) diff += currencyValues[2]; else diff -= currencyValues[2];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "CHF" ) != -1 ) ) || ( !showOnlySymbolOnChart && CHF ) )        
      {
         arrCHF[shift] = currencyValues[3];
         if ( diff == 0 ) diff += currencyValues[3]; else diff -= currencyValues[3];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "JPY" ) != -1 ) ) || ( !showOnlySymbolOnChart && JPY ) )        
      {
         arrJPY[shift] = currencyValues[4];
         if ( diff == 0 ) diff += currencyValues[4]; else diff -= currencyValues[4];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "AUD" ) != -1 ) ) || ( !showOnlySymbolOnChart && AUD ) )        
      {
         arrAUD[shift] = currencyValues[5];
         if ( diff == 0 ) diff += currencyValues[5]; else diff -= currencyValues[5];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "CAD" ) != -1 ) ) || ( !showOnlySymbolOnChart && CAD ) )        
      {
         arrCAD[shift] = currencyValues[6];
         if ( diff == 0 ) diff += currencyValues[6]; else diff -= currencyValues[6];
      }
      if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "NZD" ) != -1 ) ) || ( !showOnlySymbolOnChart && NZD ) )        
      {
         arrNZD[shift] = currencyValues[7];
         if ( diff == 0 ) diff += currencyValues[7]; else diff -= currencyValues[7];
      }
    }
         
      if (shift == 1 )
      {
         ArrayCopy(currencyValuesPrior, currencyValues);
      }
      if ( shift == 0 ) 
      {
         ShowCurrencyTable( j); // Show ordered table
      }
      
    RefreshRates();
   
 //  loop to delete indi display over more than latest maxBars.

   while(shift >= 0)
   {   
    arrUSD[maxBars+1] = EMPTY_VALUE;
    arrEUR[maxBars+1] = EMPTY_VALUE;
    arrGBP[maxBars+1] = EMPTY_VALUE;
    arrJPY[maxBars+1] = EMPTY_VALUE;
    arrCHF[maxBars+1] = EMPTY_VALUE;
    arrCAD[maxBars+1] = EMPTY_VALUE;
    arrAUD[maxBars+1] = EMPTY_VALUE;
    arrNZD[maxBars+1] = EMPTY_VALUE;
    
    shift--;
   }
   
   }
     
   return(0);
} 
Files:
Reason: