请观看如何免费下载自动交易
请在Telegram上找到我们!
加入我们粉丝页
有趣的脚本?
因此发布一个链接 -
让其他人评价
喜欢这个脚本? 在MetaTrader 5客户端尝试它
EA

稳健的外表 - MetaTrader 4EA

张庆
发布者:
Qing Zhang
显示:
11737
等级:
(2)
已发布:
2018.11.12 14:11
已更新:
2018.11.19 13:07
myea.mq4 (28.02 KB) 预览
需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务

请一定要修改代码删除/*  */符号及*/后面部分再运行,由于本系统平仓功能有问题实际测试不能正常平仓,本人非专业程序员能力有限无法解决是借壳发布的希望专业人士修改特来分享(见笑)本策略简单就是价格上破下破入场重点在资金管理。

If you still don't know, copy the following code directly.

还是不清楚就直接复制下面代码吧


//+------------------------------------------------------------------+
//|                                                         myea.mq4 |
//|                                                  Copyright peace |
//|                                                1006672928@qq.com |
//+------------------------------------------------------------------+
//#property copyright "peace"
//#property link      "1006672928@qq.com"
//#property version   "1.00"
//#property strict
#include <stdlib.mqh>
#include <stderror.mqh>

extern int    MAGICMA            = 1688;

extern double Lots               = 0.1;
extern double multiplerate               = 2.0;
extern double maxlots             = 2; 
extern int    orderquantity           = 6;
extern double guaranteedbottomincome=5;
extern bool   SndMl              = false;
datetime SellTime,BuyTime;

//---------------------------------------------------------------------------  
   double currentlyorderlots()
     {
        double lots=0.0;
        if(OrdersTotal()>0)
           {
              for(int i=0;i<OrdersTotal();i++)
                {
                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
                     {
                         if(OrderSymbol()==Symbol())
                           {
                              if(OrderMagicNumber()==MAGICMA) 
                                {
                                   if(OrderLots()!=0)
                                     {
                                        lots=lots+OrderLots();
                                     }
                                   else
                                     {
                                        lots=lots;
                                     }
                                }
                          }
                    }
               }
           }
    else
      {
        return(0);
      }
    return(lots);
      }

//---------------------------------------------------------------------------  
   double currentlyprofit()
     {
        double profit=0.0;
        if(OrdersTotal()>0)
           {
              for(int i=0;i<OrdersTotal();i++)
                {
                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
                     {
                         if(OrderSymbol()==Symbol())
                           {
                              if(OrderMagicNumber()==MAGICMA) 
                                {
                                   if(OrderProfit()!=0)
                                     {
                                        profit=profit+OrderProfit()+OrderCommission()+OrderSwap();
                                     }
                                   else
                                     {
                                        profit=profit;
                                     }
                                }
                          }
                    }
               }
           }
    else
      {
        return(0);
      }
    return(profit);
      }
      
//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   return(buys+sells);
  }

//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
double BuyOrders(string symbol)
  {
   double buys=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys=buys+OrderLots();
        }
     }
     return(buys);
  }
  
//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
double SellOrders(string symbol)
  {
   double sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_SELL) sells=sells+OrderLots();
        }
     }
     return(sells);
  }
  
//---------------------------------------------------------------------------  
   double getlots()
     {
        double lotsok=Lots;
        if(OrdersTotal()>0)
           {
              int i=OrdersTotal()-1;
                {
                   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
                     {
                         if(OrderSymbol()==Symbol())
                           {
                              if(OrderMagicNumber()==MAGICMA) 
                                {
                                   if(currentlyprofit()>=0)
                                     {
                                        lotsok=Lots;
                                     }
                                   else
                                     {
                                       lotsok=DoubleToStr(NormalizeDouble(OrderLots()*multiplerate,1),1);
                                       if(lotsok>maxlots)
                                          {
                                             lotsok=maxlots;
                                          }
                                        //break;
                                     }
                                   //break;
                                }
                          }
                    }
               }
           }
    else
      {
        return(Lots);
      }
    return(lotsok);
      }
      
//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
void CheckForOpen()
  {

   int    res;
   string sHeaderLetter;
   string sBodyLetter;
//---- 
   if(Close[0]<Low[1]&&SellTime!=Time[0]&&(SellOrders(Symbol())<BuyOrders(Symbol())||currentlyorderlots()==0))  
     {
      res=OrderSend(Symbol(),OP_SELL,getlots(),Bid,3,0,0,"",MAGICMA,0,Red);
      SellTime=Time[0];BuyTime=Time[1];
       if (SndMl == True && res != -1) 
         {
         sHeaderLetter = "Operation SELL by" + Symbol()+"";
         sBodyLetter = "Order Sell by"+ Symbol() + " at " + DoubleToStr(Bid,4)+ ", and set stop/loss at " + DoubleToStr(0,4)+"";
         sndMessage(sHeaderLetter, sBodyLetter);
         }
      return;
     }
//---- 
   if(Close[0]>High[1]&&BuyTime!=Time[0]&&(BuyOrders(Symbol())<SellOrders(Symbol())||currentlyorderlots()==0))  
     {
      res=OrderSend(Symbol(),OP_BUY,getlots(),Ask,3,0,0,"",MAGICMA,0,Blue);
      BuyTime=Time[0];SellTime=Time[1];
      if ( SndMl == True && res != -1)
      { 
      sHeaderLetter = "Operation BUY at" + Symbol()+"";
      sBodyLetter = "Order Buy at"+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and set stop/loss at " + DoubleToStr(0,4)+"";
      sndMessage(sHeaderLetter, sBodyLetter);
      }
      return;
     }
//----
  }
//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
void CheckForClose()
  {
   string sHeaderLetter;
   string sBodyLetter;
   bool rtvl;
   //----  
   if (currentlyorderlots()>Lots&&currentlyprofit()>=guaranteedbottomincome)
      {rtvl=breakorderstotalclose();}
//----  
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      if(OrderType()==OP_BUY)
        {
         if(Close[0]<Low[1]&&currentlyprofit()>=0){rtvl=OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);}
            if ( SndMl == True && rtvl != False )
            {
            sHeaderLetter = "Operation CLOSE BUY at" + Symbol()+"";
            sBodyLetter = "Close order Buy at"+ Symbol() + " for " + DoubleToStr(Bid,4)+ ", and finish this Trade";
            sndMessage(sHeaderLetter, sBodyLetter);
            }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Close[0]>High[1]&&currentlyprofit()>=0){rtvl=OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);}
         if ( SndMl == True && rtvl != False ) 
         {
         sHeaderLetter = "Operation CLOSE SELL at" + Symbol()+"";
         sBodyLetter = "Close order Sell at"+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and finish this Trade";
         sndMessage(sHeaderLetter, sBodyLetter);
         }
         break;
        }
     }
//----
  }
  
//------------------ 部分平仓 -------------------
//====================================================================
bool breakorderstotalclose()
  {
  bool rtvl;
  for (int i=OrdersTotal();i>=0; i--)
    {
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
      {
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      if(OrderType()==OP_BUY&&OrderMagicNumber()==MAGICMA)
        {rtvl=OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);}
      if(OrderType()==OP_SELL&&OrderMagicNumber()==MAGICMA)
        {rtvl=OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);}
      }
    }
  return(rtvl);
  }
  
//--------------------------------------------------------------------
// 
//--------------------------------------------------------------------
void sndMessage(string HeaderLetter, string BodyLetter)
{
   int RetVal;
   SendMail( HeaderLetter, BodyLetter );
   RetVal = GetLastError();
   if (RetVal!= ERR_NO_MQLERROR) Print ("平仓失败: ", ErrorDescription(RetVal));
}
//+------------------------------------------------------------------+
//|                                                      
//+------------------------------------------------------------------+
void start()
  {
    
       Comment("","\n",
            "交易品种 : "+ChartSymbol(0),"\n",
            "","\n",
            "图表周期 : ", _Period,"分钟", "\n",
            "","\n",
            "当前订单总量 : ", currentlyorderlots()," 手", "\n",
            "","\n",
            "当前多单总量 : ", BuyOrders(Symbol()),"  手", "\n",
            "","\n",
            "当前空单总量 : ", SellOrders(Symbol())," 手", "\n",
            "","\n",
            "当前订单总数 : ", CalculateCurrentOrders(Symbol())," 张", "\n",
            "","\n",
            "当前订单总盈亏 : ", currentlyprofit(),"   $", "\n",
            "","\n",
            "下个订单交易量 :  ", getlots()," 手","\n",
            "","\n"
           );
//---- check for history and trading
   if(Bars<25 || IsTradeAllowed()==false) return;
//----
   if(CalculateCurrentOrders(Symbol())>0){CheckForClose();}
   
   if(CalculateCurrentOrders(Symbol())<orderquantity){CheckForOpen();}
//----
  }
//+------------------------------------------------------------------+


Reverse No Repair Reverse No Repair

The Reverse No Repair indicator shows bullish arrow and bearish arrow.

KeyboardTrade KeyboardTrade

纯键盘下单交易工具, 通过键盘输入指令操作订单. 可以用于复盘/历史回测时手动下单, 也用在实盘交易.

剥头皮 剥头皮

这是一个根据均线趋势为指引的剥头皮EA。提供参考学习,不建议用于实盘。

MT4 One Key Trading MT4 One Key Trading

MT4 One Key Trader:一键交易,双击脚本即可自动完成:买入,卖出,平仓,删除挂单,删除物体。