refresh tips? - page 2

 
fly7680: Is there any mistake I do not understand?
  1. You are accessing Time[] in init. There may be no chart yet:
    1. Terminal starts.
    2. indicators/EAs are loaded.
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password; connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called; TickValue and TimeCurrent are now valid.

  2. Drop your new bar code; unnecessary in indicators.
    #define INDEX int
    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[]){
       #define  REDRAW_BAR        true                    // Redraw bar.
       #define  LAST              0                       // Draw bar zero?
       #define  REDRAW_BAR_LAST   (LAST == 0)             // Redraw bar last.
       #define  LookBack ...
       INDEX    iBar        = rates_total - MathMax(LookBack, prev_calculated);
       while(iBar > LAST){  --iBar;
          // update buffers[iBar]
          if(iBar == 1) // do new bar code
       }
       return rates_total-(iBar+REDRAW_BAR_LAST);
    }
              How to do your lookbacks correctly.
 

Here I am again because I could not solve my problem and I do not understand where I am wrong...I show an image:


//--My Function
void DTrend(string Asset, int i){

     UP=false; DW=false; OK=false; A1=0; A2=0;

   if(iOpen(Asset,PERIOD_D1,1+i) < iClose(Asset,PERIOD_D1,1+i)
   && iOpen(Asset,PERIOD_D1,  i) < iClose(Asset,PERIOD_D1,  i) ){ 
      
      UP=true; Print("Candela 1 e 2 Verdi");
     }
     
      else if(iOpen(Asset,PERIOD_D1,1+i) > iClose(Asset,PERIOD_D1,1+i)
           && iOpen(Asset,PERIOD_D1,  i) > iClose(Asset,PERIOD_D1,  i) ){
      
              DW=true; Print("Candela 1 e 2 Rosse");
             }
             
                   
                   Print("UP: "+IntegerToString(UP)); Print("DW: "+IntegerToString(DW));
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
#define  INDEX int
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[]){
   #define   REDRAW_BAR         true                      // Redraw bar.
   #define   LAST               0                        // Draw bar zero?
   #define   REDRAW_BAR_LAST   (LAST == 0 )             // Redraw bar last.
   #define   LookBack          500
   INDEX    iBar        = rates_total - MathMax (LookBack, prev_calculated);
   while (iBar > LAST){  --iBar;
       // update buffers[iBar]
       if (iBar == 1 ){ Print("ibar: "+iBar); // do new bar code
               
          DTrend(Symbol(),iBar); 

       
   }
   return rates_total-(iBar+REDRAW_BAR_LAST);
}
Any suggestions to resolve? Thank you all!!!
 
  1. If you only operate on bar one, why is LAST zero?

  2. DTrend(Symbol(),iBar); 
    
    if(iOpen(Asset,PERIOD_D1,1+i) < iClose(Asset,PERIOD_D1,1+i)
    iBar is the current chart. If your chart isn't D1 then you are mixing apples and oranges.
  3. Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
 

if I use different time frames, I should download M15, M30, H1, H4, D1 data with the function ?!?

bool  download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT)
 
What part of "the specific pair/TF referenced" is unclear?
 

I have created a Multi Time Frame Indicator, and I would like to be in M30 by default but can read, for example, Candles in D1, H4, H1 and M30 with iTime () iCLose () iOpen () etc ... I should download data every time launching MT4

 
fly7680: I have created a Multi Time Frame Indicator, and I would like to be in M30 by default but can read, for example, Candles in D1, H4, H1 and M30 with iTime () iCLose () iOpen () etc ... I should download data every time launching MT4

@whroeder1 has already answered you in regards to that:

Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
          Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

Be it multi-time-frame or multi-symbol, the concepts are similar, so read the following thread (from beginning to end) for some insight:

Forum on trading, automated trading systems and testing trading strategies

Anyone know how to develop a multicurrency indicator ?

Fernando Carreiro, 2016.04.21 04:46

In a standard indicator, you would build the buffer arrays with data from the parameters sent via the OnCalulate( ... ) event function. But, for multi-currency and/or multi-time-frame, you will have to use one of two solutions:

  • Using the old method of the "iFunction" variations, such as iTime(), iVolume, iOpen, iClose, etc. but with a different symbol such as "EURUSD", "JPYUSD", etc. instead of the default _Symbol or Symbol().
  • Using the newer method of the first variant of ArrayCopyRates() function together with array pointers of MqlRates.  The "copied" arrays, will not actually take up any space and will just be pointers to the existing data of the various symbols and time-frames.

However, for this to work, one of two conditions have to exist for the multi-symbol and/or multi-time-frame to work:

  • Either the respective charts for the symbols and time-frames are already open, so that no error is generated,
  • or you will get an error 4066 (ERR_HISTORY_WILL_UPDATED) the first time you request the data, and you will have to code a sleep & retry loop, in order to wait for data to download and then request the data again.

My personal suggested solution, which I find as the most efficient as well as easiest way to handle the 4066 error, is the ArrayCopyRates() and MqlRates method.

There is more information about this the MQL4 documentation and help files.

PS! NB! When accessing built-in indicator functions, such as iMA(), iATR(), etc. for the various symbols and time-frames, remember to also implement the sleep and retry loops so as not to get the 4066 error either. Here is a quote from the MQL4 documentation:

Anyone know how to develop a multicurrency indicator ?
Anyone know how to develop a multicurrency indicator ?
  • 2016.04.21
  • www.mql5.com
Anyone know how to develop a multicurrency indicator ? I want to choose BETWEEN 1 to 10 different currencies and 5 bars for each currency...
 
thanks to Fernando Carreiro, I will read carefully the whole topic to better understand this concept!
 

hello to all, I tried to do some tests to take the color of Heinke Hashi in D1 staying in M30 but it does not always work.


//Global scope
extern int TimeFrame=1440; //PERIOD_D1
int count=0;
datetime TimeArray[];
int    i,limit,y=0,counted_bars;

int init()
  {
   counted_bars=IndicatorCounted();
   
   return(INIT_SUCCEEDED);
  }

int start()
  {
  
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars+TimeFrame/Period();

   for(i=0,y=0;i<limit;i++)
     {
      if(Time[i]<TimeArray[y]) y++;
      
      if( iCustom(Symbol(), PERIOD_D1, "Heiken Ashi", Red, White, Red, White, 2, y+1) < iCustom(Symbol(), PERIOD_D1, "Heiken Ashi", Red, White, Red, White, 3, y+1) ) // Heiken Verde 
      
         Alert(Symbol()+": HeikenGreen"); 
         
                else Alert(Symbol()+": HeikenRed");     
     }
   return(0);
  }
 

thanks