請問,我的程式是不是那裡有錯

 
string SymbolTA::getMACDTA(string symbol, ENUM_TIMEFRAMES period, int para1=12, int para2=26, int para3=9) {

   double buf [];
   
   int NumberOfValues = 3;
   
   int macdHandle = iMACD(symbol,period,para1,para2,para3,PRICE_TYPICAL);
  
   if (macdHandle < 0) {
      Print("Creating MACD handle fail ...");
      return "";
   }
   
   string str;
   
   if ( macdHandle != INVALID_HANDLE) {
    
    SetIndexBuffer(0,buf);   
    ArraySetAsSeries(buf,true);

    if(CopyBuffer(macdHandle,0,0,NumberOfValues,buf)<NumberOfValue)  {
      Print("Failed to copy the values ("+
            symbol +";"+") to the macd_buf array! Error ("+
            IntegerToString(GetLastError())+"): ");
            IndicatorRelease(macdHandle);
            return "";
    } 
    
      
    if (buf[0] > buf[1]) {
      str = "+";
    }
    if (buf[0] < buf[1]) {
      str = "-";
    }
     
    str += ",";
    
    if(buf[0] < 0) {
      str +="-";
    }
    if(buf[0] > 0) {
      str +="+";
    }
     
   } 
   IndicatorRelease(macdHandle);
   return str;
}

我寫script去呼叫它沒有任何問題,回傳的資訊都正確。但如果是寫在EA中的OnTick(), Tester就會回報

"2014.07.08 11:27:20 Core 3 2013.12.19 11:00:00   Failed to copy the values (EURCAD;) to the macd_buf array! Error (4806): "

 請問是不是EA的程式需要特別改寫什麼? 會去Call它的上一層程式長的像下面這樣

TREND SymbolTA::checkWTrend(string symbol) {

   string rStr = getMACDTA(symbol,PERIOD_W1);
   
   if( StringCompare(StringSubstr(rStr,0,1),"+") == 0) {
      wTrendMark = "+";
      return TREND_UP;
   }
   if( StringCompare(StringSubstr(rStr,0,1),"-") == 0) {
      wTrendMark = "-";
      return TREND_DOWN;
   }
   return -1;
}

TREND SymbolTA::checkDTrend(string symbol) {

   string rStr = getMACDTA(symbol,PERIOD_D1);
   
   if( StringCompare(StringSubstr(rStr,0,1),"+") == 0) {
      dTrendMark = "+";
      return TREND_UP;
   }
   if( StringCompare(StringSubstr(rStr,0,1),"-") == 0) {
      dTrendMark = "-";
      return TREND_DOWN;
   }
   return -1;
}

 謝謝. 請高手指教,


 
kego.tong:

我寫script去呼叫它沒有任何問題,回傳的資訊都正確。但如果是寫在EA中的OnTick(), Tester就會回報

"2014.07.08 11:27:20 Core 3 2013.12.19 11:00:00   Failed to copy the values (EURCAD;) to the macd_buf array! Error (4806): "

 請問是不是EA的程式需要特別改寫什麼? 會去Call它的上一層程式長的像下面這樣

 謝謝. 請高手指教,


查了一下4806的错误:

In case of the request to the inaccessible buffer, the error 4806 The requested data was not found») will be generated.

 

我後來把IndicatorRelease(xx)拿掉就ok了, 可是其它讀indicator值的function還是有問題

string SymbolTA::getStochastic(string symbol, ENUM_TIMEFRAMES period=PERIOD_D1, int para1=5, int para2=3, int para3=3) {
   
   int stoHandle = iStochastic(symbol, period,para1,para2,para3,MODE_EMA,STO_LOWHIGH);
   
   double buf[];
   
   string rStr;
   
  
   // 這道指令讓buffer順序顛倒, 最近的資料放在array的最前面
   ArraySetAsSeries(buf,true);
   
   // read k
   int copied = CopyBuffer(stoHandle,0,0,2,buf);
   
   // read d
   //int copied = CopyBuffer(stoHandle,1,0,5,buf);
   
   if(copied<=0) {
      Print("Unable to copy the values of the indicator Stochastic. Error = ",
            GetLastError(),",  copied =",copied);
      return "";
   }
   
   if (buf[0] < buf[1]) {
      rStr = "-";
   }
   
   if (buf[0] > buf[1]) {
      rStr = "+";
   }
   
   rStr += ","+ DoubleToString(buf[0],1);
   
   //IndicatorRelease(stoHandle);
   return (rStr);

}

 還有這個

int SymbolTA::getPDATRByPips(string symbol, ENUM_TIMEFRAMES period=PERIOD_D1, int para1 = 20) {
   
   int symbol_digits = (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
   int ret = (int) (getPDATR(symbol,period,para1) * MathPow(10, symbol_digits));
   
   return ret;

}

double SymbolTA::getPDATR(string symbol, ENUM_TIMEFRAMES period=PERIOD_D1, int para1 = 20) {

   double buf [];
   int NumberOfValues = 2;
   int atr = iATR(symbol,PERIOD_D1,20);
   int copied;
         
   if (atr != INVALID_HANDLE) {
    
    
      // 這道指令讓buffer順序顛倒, 最近的資料放在array的最前面
      ArraySetAsSeries(buf,true);
      copied = CopyBuffer(atr,0,0,NumberOfValues,buf);
      if(copied <= 0)  {
         Print("Failed to copy the values ("+
               symbol +";"+") to the atr_buf array! Error ("+
               IntegerToString(GetLastError())+"): ");
               //IndicatorRelease(atr);
         return 1;
      
      } else {
      //IndicatorRelease(atr);
      return buf[1];
      }
   } else {
     
     //IndicatorRelease(atr);
     
     return 1;
   }
   //IndicatorRelease(atr);
}
 
确保你回测所需的历史数据都下载了
原因: