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

智能交易系统 God bless EA



God bless EA根据MACD信号在交易。

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

//+------------------------------------------------------------------+
//|                                                    God bless.mq4 |
//|                      Copyright @2011, QQ360737395 Software Corp. |
//|                                             http://www.fx988.cn/ |
//+------------------------------------------------------------------+
#property copyright "Copyright @2011, QQ360737395 Software Corp."
#property link      "http://www.fx988.cn/"

extern string IIIIIIIIIIII1 = "<<<<<<<<<  EA Setting >>>>>>>>";
extern double        Lots = 0.1;
extern double        StopLoss = 0;
extern double        TakeProfit = 0;
extern int           MaxBuyOrders = 2;
extern int           MaxSellOrders = 2;
extern int           BeComing = 1;
extern string IIIIIIIIIIII2 = "<<<<<<<<<  MACD Setting >>>>>>>>";
extern int           FastEMA = 12;
extern int           SlowEMA = 26;
extern int           SignalSMA = 9;
extern string IIIIIIIIIIII6 = "<<<<<<<<<  TrailingStop Setting >>>>>>>>";
extern bool          TrailingStop = true;
extern int           TrailingProfit = 100;
extern int           TrailingPoint1 = 50;
extern int           TrailingPoint2 = 30;
extern string IIIIIIIIIIII7 = "<<<<<<<<<  OrderMagic Setting >>>>>>>>";
extern int           Magic1 = 8888281;
extern int           Magic2 = 8888282;
extern int           Magic3 = 8888283;
extern int           Magic4 = 8888284;
extern string IIIIIIIIIIII8 = "<<<<<<<<<  End Setting >>>>>>>>";
int                  Bit=1;
int                  TradesSlippage = 3,CloseSlippage=3;
datetime             BuyTime,SellTime;
bool cg = false;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    Comment("www.125808047.com");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   ScreenMsg();
   if(TrailingStop)TrailingStop();
   double KDJ_MAIN = iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,BeComing+0);
   double KDJ_MAIN1 = iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,BeComing+1);
   double KDJ_SIGNAL = iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,BeComing+0);
   double KDJ_SIGNAL1 = iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,BeComing+1);
   
            if(KDJ_MAIN>KDJ_SIGNAL&&KDJ_MAIN1<KDJ_SIGNAL1&&BuyTime!=Time[0])
            {
               if(GetOrders(Magic1)>=MaxBuyOrders){
               //Print("多单开单数量已满!");
               return (0);
               }
               if(OpenBuy(Lots,OP_BUY,Magic1))
               {
                  Alert("买单:MACD出现金叉!已完成开多单的操作!");
                  BuyTime=Time[0];         
               }
            }
            if(KDJ_MAIN<KDJ_SIGNAL&&KDJ_MAIN1>KDJ_SIGNAL1&&SellTime!=Time[0])
            {
               if(GetOrders(Magic2)>=MaxSellOrders){
               //Print("空单开单数量已满!");
               return (0);
               }
               if(OpenSell(Lots,OP_SELL,Magic2))
               {
                  Alert("卖单:MACD出现死叉!已完成开空单的操作!");
                  SellTime=Time[0];
               }
            }
//----
   return(0);
  }
//+------------------------------------------------------------------+

void ScreenMsg(){
      Comment("\n", "    Copyright ?2010, QQ 360737395 right ?????", 
      "\n", "    ======================================", 
      "\n", "     Broker Time       : ", TimeToStr(TimeCurrent()), 
      "Server Time:        " + TimeToStr(TimeCurrent(), TIME_SECONDS),
      "\n", "     Current Price ->  Bid :  ", Bid, "   Ask :  ", Ask, 
      "\n", 
      "\n", "     Balance                : ", AccountBalance(), 
      "\n", "     Equity                 : ", AccountEquity(), 
      "\n", "     Orders Total         : ", OrdersTotal(), 
      "\n", "     Total Profit/Loss    : ", AccountProfit(), 
      "\n");
      if(Digits==5)Bit=10;
}
bool OpenBuy(double ldLots,int Type,int Magic){
   int ticket;
   Print("正在执行买仓中。。。。。。");
   ticket = OrderSend(Symbol(),Type,ldLots,Ask,TradesSlippage,0,0, "Buy(#" + Magic + ")",Magic,0,Red);  
   if (ticket > 0){
      if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)){
         Print("BUY order opened : ", cg = OrderOpenPrice());
         if(StopLoss!=0&&TakeProfit!=0)cg = OrderModify(OrderTicket(),0,OrderOpenPrice()-StopLoss*Point*Bit,OrderOpenPrice()+TakeProfit*Point*Bit,0,Red);
         if(StopLoss==0&&TakeProfit!=0)cg = OrderModify(OrderTicket(),0,0,OrderOpenPrice()+TakeProfit*Point*Bit,0,Red);
         if(StopLoss!=0&&TakeProfit==0)cg = OrderModify(OrderTicket(),0,OrderOpenPrice()-StopLoss*Point*Bit,0,0,Red);
         }
   }else{
      Print("Error opening BUY order : ", GetLastError());
      return (False);
   }
   return (True);
}

