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

超短EA MMA_Breakout_strategy.mq4

MMA_Breakout_strategy EA根据均线信号进行超短交易。

源码:

//+-------------------------------------------------------------------+
//|                                         MMA_Breakout_strategy.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp.  |
//+-------------------------------------------------------------------+
#property copyright "Copyright 2012, WhooDoo22."
#property link      "http://www.125808047.com"

int MaxOrders = 1; 
int TradePerBar = 0; 
int BarCount = -1; 
int MaxTradePerBar = 1; 
int BarsCount = 0;

bool MaxTradePerBarUSE = true;

int ticket;
int TakeProfit;
bool BuyTicket_12345_InUse1;
bool BuyTicket_12345_InUse2;
bool BuyTicket_12345_InUse3;
bool BuyTicket_12345_InUse4;

bool SellTicket_77777_InUse1;
bool SellTicket_77777_InUse2;
bool SellTicket_77777_InUse3;
bool SellTicket_77777_InUse4;

bool win;
int i;
bool cg = false;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{ 
  Comment("www.125808047.com"); 
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void OnTick()
  {
//***************************
// BUY ORDER OPEN SECTION 1 ;
//***************************
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(OrdersHistoryTotal()==0)                                                                 {
   if(OrdersTotal()<MaxOrders)                                                                 {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,2)<(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,2)))     { 
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)>(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,1)))     {
   if(Bars>BarsCount)                                                                          {
   if(MaxTradePerBarUSE)                                                                       { 
     {
      ticket=OrderSend(Symbol(),OP_BUY,0.04,Ask,30,Ask-5000*Point,Ask+99999*Point,"",12345,0,Blue);    
      BarsCount=Bars;
      BuyTicket_12345_InUse1=true;
      BuyTicket_12345_InUse2=true;
      BuyTicket_12345_InUse3=true;
      BuyTicket_12345_InUse4=true;
      i++;
     }
     }}}}}}
     
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(OrdersHistoryTotal()>0)                                                                  {
   if(OrdersTotal()<MaxOrders)                                                                 {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,2)<(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,2)))     { 
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)>(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,1)))     {
   if(Bars>BarsCount)                                                                          {
   if(MaxTradePerBarUSE)                                                                       { 
     {
      ticket=OrderSend(Symbol(),OP_BUY,0.04,Ask,30,Ask-5000*Point,Ask+99999*Point,"",12345,0,Blue);    
      BarsCount=Bars;
      BuyTicket_12345_InUse1=true;
      BuyTicket_12345_InUse2=true;
      BuyTicket_12345_InUse3=true;
      BuyTicket_12345_InUse4=true;
      i++;
     }
     }}}}}}
     
//****************************
// BUY ORDER CLOSE SECTION 1 ;
//****************************          
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse1==true)                                                            {
   if(OrderLots()==0.04)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)<(iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0)))        { 
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE);
      BuyTicket_12345_InUse1=false;
      i++;
     }
     }}}}}     

   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse2==true)                                                            {
   if(OrderLots()==0.03)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)<(iMA(NULL,0,25,0,MODE_SMMA,PRICE_CLOSE,0)))      { 
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE); 
      BuyTicket_12345_InUse2=false;
      i++;
     }
     }}}}}
     
   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse3==true)                                                            {
   if(OrderLots()==0.02)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)<(iMA(NULL,0,50,0,MODE_SMMA,PRICE_CLOSE,0)))      { 
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE); 
      BuyTicket_12345_InUse3=false;
      i++;
     }
     }}}}}
     
   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse4==true)                                                            {
   if(OrderLots()==0.01)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)<(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,0)))     { 
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE); 
      BuyTicket_12345_InUse4=false;
     }
     }}}}}     
//****************************
// BUY ORDER CLOSE SECTION 2 ;
//****************************      
     
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse1 == true)                                                          {
   if(OrderLots()==0.04)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)<(iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1)))        { 
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE);
      BuyTicket_12345_InUse1=false;
      i++;
     }
     }}}}}     

   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse2==true)                                                            {
   if(OrderLots()==0.03)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)<(iMA(NULL,0,25,0,MODE_SMMA,PRICE_CLOSE,1)))      {  
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE); 
      BuyTicket_12345_InUse2=false;
      i++;
     }
     }}}}}
     
   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse3==true)                                                            {
   if(OrderLots()==0.02)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)<(iMA(NULL,0,50,0,MODE_SMMA,PRICE_CLOSE,1)))      {  
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE); 
      BuyTicket_12345_InUse3=false;
      i++;
     }
     }}}}}
     
   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(BuyTicket_12345_InUse4==true)                                                            {
   if(OrderLots()==0.01)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)<(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,1)))     { 
     {
      cg = OrderClose(i,0.01,Ask,30,CLR_NONE); 
      BuyTicket_12345_InUse4=false;
      
      ticket=OrderSend(Symbol(),OP_SELL,0.04,Bid,30,Bid+5000*Point,Bid-99999*Point,"",77777,0,Red);
      BarsCount=Bars;
      SellTicket_77777_InUse1=true;
      SellTicket_77777_InUse2=true;
      SellTicket_77777_InUse3=true;
      SellTicket_77777_InUse4=true;
      i++;
     }
     }}}}}            
    
