COCO研究院

 找回密碼
 註冊
搜索
查看: 2191|回復: 0

[MT4] EA 程式完成後 執行沒反應

[複製鏈接]
發表於 16-7-12 12:22 | 顯示全部樓層 |閱讀模式
各位高手
小弟我剛開始學寫程式,就用很簡單的比大小程式來測試結果寫完 除錯都沒問提了,但執行時卻不動
有沒有人可以幫幫我,我的程式出了什麼問題

int  start()
  {
   int ticket, total;
   double lots;
   double O0;
   double C0;
   double M1,M2,M3,M4,M5,M6,M7,M8,M15;
   double B0,B1,B2,B3,B4,ES;
   int kind;//3B 5S 7O

    lots=0.1;
    O0= iOpen(NULL,0,0);
    C0= iClose(NULL,0,0);
    M1= (iOpen(NULL,1,0)+ iClose(NULL,1,0))/2;
    M2= (iOpen(NULL,2,0)+ iClose(NULL,2,0))/2;
    M3= (iOpen(NULL,3,0)+ iClose(NULL,3,0))/2;
    M4= (iOpen(NULL,4,0)+ iClose(NULL,4,0))/2;
    M5= (iOpen(NULL,5,0)+ iClose(NULL,5,0))/2;
    M6= (iOpen(NULL,6,0)+ iClose(NULL,6,0))/2;
    M7= (iOpen(NULL,7,0)+ iClose(NULL,7,0))/2;
    M8= (iOpen(NULL,8,0)+ iClose(NULL,8,0))/2;
    M15= (iOpen(NULL,15,0)+ iClose(NULL,15,0))/2;
    B0= iOpen(NULL,0,0)- iClose(NULL,0,0);
    B1= iOpen(NULL,1,0)- iClose(NULL,1,0);
    B2= iOpen(NULL,2,0)- iClose(NULL,2,0);
    B3= iOpen(NULL,3,0)- iClose(NULL,3,0);
    B4= iOpen(NULL,4,0)- iClose(NULL,4,0);
    ES=B0+ B1+ B2+ B3+ B4;

   total=OrdersTotal();
   while(total<1)
   {
      // no opened orders identified
      kind=7;
      if(AccountFreeMargin()<(1000*lots))
      {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);
      }
      // check for long position (BUY) possibility
      if(M15<M1 && M15<M2 && M15<M3 && M15<M4 && M15<M5 && M15<M6 && M15<M7 && M15<M8 )
      {
         ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,0,Ask+500*Point,NULL,NULL,0,Green);
         if(ticket>0)
         {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("time:",Year(),"/",Month(),"/",Day(),Hour(),":",Minute(),"B order price : ",OrderOpenPrice());
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {kind=3;}
         }

         else
         {Print("Error opening BUY order : ",GetLastError());
         return(0);
         }
       }
      // check for short position (SELL) possibility
      if(M15>M1 && M15>M2 && M15>M3 && M15>M4 && M15>M5 && M15>M6 && M15>M7 && M15>M8 )
      {
         ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,3,0,Bid-500*Point,NULL,NULL,0,Red);
         if(ticket>0)
         {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("time::",Year(),"/",Month(),"/",Day(),Hour(),":",Minute(),"S oder price : ",OrderOpenPrice());
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {kind=5;}
         }

         else
         {Print("Error opening SELL order : ",GetLastError());
         return(0);
         }
      }
     }

   while(total>1)
   {
     while(kind==5)
       {
         if(ES<=-0.009)
          {
           ticket=OrderClose(OrderTicket(),lots,Ask,3,Violet);
              if(total<1)
                {
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("time:",Year(),"/",Month(),"/",Day(),Hour(),":",Minute(),"profit:",AccountProfit());
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {kind=7;}
                }


          }               
         if(M15<M1 && M15<M2 && M15<M3 && M15<M4 && M15<M5 && M15<M6 && M15<M7 && M15<M8 )
          {
            if(M1<M3 )
            {
             Print("S not close to B,","TIME:",Year(),"/",Month(),"/",Day(),Hour(),":",Minute());
            }
            else
            {
            ticket=OrderClose(OrderTicket(),lots,Ask,3,Violet);
              if(total<1)
                {
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("time:",Year(),"/",Month(),"/",Day(),Hour(),":",Minute(),"profit:",AccountProfit());
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {kind=7;}
                }


            }
          }
       }
     while(kind==3)       {
         if(ES>=0.009)
          {
          ticket=OrderClose(OrderTicket(),lots,Ask,3,Violet);
              if(total<1)
                {
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("time:",Year(),"/",Month(),"/",Day(),Hour(),":",Minute(),"profit:",AccountProfit());
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {kind=7;}
                }


          }               
         if( M15>M1 && M15>M2 && M15>M3 && M15>M4 && M15>M5 && M15>M6 && M15>M7 && M15>M8 )
          {
            if(M1>M3 )
            {
             Print("B not CLose to sell,","Time:",Year(),"/",Month(),"/",Day(),Hour(),":",Minute());
            }
            else
            {
             ticket=OrderClose(OrderTicket(),lots,Ask,3,Violet);
              if(total<1)
                {
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("time:",Year(),"/",Month(),"/",Day(),Hour(),":",Minute(),"profit:",AccountProfit());
                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {kind=7;}
                }


            }
          }
       }

   }
    return(0);     
  }


您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-11-25 02:53

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |