有您的持续关注
我们会做得更好

根据Volume设计的智能交易系统 Volume_trader_v2 EA



Volume_trader_v2 EA是根据指定时间段的Volume值增加还是缩小来交易的超短EA。在语法方面精悍简短。值得拓展借鉴。

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。Volume_trader_v2 EA源码如下:

//+------------------------------------------------------------------+
//|                                             Volume_trader_v2.mq4 |
//|                                     Copyright 2014, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"

#include <stdlib.mqh>

#define MySuperMagic 111020051110
extern int StartHour = 8;
extern int EndHour   = 20;
extern double Lots  = 0.1;


double LastBarChecked;

int init()
  {
//---- 
  LastBarChecked = Time[0]; 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }




//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   string cm = "Volume ";
   if (Period() == 1) cm = cm + "1M";
   if (Period() == 5) cm = cm + "5M";
   if (Period() == 15) cm = cm + "15M";
   if (Period() == 30) cm = cm + "30M";
   if (Period() == 60) cm = cm + "1H";
   if (Period() == 240) cm = cm + "4H";
   if (Period() == 1440) cm = cm + "1D";
   if (Period() == 10080) cm = cm + "1W";
   if (Period() == 43200) cm = cm + "1M";
   cm = cm + " - ";
   cm = cm + TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS); 
   int EAMagic = MySuperMagic + Period();
   //------------------------------------------------------------------------------------------------ 
   bool doShort = false;
   bool doLong  = false;
   
   bool hourValid = (Hour() >= StartHour) && (Hour() <= EndHour);
   if ( (Volume[1] < Volume[2]) && hourValid ) 
   {
      doLong = true;
      Comment("Up trend");
   }
   if ( (Volume[1] > Volume[2]) && hourValid ) 
   {
      doShort = true;
      Comment("Down trend");
   }
   if ( Volume[1] == Volume[2] )
   {
      Comment("No trend...");
   }
   if(LastBarChecked != Time[0])
   {
      int cnt = 0;
      while (cnt<OrdersTotal()) 
      {
         if ( OrderSelect (cnt, SELECT_BY_POS) == false )  continue;
         if ( OrderSymbol()==Symbol() && OrderMagicNumber()==EAMagic)
         {
            int ticket = OrderTicket();
            double oLots = OrderLots(); 
            double priceClose;
            if (OrderType() == OP_BUY)
            {
                 priceClose = Bid;
                 if ( doLong ) 
                 {
                      LastBarChecked = Time[0];
                      return(0);
                 }
            }
            else
            {
                 priceClose = Ask; 
                 if ( doShort ) 
                 {
                      LastBarChecked = Time[0];
                      return(0);
                 }                 
            }
            if(!OrderClose(ticket,oLots,priceClose,7,Red))
            {
               Alert("Error closing trade: " + ErrorDescription(GetLastError()));                
               return(0);
            }
         }
         else
         {
            cnt ++;
         }
      }

      if (hourValid)
      {
         if ( Volume[1] < Volume[2] ) 
         {
         bool cg = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,cm,EAMagic,0,White);     
         }
         if ( Volume[1] > Volume[2] )
         {
         cg = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,cm,EAMagic,0,Red);
         }      
      }
      LastBarChecked = Time[0];
   }
   return(0);
  }
//+------------------------------------------------------------------+
如您喜欢此文章请点下面分享按钮↴峰汇在线 » 根据Volume设计的智能交易系统 Volume_trader_v2 EA
上一篇:
下一篇:
分享到:更多 ()