bool OpenSell(double ldLots,int Type,int Magic)
{
   int ticket;
   Print("正在执行卖仓中。。。。。。");
   ticket=OrderSend(Symbol(),Type,ldLots,Bid,TradesSlippage,0,0, "SELL(#" + Magic + ")",Magic,0,Green);  
   if (ticket > 0){
      if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)){
         Print("SELL order opened : ", cg = OrderOpenPrice());
         if(StopLoss!=0&&TakeProfit!=0)cg = OrderModify(OrderTicket(),0,Bid+StopLoss*Point*Bit,Bid-TakeProfit*Point*Bit,0,Green);
         if(StopLoss==0&&TakeProfit!=0)cg = OrderModify(OrderTicket(),0,0,Bid-TakeProfit*Point*Bit,0,Green);
         if(StopLoss!=0&&TakeProfit==0)cg = OrderModify(OrderTicket(),0,Bid+StopLoss*Point*Bit,0,0,Green);
         }
   }else{
      Print("Error opening SELL order : ", GetLastError());
      return (False);
   }
   return (True);
}
int GetOrders(int magic_number)
{
   int total = OrdersTotal();
   int s=0;
   for (int i = total - 1; i >= 0; i--) {
      if (OrderSelect(i, SELECT_BY_POS) == TRUE)
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic_number && (OrderType()==OP_SELL||OrderType()==OP_BUY))s++;
   }
   return (s);
}

void TrailingStop()
{
   
   double NewStop;
   int Total = OrdersTotal();
   for (int i = 0; i < Total; i++) {
  cg = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() == OP_BUY && OrderSymbol() == Symbol()&& (OrderMagicNumber()==Magic1||OrderMagicNumber()==Magic2)) {
            Print("11");
            if(MathFloor((Bid-OrderOpenPrice())/(Point*Bit)) < TrailingProfit){
            
            NewStop = NormalizeDouble(Bid-TrailingPoint1*Point*Bit,Digits);
            if(OrderStopLoss() < NewStop){
            if(OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), 0, MediumSeaGreen))
               Print("进入BUY移动止损:Buy 盈利:",MathFloor((Bid-OrderOpenPrice())/(Point*Bit))," 点,订单开盘价:",OrderOpenPrice(),"现在买价:",Bid," 当前止损价:",NewStop);
            }
            }
            if(MathFloor((Bid-OrderOpenPrice())/(Point*Bit)) >= TrailingProfit){
            NewStop = NormalizeDouble(Bid-TrailingPoint2*Point*Bit,Digits);
            if(OrderStopLoss() < NewStop){
            if(OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), 0, MediumSeaGreen))
               Print("进入BUY移动止损:Buy 盈利:",MathFloor((Bid-OrderOpenPrice())/(Point*Bit))," 点,订单开盘价:",OrderOpenPrice(),"现在买价:",Bid," 当前止损价:",NewStop);
            }
            }
            
            
         } else if(OrderType() == OP_SELL && OrderSymbol() == Symbol()&& (OrderMagicNumber()==Magic1||OrderMagicNumber()==Magic2)){
            
            if(MathFloor((OrderOpenPrice()-Ask)/(Point*Bit)) < TrailingProfit){
            
            NewStop = NormalizeDouble(Ask-TrailingPoint1*Point*Bit,Digits);
            if(OrderStopLoss() > NewStop){
            if(OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), 0, DarkOrange))
               Print("进入SELL移动止损:Sell 盈利:",MathFloor((OrderOpenPrice()-Ask)/(Point*Bit))," 点,订单开盘价:",OrderOpenPrice(),"现在买价:",Bid," 当前止损价:",NewStop);
            }
            }
            
            if(MathFloor((OrderOpenPrice()-Ask)/(Point*Bit)) >= TrailingProfit){
            NewStop = NormalizeDouble(Ask-TrailingPoint2*Point*Bit,Digits);
            if(OrderStopLoss() > NewStop){
            if(OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), 0, DarkOrange))
               Print("进入SELL移动止损:Sell 盈利:",MathFloor((OrderOpenPrice()-Ask)/(Point*Bit))," 点,订单开盘价:",OrderOpenPrice(),"现在买价:",Bid," 当前止损价:",NewStop);
            }
            }
            
            
         }
      }
}

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