Getting Previous Day High and Low on Hour and minute timeframe

 

HI There


I would like to know how to get the Previous days high and low when trading on lowwer time frames.


Thanks

 

iHigh function:

Returns High price value for the bar of specified symbol with timeframe and shift.

double  iHigh( 
   string           symbol,          // symbol 
   int              timeframe,       // timeframe 
   int              shift            // shift 
   );

Parameters

symbol

[in]  Symbol name. NULL means the current symbol.

timeframe

[in]  Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.

shift

[in]  Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Returned value

High value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.

Note

For the current chart, the information about high prices is in the High[] predefined array.

Example:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                      iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                      iClose("USDCHF",PERIOD_H1,0),", "iVolume("USDCHF",PERIOD_H1,0));

 


iLow function:

Returns Low price value for the bar of indicated symbol with timeframe and shift.

double  iLow( 
   string           symbol,          // symbol 
   int              timeframe,       // timeframe 
   int              shift            // shift 
   );

Parameters

symbol

[in]  Symbol name. NULL means the current symbol.

timeframe

[in]  Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.

shift

[in]  Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Returned value

Low price value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.

Note

For the current chart, the information about low prices is in the Low[] predefined array.

Example:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,0),", ",  iOpen("USDCHF",PERIOD_H1,0),", ",
                                      iHigh("USDCHF",PERIOD_H1,0),", ",  iLow("USDCHF",PERIOD_H1,0),", ",
                                      iClose("USDCHF",PERIOD_H1,0),", "iVolume("USDCHF",PERIOD_H1,0));

 


 
  1. Mohammad Soubra:

    iHigh function:

    Returns High price value for the bar of specified symbol with timeframe and shift.

    There is no such function in MT5.
              List of MQL5 Functions - Reference on algorithmic/automated trading language for MetaTrader 5

  2. StantonR: I would like to know how to get the Previous days high and low when trading on lowwer time frames.
    Just get the high using the D1, but remember on MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thanks for the replies.

Went with this solution


MqlRates PriceDataTableDaily[];  

ArraySetAsSeries(PriceDataTableDaily,true);

CopyRates(_Symbol,PERIOD_D1,0,1,PriceDataTableDaily); 

PriceDataTableDaily[1].high
PriceDataTableDaily[1].low
PriceDataTableDaily[1].close

 
StantonR:

Thanks for the replies.

Went with this solution



You're going to get an array out of range error calling for the second element in an array size of 1. Also, there's no need to set the array as series when it only has one element. 

MqlRates PriceDataTableDaily[];  
CopyRates(_Symbol,PERIOD_D1,0,1,PriceDataTableDaily); 

PriceDataTableDaily[0].high
PriceDataTableDaily[0].low
PriceDataTableDaily[0].close
 

try this



Files:
High_low..ex4  13 kb
 
Samuel Akinbowale: try this
int BarShift(int cur_i){return(iBarShift(Symbol(),TimeFrame,Time[cur_i],false));} 
double high(int cur_i){return(iHigh(Symbol(),TimeFrame,BarShift(cur_i)));}
double low(int cur_i){return(iLow(Symbol(),TimeFrame,BarShift(cur_i)));}  

No such functions in MT5. Why did you post your MT4 solution when this post is in the Root / MT5 Systems section not in the MQL4 section, (bottom of the Root page?)
          General rules and best pratices of the Forum. - General - MQL5 programming forum

Reason: