iHigh iClose

 

Dear Friends

I was using this codes to get todays high and yesterdays low values in MT4. 

  double ToDayHigh=iHigh(NULL,1440,0);
  double YesterDayLow=iLow(NULL,1440,1);

 Whats the code in MQL5 for the same.

Thanks

 

Noufel 

 
1007:

 

Dear Friends

I was using this codes to get todays high and yesterdays low values in MT4. 

  double ToDayHigh=iHigh(NULL,1440,0);
  double YesterDayLow=iLow(NULL,1440,1);

 Whats the code in MQL5 for the same.

Thanks

 

Noufel 

 

 try this

Paul 

double ToDayHigh=iHigh(_Symbol,PERIOD_D1,0);
double YesterDayLow=iLow(_Symbol,PERIOD_D1,1);

double iLow(string strSymbol,ENUM_TIMEFRAMES tf,int nShift)
{
   double timeseries[1];
   if(CopyLow(strSymbol,tf,nShift,1,timeseries)==1) return(timeseries[0]);
   else return(-1.0);
}
double iHigh(string strSymbol,ENUM_TIMEFRAMES tf,int nShift)
{
   double timeseries[1];
   if(CopyLow(strSymbol,tf,nShift,1,timeseries)==1) return(timeseries[0]);
   else return(-1.0);
}

 

 
1007:

 

Dear Friends

I was using this codes to get todays high and yesterdays low values in MT4.

Please, read article MQL5.community - User Memo :

The   button of the object inserting menu is intended to insert the initial MQL code into the text of the message. An empty window to paste the code in appears as soon as you press this button. In order to finish code adding you should press the Insert button. To cancel the operation you should press the Cancel button. The example of inserting the code is given at the corresponding section.

 

Thanks Rosh and Paul

 

I am getting the description

'=' - constant expression is required 

when i am trying to compile in mql5 for the code

string symbol=Symbol();

Whats the soln please

 

Noufel 

 
1007:

I am getting the description

'=' - constant expression is required 

when i am trying to compile in mql5 for the code


Don't use such expression on global scope. See sections Initialization of Variables and Visibility Scope and Lifetime of Variables
 
"CopyLow" on the Low
"CopyHigh" on the high

And now the code works perfect...
 

Hi friends,

Want to check for at new value(nv) for sell indicator as follows. But no response for this,

help me to fix my pattern

***

 
Krishnamoorthy Ramanathan #: Want to check for at new value(nv) for sell indicator as follows. But no response for this, help me to fix my pattern
bool M5LTPrevM5()
{
    double ov,nv;
   
   ov=iHigh(NULL,PERIOD_M5,1)-iClose(NULL,PERIOD_M5,1);
   nv=iClose(NULL,PERIOD_M5,1)-ov;
   
   if(iClose(NULL,PERIOD_M5,1)==nv)
      return(true);
   
   return(false);
} 

Your math is "faulty" ...

ov = high - close
nv = close - ov = close - high + close = 2 * close - high
close == nv == 2 * close - high == high

Simplifying and taking into account floating point adjustments ...

bool M5LTPrevM5()
{
   double
      dbHighM5  = iHigh(  _Symbol, PERIOD_M5, 1 ),
      dbCloseM5 = iClose( _Symbol, PERIOD_M5, 1 );

   return !( dbCloseM5 < dbHighM5 );
};
 
Paul #:

 try this

Paul 

double ToDayHigh=iHigh(_Symbol,PERIOD_D1,0);
double YesterDayLow=iLow(_Symbol,PERIOD_D1,1);

Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

  1. They are initialized once on program load.

  2. They don't update unless you assign to them.

  3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

    MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and

    Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    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. Now TickValue, TimeCurrent, account information and prices are valid.

  4. Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
              external static variable - MQL4 programming forum #2 (2013)

 
Fernando Carreiro #:

Your math is "faulty" ...

Simplifying and taking into account floating point adjustments ...

working swiftly. thanks a lot for your help

may I apply same for Buy too? (can i apply iLow instead of iHigh to get M5GTPrevM5?? )

Reason: