Download MetaTrader 5

need help: how to get PRICE_HIGH

To add comments, please log in or register
yoshi1988
30
yoshi1988  

Hello

I am trying to get Price_High everytick. I want to output Price High to Control Log.

My OnTick() function outputs string, "Hello" everytick.

How do i output Price High everytick?

 Actually my final purpose is to get histgram of price difference, PRICE_OPEN - PRICE_CLOSE, monday to friday. Therefore, outputted data will be pasted into excel and utilized for histgram calculation.

  

Yoshi 

 

//+------------------------------------------------------------------+
void OnTick()
  {
      //printf("Price_Close: " + (string)PRICE_CLOSE);
  // MqlRates bar_info[];
   printf("hello");
  // printf("bar price: " + (string)bar_info[0].open);
   
  }

 log

Alain Verleyen
Moderator
31183
Alain Verleyen  
Jian Chen
Moderator
3650
Jian Chen  
yoshi1988:


 Actually my final purpose is to get histgram of price difference, PRICE_OPEN - PRICE_CLOSE, monday to friday. Therefore, outputted data will be pasted into excel and utilized for histgram calculation.


You may have a look at the online doc and example code of "CopyRates".

BTW, if you only need the HLOC data, a script program is more suitable for that purpose than an EA.  The example code of "CopyRates" is just a script and you may customize it.

yoshi1988
30
yoshi1988  

Hello

Thanks you very much for comment.

However, I have a problem that output of sample code is not what i expect.

I have tried sample code of CopyHigh as  angevoyageur  has implied.

I receive an identical values of Highest and Lowest while output is supposed to give distinct Highest and Lowest of tick.  

Why is that?

Below, code and output are posted.

 

Thank you 

#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
 
#property description "An example for output of the High[i] and Low[i]"
#property description "for a random chosen bars"
 
double High[],Low[];
//+------------------------------------------------------------------+
//| Get Low for specified bar index                                  |
//+------------------------------------------------------------------+
double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double low=0;
   ArraySetAsSeries(Low,true);
   int copied=CopyLow(symbol,timeframe,0,Bars(symbol,timeframe),Low);
   if(copied>0 && index<copied) low=Low[index];
   return(low);
  }
//+------------------------------------------------------------------+
//| Get the High for specified bar index                             |
//+------------------------------------------------------------------+
double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double high=0;
   ArraySetAsSeries(High,true);
   int copied=CopyHigh(symbol,timeframe,0,Bars(symbol,timeframe),High);
   if(copied>0 && index<copied) high=High[index];
   return(high);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- on every tick we output the High and Low values for the bar with index,
//--- that is equal to the second, on which tick arrived
   datetime t=TimeCurrent();
   int sec=t%60;
   printf("High[%d] = %G  Low[%d] = %G",
          sec,iHigh(Symbol(),0,sec),
          sec,iLow(Symbol(),0,sec));
  }

 same_value

To add comments, please log in or register