诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

以MACD信号开发的止损加倍开仓EA macdea.mq4

macdea EA是根据MACD信号开发的自动交易系统,该EA当订单止损后即加倍开仓。

源码:

//+------------------------------------------------------------------+
//|                                                       macdea.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "http://www.125808047.com"
#property version   "1.00"
#property strict

extern double Lots=0.01;
extern double kcbs=2;
extern int fastma=12;
extern int slowma=26;
extern int signalma=9;
extern int Slippage = 3;
extern double stoploss=500;
extern double takeprofit=1000;
datetime buytime=0;
datetime selltime=0;
int magic=1218;

void OnTick()
{
 orderopen();
}
  
int buydanshu(double &op,double &lots)
  {
     int a=0;
     op=0;
     lots=0;
     for(int i=0;i<OrdersTotal();i++)
      {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
          {
            if(OrderSymbol()==Symbol()&&OrderType()==OP_BUY)
              {
                a++;
                op=OrderOpenPrice();
                lots=OrderLots();
              }
          }
      }
    return(a);
  }
int selldanshu(double &op,double &lots)
  {
     int a=0;
     op=0;
     lots=0;
     for(int i=0;i<OrdersTotal();i++)
      {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
          {
            if(OrderSymbol()==Symbol()&&OrderType()==OP_SELL)
              {
                a++;
                op=OrderOpenPrice();
                lots=OrderLots();
              }
          }
      }
    return(a);
  }
double flots(double dlots)
  {
    double fb=NormalizeDouble(dlots/MarketInfo(Symbol(),MODE_MINLOT),0);
    return(MarketInfo(Symbol(),MODE_MINLOT)*fb);
  }  
double CheckHistoryClosep()
   {  
   double b=0;
   for (int i=0;i<OrdersHistoryTotal();i++)  
      {
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
         { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
            {
            b=OrderProfit();
            }          
         }
      }
   return(b);
   } 
 double CheckHistorylots()
   {  
   double b=0;
   for (int i=0;i<OrdersHistoryTotal();i++)  
      {
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
         { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
            {
            b=OrderLots();
            }          
         }
      }
   return(b);
   }  
void Closebuy()
  {         
        for(int i=OrdersTotal()-1;i>=0;i--)
         {
           if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
             {
               if(OrderSymbol()==Symbol() && OrderType()==OP_BUY )
                 {
                   bool y=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),300,Green);
                 }
             }
         }
        Sleep(800);         
     }  
void Closesell()
  {
        for(int i=OrdersTotal()-1;i>=0;i--)
         {
           if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
             {
               if(OrderSymbol()==Symbol() && OrderType()==OP_SELL )
                 {
                   bool y=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),300,Green);
                 }
             }
         }
        Sleep(800);             
     }
void orderopen()
{
int ticket;
double a=iMACD(NULL,0,fastma,slowma,signalma,PRICE_CLOSE,MODE_MAIN,0);
double b=iMACD(NULL,0,fastma,slowma,signalma,PRICE_CLOSE,MODE_SIGNAL,0);
double c=iMACD(NULL,0,fastma,slowma,signalma,PRICE_CLOSE,MODE_MAIN,1);
double d=iMACD(NULL,0,fastma,slowma,signalma,PRICE_CLOSE,MODE_SIGNAL,1);
double buyop,buylots;
    int buydanshu=buydanshu(buyop,buylots);
     double sellop,selllots;
     int selldanshu=selldanshu(sellop,selllots);
if(CheckHistorylots()>=0)
{
if(CheckHistoryClosep()>=0)
{
if(buydanshu<1&&c<d&&a>b&&buytime!=Time[0])
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-stoploss*Point,Ask+takeprofit*Point,"",magic,0,Blue);  
                 buytime=Time[0];
                 }
 if(selldanshu<1&&c>d&&a<b&&selltime!=Time[0])
 {
 ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+stoploss*Point,Bid-takeprofit*Point,"",magic,0,Green); 
                 selltime=Time[0];
               }
 }                
 else
 if(CheckHistoryClosep()<0) 
 {
  if(buydanshu<1&&c<d&&a>b&&buytime!=Time[0])
{
ticket=OrderSend(Symbol(),OP_BUY,flots(CheckHistorylots()*kcbs),Ask,Slippage,Ask-stoploss*Point,Ask+takeprofit*Point,"",magic,0,Blue);  
                 buytime=Time[0];
                 }
 if(selldanshu<1&&c>d&&a<b&&selltime!=Time[0])
 {
 ticket=OrderSend(Symbol(),OP_SELL,flots(CheckHistorylots()*kcbs),Bid,Slippage,Bid+stoploss*Point,Bid-takeprofit*Point,"",magic,0,Green); 
                 selltime=Time[0];
               } 
} 
}
}        
打赏
版权所有转载请注明标题及链接:峰汇在线 » 以MACD信号开发的止损加倍开仓EA macdea.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