当前位置:网站首页>Mt4/mql4 getting started to proficient in foreign exchange EA automatic trading tutorial - identify the emergence of the new K line

Mt4/mql4 getting started to proficient in foreign exchange EA automatic trading tutorial - identify the emergence of the new K line

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

Identify new K The appearance of lines in EA It is a very important function in the program ,K The line is the entire trading market , The main basis for trend judgment . Identify and analyze K The meaning of the line is also the basis of the transaction .

Custom method

datetime timelast,timenow;
bool isNewK(){
bool isnewk=false;
timenow=Time[0];
if(timenow!=timelast){
timelast=Time[0];
isnewk=true;
}
else isnewk=false;
return isnewk;
}

EA example :

//+------------------------------------------------------------------+
//| NewK.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
​
datetime timelast,timenow;//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
    
//--- create timer
   timelast=Time[0];
   timenow=Time[0];
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    
//--- destroy timer
  
   
  }
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
    
//---
   if(isNewK())printf(" new K The line appears !");
  }
  
bool isNewK(){
    
   bool isnewk=false;
   timenow=Time[0];
   if(timenow!=timelast){
    
      timelast=Time[0];
      isnewk=true;
   }
   else isnewk=false;
   return isnewk;
 }

​ Execution effect :

The execution effect after loading the one minute cycle chart : new K Print once when lines appear : new K The line appears !

 Insert picture description here
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/202202220530130868.html