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

智能交易系统 DUMMYEA-HZH均线通道1 EA



DUMMYEA-HZH均线通道1 EA根据均线通道在交易。

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

//+------------------------------------------------------------------+
//|                                         DUMMYEA-HZH均线通道1.mq4 |
//|                       Copyright @2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright @2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern int LotsPersent = 10; //定义下单占保证金的百分比
extern int Slippage = 3;
extern int MagicNumber = 24680;
extern int MA1 = 13;
extern int MA2 = 34;

int Ticket;
int LineTime;
bool OrderOpen=false;

int jczq=0;
int sczq=0;
double tdup;//通道上轨
double tdlow;//通道下轨

int init()
  {
   ObjectCreate("comment_label", OBJ_LABEL, 0, 0, 0);
   ObjectSet("comment_label", OBJPROP_XDISTANCE, 50);
   ObjectSet("comment_label", OBJPROP_YDISTANCE, 20);
   ObjectSetText("comment_label", "DUMMYEA-HZH均线通道1", 20, "Arial", Yellow);
   return(0);
  }

int deinit()
  {
   ObjectDelete("comment_label");
   Comment("www.125808047.com");
   return(0);
  }


int start()
  {
//----
      double MA10=iMA(NULL,0,MA1,0,MODE_SMA,PRICE_CLOSE,0);
      double MA11=iMA(NULL,0,MA1,0,MODE_SMA,PRICE_CLOSE,1);
      double MA20=iMA(NULL,0,MA2,0,MODE_SMA,PRICE_CLOSE,0);
      double MA21=iMA(NULL,0,MA2,0,MODE_SMA,PRICE_CLOSE,1);
      
      double Lots = NormalizeDouble(AccountFreeMargin() / 1000.0 * (LotsPersent / 100.0),1); // 定义仓位大小
      
      if (Time[0] != LineTime) {LineTime = Time[0]; OrderOpen = false; jczq++; sczq++;}
      
      if(MA11<MA21&&MA10>MA20) CloseAllWinSell(); //金叉平盈利空仓
      if(MA11>MA21&&MA10<MA20) CloseAllWinBuy(); //死叉平盈利多仓
      
      int HoldingBuy = 0;   // 计算买单数量
      int HoldingSell = 0;   // 计算卖单数量
      if( OrdersTotal() != 0) {
         for (int i = 0; i < OrdersTotal(); i++) {
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType() == OP_BUY)HoldingBuy++;
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderType() == OP_SELL)HoldingSell++;
         }
      }
      
      if(MA11<MA21&&MA10>MA20 && HoldingBuy==0 && OrderOpen==false){
             Ticket=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask, Digits),Slippage,0,0,"dummy-buy",MagicNumber,0,Red);
             if(Ticket>0){
                    if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)){
                       OrderOpen=true;
                       jczq=0;
                       if(HoldingSell>0){
                           tdup=High[iHighest(NULL,0,MODE_HIGH,sczq,0)];  //计算通道上轨
                           tdlow=Low[iLowest(NULL,0,MODE_LOW,sczq,0)];   //计算通道下轨
                       }
                    }
                    else{
                       Print("Error opening Pivot dummy-buy order : ",GetLastError());
                       return(0);
                    }
                 }
             
        }else
        if(MA11>MA21&&MA10<MA20 && HoldingSell==0 && OrderOpen==false){
             Ticket=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid, Digits),Slippage,0,0,"dummy-sell",MagicNumber,0,Blue);
             if(Ticket>0){
                    if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)){
                       OrderOpen=true;
                       sczq=0;
                       if(HoldingBuy>0){
                           tdup=High[iHighest(NULL,0,MODE_HIGH,jczq,0)];
                           tdlow=Low[iLowest(NULL,0,MODE_LOW,jczq,0)];
                       }
                    }
                    else{
                       Print("Error opening Pivot dummy-sell order : ",GetLastError());
                       return(0);
                    }
              }
        }
        
        if(Close[0]>tdup && HoldingBuy>0 && HoldingSell>0)CloseAllSell(); //突破通道上轨平空仓
        if(Close[0]<tdlow && HoldingBuy>0 && HoldingSell>0)CloseAllBuy(); //突破通道下轨平多仓
   
//----
   return(0);
  }
//+------------------------------------------------------------------+


void CloseAllSell()
{
   bool CAS = FALSE;
   for (int t=0; t<OrdersTotal(); t++)
   {
      OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber )
      CAS = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(), Digits), Slippage, Yellow);
   }
}


void CloseAllBuy() 
{
   bool CAB = FALSE;
   for (int t=0; t<OrdersTotal(); t++) 
   {
      OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber)
      CAB = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(), Digits), Slippage, Yellow);
   }
}


void CloseAllWinSell() 
{
   bool CAWS = FALSE;
   for (int t=0; t<OrdersTotal(); t++) 
   {
      OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber && OrderProfit() > 0.0 )
      CAWS = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(), Digits), Slippage, Yellow);
   }
}

void CloseAllWinBuy() 
{
   bool CAWB = FALSE;
   for (int t=0; t<OrdersTotal(); t++)
   {
      OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber && OrderProfit() > 0.0)
      CAWB = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(), Digits), Slippage, Yellow);
   }
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 智能交易系统 DUMMYEA-HZH均线通道1 EA
上一篇:
下一篇:
分享到:更多 ()