請問PositionsClose接受又被拒絕是甚麼原因呢?

 

請問出現以下回報

該怎麼修改程式呢?

我的系統是多空可以並存的

懇請提示一二

謝謝



2019.06.01 00:58:59.746 Trades '3000027': instant sell 0.01 EURUSD_ at 1.11606, close #49945 buy 0.01 EURUSD_ 1.11627 (deviation: 30)

2019.06.01 00:58:59.784 Trades '3000027': accepted instant sell 0.01 EURUSD_ at 1.11606, close #49945 buy 0.01 EURUSD_ 1.11627 (deviation: 30)
2019.06.01 00:59:00.146 Trades '3000027': rejected instant sell 0.01 EURUSD_ at 1.11606, close #49945 buy 0.01 EURUSD_ 1.11627 (deviation: 30)



 //+----------------------------------------------- -------------------+
 //| 版權資訊
 //+----------------------------------------------- -------------------+
 #property copyright "Copyright 2012, MetaQuotes Software Corp."
 #property link "https://www.mql5.com"
 #property version "1.00"
 //+----------------------------------------------- -------------------+
 //| EA初始化1
 //+----------------------------------------------- -------------------+
 #include <Trade\Trade.mqh> //包含執行的交易庫
 #include <Trade\PositionInfo.mqh> //包含部位的資訊庫
CPositionInfo  m_Position;                   // trade position object
CTrade         m_Trade;                      // trading object

 bool  SendNotification; 

 input int UpThreshold = 1;
 input int DownThreshold = 1;
 
 input double 下單量 = 0.01;
  
 int Upcount ; int Downcount;
  
   int CheckBar;   int Kcount;   int iKcount;
 
 double Close_buf[];   //存儲動態數組
 double Open_buf[];    //存儲動態數組

   datetime CTime;
   string CCTime ;
   string CCCTime ;
   string iCCCTime ;
   
   input int 可交易時間 = 24 ; //24代表全時段 0代表 0~1可交易
   bool 可交易嗎;

 //ENUM_TIMEFRAMES my_timeframe; //存儲時間框架的變量

 input int 已有部位 = 0; //多單填1,空單填-1,空手填0
 input int 目前持有單號 = 0;//一般為五位數數字
 int iMyPositions = 已有部位;
 int pMyPositions = 已有部位;
 int i目前持有單號 = 目前持有單號;
 int p目前持有單號 = 目前持有單號;
 
//m_Position.SelectByIndex(0)
 //+----------------------------------------------- -------------------+
 //| EA初始化2
 //+----------------------------------------------- -------------------+
 int OnInit ()  {    
 ArraySetAsSeries (Close_buf, true ); //將buf數組的索引設置為時間序列
 ArraySetAsSeries (Open_buf,  true ); //將buf數組的索引設置為時間序列
 
 return ( 0 ); 
 }
 //+----------------------------------------------- -------------------+
 //| EA去初始化函數|
 //+----------------------------------------------- -------------------+
 void OnDeinit ( const int reason) { 
 ArrayFree (Open_buf);  //釋放動態數組
 ArrayFree (Close_buf); //釋放動態數組
 }
 //+----------------------------------------------- -------------------+
 //| EA的tick函數|
 //+----------------------------------------------- -------------------+
 void OnTick ()
 {  int err1= 0 ;  int err2= 0 ; //用於存儲價格圖表處理結果的變量 
 err1= CopyOpen (Symbol(),0, 0 ,2 ,Open_buf );   //將價格數據拷貝到動態數組,以進一步處理
 err2= CopyClose(Symbol(),0, 0 ,2 ,Close_buf);   //將價格數據拷貝到動態數組,以進一步處理
 if (err1!= 2 || err2!= 2  )  { Print ( "Failed to copy data " );  }//如果出錯退出
 
 
 
  iKcount = SeriesInfoInteger (Symbol(), Period(), SERIES_BARS_COUNT);   
   if (Kcount == 0)  Kcount = iKcount;
   if (Kcount == iKcount)  CheckBar = 0 ;
   if (iKcount != Kcount ) CheckBar = 1 ;  
   
   
CTime = SeriesInfoInteger (Symbol(), 0, SERIES_LASTBAR_DATE);
CCTime = TimeToString(CTime,TIME_MINUTES);
CCCTime =  StringSubstr(CCTime,0,2);
//Print("CCTime → " +CCTime + "  CCCTime → " +CCCTime);
if( CCCTime <10 ) {CCCTime =  StringSubstr(CCTime,1,1);}
   
   
   if(可交易時間!=CCCTime                   ) { 可交易嗎 = false;}
   if(可交易時間==CCCTime || 可交易時間== 24) { 可交易嗎 = true; }
   
   
  if (CheckBar == 1 ) //////////////超大if
 { 
  
  if (可交易嗎)
  {
  if (Close_buf[ 1 ] > Open_buf[ 1 ]) Upcount   = Upcount+1   ; //上漲實體 加積分
  if (Close_buf[ 1 ] < Open_buf[ 1 ]) Downcount = Downcount+1 ; //上漲實體 加積分
  }
 
  //做多
 if (iMyPositions  < 0 && Upcount == UpThreshold  && 可交易嗎)   
    {  m_Trade.PositionClose(Symbol(),30) ; Sleep(200); iMyPositions=0; Downcount=0;
      Print(PositionGetSymbol(0), "PositionClose() method  Return code=",m_Trade.ResultRetcode()+
     ". Code description: ",m_Trade.ResultRetcodeDescription());}
 if (iMyPositions == 0 && Upcount == UpThreshold  && 可交易嗎)   { m_Trade.Buy( 下單量 ,Symbol());  iMyPositions=1; Downcount=0  ;Sleep(200);m_Position.SelectByIndex(0);i目前持有單號 =m_Position.Ticket();}
 if (iMyPositions > pMyPositions  ) {
  SendNotification( 
     Symbol() + "\n" +  "已出現 " +Upcount + " 次實體上漲"  +"\n"   + "請務必評估自身風險承受度與資金控管,善設停損。" 
   );                 }
   
   //做空
 if (iMyPositions  > 0 && Downcount == DownThreshold && 可交易嗎 ) 
    { m_Trade.PositionClose(Symbol(),30); Sleep(200); iMyPositions=0 ; Upcount=0;
     Print(PositionGetSymbol(0), "PositionClose() method Return code=",m_Trade.ResultRetcode()+
     ". Code description: ",m_Trade.ResultRetcodeDescription());} 
 if (iMyPositions == 0 && Downcount == DownThreshold && 可交易嗎 )   { m_Trade.Sell( 下單量 ,Symbol());  iMyPositions=-1; Upcount=0;Sleep(200);m_Position.SelectByIndex(0) ;i目前持有單號 =m_Position.Ticket();}
 if (iMyPositions < pMyPositions  ) {
  SendNotification( 
     Symbol() + "\n" +  "已出現 " +Downcount + " 次實體下跌"  +"\n"   + "請務必評估自身風險承受度與資金控管,善設停損。" 
   );                  }


 //強平 休息囉  亦可以用在期貨沒開盤
 if (可交易嗎 == false)
 { 
   if (iMyPositions != 0 )  
  {
      if (iMyPositions ==  1 )   { m_Trade.Sell( 下單量 ,Symbol()); }
      if (iMyPositions == -1 )   { m_Trade.Buy ( 下單量 ,Symbol()); }
    SendNotification( 
     Symbol() + "\n" +  "強平!休息啦!"                 );  
   }
iMyPositions=0; Upcount=0;Downcount=0;
}


     SendNotification(   Symbol() +  "\n" 
     "Upcount"       "\n    " +  Upcount+      "\n"          "Downcount"       "\n    " +  Downcount     + "\n" 
     "iMyPositions"  "\n    " +  iMyPositions+ "\n"     
       "m_Position.Ticket()"        "\n    " +  m_Position.Ticket()      + "\n"
      "i目前持有單號"        "\n    " +  i目前持有單號+       "\n"           "p目前持有單號"        "\n    " +  p目前持有單號      + "\n");

 
   Kcount = iKcount ;
  pMyPositions = iMyPositions; 
  p目前持有單號=i目前持有單號;
  
}//超大if
  } //             Symbol() +  "\n" 
   //  "Upcount"      "\n    " +  Upcount+ "\n" 
 //+----------------------------------------------- -------------------+