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

根据布林带写的趋势EA DUMMYEA-BOLL



DUMMYEA-BOLL EA根据布林带信号在交易。属于趋势短线。

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

//+------------------------------------------------------------------+
//|                                                 DUMMYEA-BOLL.mq4 |
//|                       Copyright @2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright @2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Lots = 0.1;
extern int Slippage = 3;
extern int MagicNumber = 999999;

extern int Boll周期 = 20;
extern int Boll偏差 = 2;

bool OrderOpen = false; 
int OrderTime;
int Ticket;
int HoldingOrderType;

double MaxBid = 0;
double MinAsk = 0;
double MovePoint = 0;

double BollUpper1;
double BollLower1;
double BollMiddle1;
double BollUpper2;
double BollLower2;
double BollMiddle2;
double BollUpper3;
double BollLower3;
double BollMiddle3;

int init()
  {

   return(0);
  }

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

int start()
  {
//----

       BollUpper1 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 1);
       BollLower1 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 1);
       BollMiddle1 = (BollUpper1 + BollLower1)/2;
       BollUpper2 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 2);
       BollLower2 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 2);
       BollMiddle2 = (BollUpper2 + BollLower2)/2;
       BollUpper3 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 3);
       BollLower3 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 3);
       BollMiddle3 = (BollUpper3 + BollLower3)/2;
   
       if (Time[0] != OrderTime) OrderOpen = false; //每根k线只能下单一次
      
       if (Bid > MaxBid) MaxBid = Bid; 
       if (Ask < MinAsk) MinAsk = Ask;
       
       if (HoldingOrderType == OP_BUY){
           if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES) == true){
               if (MaxBid - OrderOpenPrice() < 15 * Point) MovePoint = 8 * Point ;   // 盈利小于15刀,定义止损止盈为回落8刀
               if (MaxBid - OrderOpenPrice() >= 15 * Point)MovePoint = (MaxBid - OrderOpenPrice()) * 0.3 * Point ; // 盈利大于15刀,定义止损止盈为回落盈利的30%
           }
           if ((MaxBid - Bid >MovePoint) || (Close[2]>BollMiddle2 && Close[1]<BollMiddle1) ||  OrderProfit() > 10.0)CloseAllBuy();
       }
       
       if (HoldingOrderType == OP_SELL){
           if (OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES) == true){
               if (OrderOpenPrice() - MinAsk < 15 * Point) MovePoint = 8 * Point ;
               if (OrderOpenPrice() - MinAsk >= 15 * Point)MovePoint = (OrderOpenPrice() - MinAsk) * 0.3 * Point ;
           }
           if ((Ask - MinAsk > MovePoint) || (Close[2]<BollMiddle2 && Close[1]>BollMiddle1) ||  OrderProfit() > 10.0) CloseAllSell();
       }
       
      
       if(Boll(OP_BUY) == true && 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;
                 OrderTime = Time[0];
                 MaxBid = Bid;
                 HoldingOrderType = OrderType();
                 
                 Print("Pivot dummy-buy order opened : ",OrderOpenPrice());
              }
              else
              {
                 Print("Error opening Pivot dummy-buy order : ",GetLastError());
                 return(0);
              }
           }
        }
        
        else if(Boll(OP_SELL) == true && 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;
                 OrderTime = Time[0];
                 MinAsk = Ask;
                 HoldingOrderType = OrderType();
                 
                 Print("Pivot dummy-sell order opened : ",OrderOpenPrice());
              }
              else
              {
                 Print("Error opening Pivot dummy-sell order : ",GetLastError());
                 return(0);
              }
           }
        }
      
      
      
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

bool Boll(int type)
{
   BollUpper1 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 1);
   BollLower1 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 1);
   BollMiddle1 = (BollUpper1 + BollLower1)/2;
   BollUpper2 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 2);
   BollLower2 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 2);
   BollMiddle2 = (BollUpper2 + BollLower2)/2;
   BollUpper3 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_UPPER , 3);
   BollLower3 = iBands(Symbol() , 0 , Boll周期 , Boll偏差 , 0 , PRICE_CLOSE , MODE_LOWER , 3);
   BollMiddle3 = (BollUpper3 + BollLower3)/2;
   
   switch(type)
   {
   case OP_BUY: // 上轨 中轨 初次向上 下轨向下
    if((BollUpper2<BollUpper3&&BollUpper2<BollUpper1 && BollMiddle2<BollMiddle1 && BollLower1<BollLower2)||(BollUpper2<BollUpper1 &&  BollMiddle2<BollMiddle3&&BollMiddle2<BollMiddle1 && BollLower1<BollLower2))
    {
     return (true);
    }else return(false);
    break;
    
   case OP_SELL: // 上轨 中轨 初次向下 下轨向上
    if((BollUpper2>BollUpper3&&BollUpper2>BollUpper1 && BollMiddle2>BollMiddle1 && BollLower1>BollLower2)||(BollUpper2>BollUpper1 &&  BollMiddle2>BollMiddle3&&BollMiddle2>BollMiddle1 && BollLower1>BollLower2))
    {
     return (true);
    }else return(false);
    break;
   }
return (0);
}


void CloseAllSell()
{
   bool CAS = FALSE;
   for (int t=0; t<OrdersTotal(); t++)
   {
      bool cg = OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()==Symbol() && 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++) 
   {
      bool cg = OrderSelect(t, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()==Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber)
      CAB = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(OrderClosePrice(), Digits), Slippage, Yellow);
   }
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 根据布林带写的趋势EA DUMMYEA-BOLL
上一篇:
下一篇:
分享到:更多 ()