//****************************
// SELL ORDER OPEN SECTION 1 ;
//****************************
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(OrdersHistoryTotal()==0)                                                                 {
   if(OrdersTotal()<MaxOrders)                                                                 {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,2)>(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,2)))     {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)<(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,1)))     {  
   if(Bars>BarsCount)                                                                          {
   if(MaxTradePerBarUSE)                                                                       { 
     {
      ticket=OrderSend(Symbol(),OP_SELL,0.04,Bid,30,Bid+5000*Point,Bid-99999*Point,"",77777,0,Red);
      BarsCount=Bars;
      SellTicket_77777_InUse1=true;
      SellTicket_77777_InUse2=true;
      SellTicket_77777_InUse3=true;
      SellTicket_77777_InUse4=true;
      i++;
     }
     }}}}}}
     
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(OrdersHistoryTotal()>0)                                                                  {
   if(OrdersTotal()<1)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,2)>(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,2)))     {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)<(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,1)))     { 
   if(Bars>BarsCount)                                                                          {
   if(MaxTradePerBarUSE)                                                                       {   
     {
      ticket=OrderSend(Symbol(),OP_SELL,0.04,Bid,30,Bid+5000*Point,Bid-99999*Point,"",77777,0,Red);    
      BarsCount=Bars;
      SellTicket_77777_InUse1=true;
      SellTicket_77777_InUse2=true;
      SellTicket_77777_InUse3=true;
      SellTicket_77777_InUse4=true;
      i++;
     }
     }}}}}}     

//*****************************
// SELL ORDER CLOSE SECTION 1 ;
//***************************** 
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse1==true)                                                           {
   if(OrderLots()==0.04)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)>(iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0)))        { 
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse1=false;
      i++;
     }
     }}}}}     

   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse2==true)                                                           {
   if(OrderLots()==0.03)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)>(iMA(NULL,0,25,0,MODE_SMMA,PRICE_CLOSE,0)))      {  
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse2=false;
      i++; 
     }
     }}}}}
     
   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse3==true)                                                           {
   if(OrderLots()==0.02)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)>(iMA(NULL,0,50,0,MODE_SMMA,PRICE_CLOSE,0)))      {  
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse3=false;
      i++; 
     }
     }}}}}
     
   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse4==true)                                                           {
   if(OrderLots()==0.01)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()>=0)                                                                        {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0)>(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,0)))     { 
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse4=false; 
     }
     }}}}}          
     
//*****************************
// SELL ORDER CLOSE SECTION 2 ;
//*****************************     
   cg = OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse1==true)                                                           {
   if(OrderLots()==0.04)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)>(iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1)))        { 
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse1=false;
      i++;
     }
     }}}}}     

   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse2==true)                                                           {
   if(OrderLots()==0.03)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)>(iMA(NULL,0,25,0,MODE_SMMA,PRICE_CLOSE,1)))      {  
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse2 = false;
      i++;
     }
     }}}}}

   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse3==true)                                                           {
   if(OrderLots()==0.02)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)>(iMA(NULL,0,50,0,MODE_SMMA,PRICE_CLOSE,1)))      { 
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse3 = false;
      i++;
     }
     }}}}}
     
   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(SellTicket_77777_InUse4==true)                                                           {
   if(OrderLots()==0.01)                                                                       {
   if(OrdersTotal()>0)                                                                         {
   if(OrderProfit()<0)                                                                         {
   if(iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,1)>(iMA(NULL,0,200,0,MODE_SMMA,PRICE_CLOSE,1)))     { 
     {
      cg = OrderClose(i,0.01,Bid,30,CLR_NONE);
      SellTicket_77777_InUse4 = false; 
      
      ticket=OrderSend(Symbol(),OP_BUY,0.04,Ask,30,Ask-5000*Point,Ask+99999*Point,"",12345,0,Blue);    
      BarsCount=Bars;
      BuyTicket_12345_InUse1=true;
      BuyTicket_12345_InUse2=true;
      BuyTicket_12345_InUse3=true;
      BuyTicket_12345_InUse4=true; 
      i++;
     }
     }}}}}     

   cg = OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES);
   if(OrderLots()==0.01){
    
   Comment("/n OrderTicket() = " ,i, 
           "/n OrderProfit() = ",OrderProfit());
          }  
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 超短EA MMA_Breakout_strategy.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