当前位置:网站首页>Mt4/mql4 getting started to mastering EA tutorial lesson 3 - common functions of MQL language (III) - common functions of K-line value taking

Mt4/mql4 getting started to mastering EA tutorial lesson 3 - common functions of MQL language (III) - common functions of K-line value taking

2022-06-22 08:01:00 EA development - green shirt code customer

double iOpen();

double  iOpen( 
   string           symbol,     //  Trade variety  
   int              timeframe,  //  cycle  
   int              shift       // K Line post  
   );

iOpen() The function has three arguments ,symbol、timeframe、shift

The function returns a root of a specified period of a specific transaction type K Line post Opening price

double iClose();

double  iClose( 
   string           symbol,          //  Trade variety  
   int              timeframe,       //  cycle  
   int              shift            // K Line post  
   );

iClose() The function has three arguments ,symbol、timeframe、shift

The function returns a root of a specified period of a specific transaction type K Line post Closing price

double iLow();

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

iLow() The function has three arguments ,symbol、timeframe、shift

The function returns a root of a specified period of a specific transaction type K Line post The lowest price

double iHigh();


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

iHigh() The function has three arguments ,symbol、timeframe、shift

The function returns a root of a specified period of a specific transaction type K Line post Highest price

datetime iTime();

datetime  iTime( 
   string           symbol,          // symbol 
   int              timeframe,       // timeframe 
   int              shift            // shift 
   );

iTime() The function has three arguments ,symbol、timeframe、shift

The function returns a root of a specified period of a specific transaction type K Line post Time

long iVolume();

long  iVolume( 
   string           symbol,          // symbol 
   int              timeframe,       // timeframe 
   int              shift            // shift 
   );

iVolume() The function has three arguments ,symbol、timeframe、shift

The function returns a root of a specified period of a specific transaction type K Line post volume

The script instance


//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart() 
  {
     
   double open=iOpen("USDCHF",PERIOD_H1,0);    // return K The opening price of the string column 
   double close=iClose("USDCHF",PERIOD_H1,0);   // return K The closing price of the string column 
   double low=iLow("USDCHF",PERIOD_H1,0);     // return K The lowest price of the line post 
   double high=iHigh("USDCHF",PERIOD_H1,0);    // return K The highest price of the line post 
   datetime time=iTime("USDCHF",PERIOD_H1,0);    // return K Time of line post 
   long volume=iVolume("USDCHF",PERIOD_H1,0);  // return K Trading volume of the line column 
   
   Print("Current bar for USDCHF H1 open: ",open);
   Print("Current bar for USDCHF H1 close: ",close);
   Print("Current bar for USDCHF H1 low: ",low);
   Print("Current bar for USDCHF H1 high: ",high);
   Print("Current bar for USDCHF H1 time: ",time);
   Print("Current bar for USDCHF H1 volume: ",volume); 
  
  }

The code function is Log print out USDCHF The current of the one hour period K The opening price of the string column 、 Closing price 、 The lowest price 、 Highest price 、 Time 、 volume .

Parameter details

(“USDCHF”,PERIOD_H1,0)

“USDCHF”, Trade variety
PERIOD_H1, The time period is one hour
0 , At present K Line post

 The results show that all the data are 0, That is to say, no data is read , The reason is that there is no open... In the chart window USDCHF Chart , So no data can be read .
The results show that all the data are 0, That is to say, no data is read , The reason is that there is no open... In the chart window USDCHF Chart , So no data can be read .

Now open it casually USDCHF A chart of a cycle , Open one USDCHF5 Minute cycle chart .

 Insert picture description here
You can see in the log that USDCHF A set of data

Then verify the correctness of the data , Switch back to the USDCHF One hour chart , Click on the data window to view
 Insert picture description here
You can see Low、Close、Volume The data in the log is Not the same .

Why? ???

Because I read the current K Line column data except Open Other data are still Fluctuating .

Of course , Procedures need to be rigorous , No mistake is allowed .

Now change the parameters , Read the previous one K Line column data

//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart() 
  {
     
   double open=iOpen("USDCHF",PERIOD_H1,1);    // return K The opening price of the string column 
   double close=iClose("USDCHF",PERIOD_H1,1);   // return K The closing price of the string column 
   double low=iLow("USDCHF",PERIOD_H1,1);     // return K The lowest price of the line post 
   double high=iHigh("USDCHF",PERIOD_H1,1);    // return K The highest price of the line post 
   datetime time=iTime("USDCHF",PERIOD_H1,1);    // return K Time of line post 
   long volume=iVolume("USDCHF",PERIOD_H1,1);  // return K Trading volume of the line column 
    
   Print("Current bar for USDCHF H1 open: ",open);
   Print("Current bar for USDCHF H1 close: ",close);
   Print("Current bar for USDCHF H1 low: ",low);
   Print("Current bar for USDCHF H1 high: ",high);
   Print("Current bar for USDCHF H1 time: ",time);
   Print("Current bar for USDCHF H1 volume: ",volume); 
  }

Just put the parameters 0 Change to 1.

0 On behalf of the current K Line post , In turn forward K The parameters of the line column are 1、2、3·······

Continue to execute the script

 Insert picture description here
Printed out a set of data

Data window to verify

 Insert picture description here
All data are correct , The explanation is correct .

A good workman does his work well , You must sharpen your tools first , The most important thing in trading is to follow the rules , Strictly carry out . Official account , Study MQL Beginner to master EA course , Learn more EA Programming , Write your own EA, Forge your own magic weapon .

 Insert picture description here

原网站

版权声明
本文为[EA development - green shirt code customer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220530131196.html