WEB开发网
开发学院软件开发VC 用VC开发股票分析软件(二) 阅读

用VC开发股票分析软件(二)

 2008-09-25 19:27:09 来源:WEB开发网   
核心提示:/*Makesureslowisreallyslowerthan*thefastperiod!ifnot,swap...*/if(optInSlowPeriod<optInFastPeriod){/*swap*/tempInteger=optInSlowPeriod;optInSlowPeriod=optInFa

/*Makesureslowisreallyslowerthan
  *thefastperiod!ifnot,swap...
  */
 if(optInSlowPeriod<optInFastPeriod)
 {
   /*swap*/
   tempInteger   =optInSlowPeriod;
   optInSlowPeriod=optInFastPeriod;
   optInFastPeriod=tempInteger;
 }
 /*Catchspecialcaseforfix26/12MACD.*/
 if(optInSlowPeriod!=0)
   k1=PER_TO_K(optInSlowPeriod);
 else
 {
   optInSlowPeriod=26;
   k1=(double)0.075;/*Fix26*/
 }
 if(optInFastPeriod!=0)
   k2=PER_TO_K(optInFastPeriod);
 else
 {
   optInFastPeriod=12;
   k2=(double)0.15;/*Fix12*/
 }
 lookbackSignal=LOOKBACK_CALL(EMA)(optInSignalPeriod_2); 
 /*Moveupthestartindexifthereisnot
  *enoughinitialdata.
  */
 lookbackTotal= lookbackSignal;
 lookbackTotal+=LOOKBACK_CALL(EMA)(optInSlowPeriod);
 if(startIdx<lookbackTotal)
   startIdx=lookbackTotal;
 /*Makesurethereisstillsomethingtoevaluate.*/
 if(startIdx>endIdx)
 {
   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
   returnENUM_VALUE(RetCode,TA_SUCCESS,Success);
 }
 /*Allocateintermediatebufferforfast/slowEMA.*/
 tempInteger=(endIdx-startIdx)+1+lookbackSignal;
 ARRAY_ALLOC(fastEMABuffer,tempInteger);
 #if!defined(_JAVA)
   if(!fastEMABuffer)
   {
    VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
    VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
    returnENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr);
   }
 #endif
 ARRAY_ALLOC(slowEMABuffer,tempInteger);
 #if!defined(_JAVA)
   if(!slowEMABuffer)
   {
    VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
    VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
    ARRAY_FREE(fastEMABuffer);
    returnENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr);
   }
 #endif
 /*CalculatetheslowEMA. 
  *
  *MovebackthestartIdxtogetenoughdata
  *forthesignalperiod.Thatway,oncethe
  *signalcalculationisdone,alltheoutput
  *willstartattherequested'startIdx'.
  */
 tempInteger=startIdx-lookbackSignal;
 retCode=FUNCTION_CALL(INT_EMA)(tempInteger,endIdx,
                  inReal,optInSlowPeriod,k1,
                  VALUE_HANDLE_OUT(outBegIdx1),VALUE_HANDLE_OUT(outNbElement1),slowEMABuffer);
 if(retCode!=ENUM_VALUE(RetCode,TA_SUCCESS,Success))
 {
   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
   ARRAY_FREE(fastEMABuffer);
   ARRAY_FREE(slowEMABuffer);
   returnretCode;
 }
 /*CalculatethefastEMA.*/
 retCode=FUNCTION_CALL(INT_EMA)(tempInteger,endIdx,
                  inReal,optInFastPeriod,k2,
                  VALUE_HANDLE_OUT(outBegIdx2),VALUE_HANDLE_OUT(outNbElement2),fastEMABuffer);
 if(retCode!=ENUM_VALUE(RetCode,TA_SUCCESS,Success))
 {
   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
   ARRAY_FREE(fastEMABuffer);
   ARRAY_FREE(slowEMABuffer);
   returnretCode;
 }
 /*Paranotests.Willberemovedeventually.*/
 if((VALUE_HANDLE_GET(outBegIdx1)!=tempInteger)|| 
   (VALUE_HANDLE_GET(outBegIdx2)!=tempInteger)|| 
   (VALUE_HANDLE_GET(outNbElement1)!=VALUE_HANDLE_GET(outNbElement2))||
   (VALUE_HANDLE_GET(outNbElement1)!=(endIdx-startIdx)+1+lookbackSignal))
 {
   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
   ARRAY_FREE(fastEMABuffer);
   ARRAY_FREE(slowEMABuffer);
   returnTA_INTERNAL_ERROR(119);
 }
 /*Calculate(fastEMA)-(slowEMA).*/
 for(i=0;i<VALUE_HANDLE_GET(outNbElement1);i++)
   fastEMABuffer[i]=fastEMABuffer[i]-slowEMABuffer[i];
 /*Copytheresultintotheoutputforthecaller.*/
 ARRAY_MEMMOVE(outMACD,0,fastEMABuffer,lookbackSignal,(endIdx-startIdx)+1);
 /*Calculatethesignal/triggerline.*/
 retCode=FUNCTION_CALL_DOUBLE(INT_EMA)(0,VALUE_HANDLE_GET(outNbElement1)-1,
                      fastEMABuffer,optInSignalPeriod_2,PER_TO_K(optInSignalPeriod_2), 
                      VALUE_HANDLE_OUT(outBegIdx2),VALUE_HANDLE_OUT(outNbElement2),outMACDSignal);
 ARRAY_FREE(fastEMABuffer);
 ARRAY_FREE(slowEMABuffer);
 if(retCode!=ENUM_VALUE(RetCode,TA_SUCCESS,Success))
 {
   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
   returnretCode;
 }
 /*Calculatethehistogram.*/
 for(i=0;i<VALUE_HANDLE_GET(outNbElement2);i++)
   outMACDHist[i]=outMACD[i]-outMACDSignal[i];
 /*Alldone!Indicatetheoutputlimitsandreturnsuccess.*/
 VALUE_HANDLE_DEREF(outBegIdx)  =startIdx;
 VALUE_HANDLE_DEREF(outNBElement) =VALUE_HANDLE_GET(outNbElement2);
 returnENUM_VALUE(RetCode,TA_SUCCESS,Success);
}
/****STARTGENCODESECTION5-DONOTDELETETHISLINE****/
/*Generated*/ 
/*Generated*/#define USE_SINGLE_PRECISION_INPUT
/*Generated*/#if!defined(_MANAGED)&&!defined(_JAVA)
/*Generated*/  #undef TA_PREFIX
/*Generated*/  #define TA_PREFIX(x)TA_S_##x
/*Generated*/#endif
/*Generated*/#undef INPUT_TYPE
/*Generated*/#define INPUT_TYPEfloat
/*Generated*/#ifdefined(_MANAGED)
/*Generated*/enumclassCore::RetCodeCore::Macd(int  startIdx,
/*Generated*/                   int  endIdx,
/*Generated*/                   cli::array<float>^inReal,
/*Generated*/                   int     optInFastPeriod,/*From2to100000*/
/*Generated*/                   int     optInSlowPeriod,/*From2to100000*/
/*Generated*/                   int     optInSignalPeriod,/*From1to100000*/
/*Generated*/                   [Out]int%  outBegIdx,
/*Generated*/                   [Out]int%  outNBElement,
/*Generated*/                   cli::array<double>^ outMACD,
/*Generated*/                   cli::array<double>^ outMACDSignal,
/*Generated*/                   cli::array<double>^ outMACDHist)
/*Generated*/#elifdefined(_JAVA)
/*Generated*/publicRetCodemacd(int  startIdx,
/*Generated*/           int  endIdx,
/*Generated*/           float    inReal[],
/*Generated*/           int     optInFastPeriod,/*From2to100000*/
/*Generated*/           int     optInSlowPeriod,/*From2to100000*/
/*Generated*/           int     optInSignalPeriod,/*From1to100000*/
/*Generated*/           MInteger  outBegIdx,
/*Generated*/           MInteger  outNBElement,
/*Generated*/           double    outMACD[],
/*Generated*/           double    outMACDSignal[],
/*Generated*/           double    outMACDHist[])
/*Generated*/#else
/*Generated*/TA_RetCodeTA_S_MACD(int  startIdx,
/*Generated*/           int  endIdx,
/*Generated*/           constfloat inReal[],
/*Generated*/           int     optInFastPeriod,/*From2to100000*/
/*Generated*/           int     optInSlowPeriod,/*From2to100000*/
/*Generated*/           int     optInSignalPeriod,/*From1to100000*/
/*Generated*/           int     *outBegIdx,
/*Generated*/           int     *outNBElement,
/*Generated*/           double    outMACD[],
/*Generated*/           double    outMACDSignal[],
/*Generated*/           double    outMACDHist[])
/*Generated*/#endif
/*Generated*/{
/*Generated*/ #ifndefTA_FUNC_NO_RANGE_CHECK
/*Generated*/  if(startIdx<0)
/*Generated*/    returnENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
/*Generated*/  if((endIdx<0)||(endIdx<startIdx))
/*Generated*/    returnENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
/*Generated*/  #if!defined(_JAVA)
/*Generated*/  if(!inReal)returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  #endif 
/*Generated*/  if((int)optInFastPeriod==TA_INTEGER_DEFAULT)
/*Generated*/    optInFastPeriod=12;
/*Generated*/  elseif(((int)optInFastPeriod<2)||((int)optInFastPeriod>100000))
/*Generated*/    returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  if((int)optInSlowPeriod==TA_INTEGER_DEFAULT)
/*Generated*/    optInSlowPeriod=26;
/*Generated*/  elseif(((int)optInSlowPeriod<2)||((int)optInSlowPeriod>100000))
/*Generated*/    returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  if((int)optInSignalPeriod==TA_INTEGER_DEFAULT)
/*Generated*/    optInSignalPeriod=9;
/*Generated*/  elseif(((int)optInSignalPeriod<1)||((int)optInSignalPeriod>100000))
/*Generated*/    returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  #if!defined(_JAVA)
/*Generated*/  if(!outMACD)
/*Generated*/    returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  if(!outMACDSignal)
/*Generated*/    returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  if(!outMACDHist)
/*Generated*/    returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  #endif 
/*Generated*/ #endif 
/*Generated*/  returnFUNCTION_CALL(INT_MACD)(startIdx,endIdx,inReal,
/*Generated*/                  optInFastPeriod,
/*Generated*/                  optInSlowPeriod,
/*Generated*/                  optInSignalPeriod,
/*Generated*/                  outBegIdx,
/*Generated*/                  outNBElement,
/*Generated*/                  outMACD,
/*Generated*/                  outMACDSignal,
/*Generated*/                  outMACDHist);
/*Generated*/}
/*Generated*/#ifdefined(_MANAGED)&&defined(USE_SUBARRAY)&&!defined(USE_SINGLE_PRECISION_INPUT)
/*Generated*/ enumclassCore::RetCodeCore::TA_INT_MACD(int  startIdx,
/*Generated*/                       int  endIdx,
/*Generated*/                       SubArray^inReal,
/*Generated*/                       int  optInFastPeriod, 
/*Generated*/                       int  optInSlowPeriod, 
/*Generated*/                       int  optInSignalPeriod_2,
/*Generated*/                       [Out]int%outBegIdx,
/*Generated*/                       [Out]int%outNBElement,
/*Generated*/                       cli::array<double>^outMACD,
/*Generated*/                       cli::array<double>^outMACDSignal,
/*Generated*/                       cli::array<double>^outMACDHist)
/*Generated*/#elifdefined(_MANAGED)
/*Generated*/ enumclassCore::RetCodeCore::TA_INT_MACD(int  startIdx,
/*Generated*/                       int  endIdx,
/*Generated*/                       cli::array<INPUT_TYPE>^inReal,
/*Generated*/                       int  optInFastPeriod, 
/*Generated*/                       int  optInSlowPeriod, 
/*Generated*/                       int  optInSignalPeriod_2,
/*Generated*/                       [Out]int%outBegIdx,
/*Generated*/                       [Out]int%outNBElement,
/*Generated*/                       cli::array<double>^outMACD,
/*Generated*/                       cli::array<double>^outMACDSignal,
/*Generated*/                       cli::array<double>^outMACDHist)
/*Generated*/#elifdefined(_JAVA)
/*Generated*/RetCodeTA_INT_MACD(int    startIdx,
/*Generated*/           int    endIdx,
/*Generated*/           INPUT_TYPEinReal[],
/*Generated*/           int    optInFastPeriod, 
/*Generated*/           int    optInSlowPeriod, 
/*Generated*/           int    optInSignalPeriod_2,
/*Generated*/           MInteger outBegIdx,
/*Generated*/           MInteger outNBElement,
/*Generated*/           double  outMACD[],
/*Generated*/           double  outMACDSignal[],
/*Generated*/           double  outMACDHist[])
/*Generated*/#else
/*Generated*/TA_RetCodeTA_PREFIX(INT_MACD)(int  startIdx,
/*Generated*/                int  endIdx,
/*Generated*/                constINPUT_TYPEinReal[],
/*Generated*/                int  optInFastPeriod, 
/*Generated*/                int  optInSlowPeriod, 
/*Generated*/                int  optInSignalPeriod_2,
/*Generated*/                int *outBegIdx,
/*Generated*/                int *outNBElement,
/*Generated*/                double   outMACD[],
/*Generated*/                double   outMACDSignal[],
/*Generated*/                double   outMACDHist[])
/*Generated*/#endif
/*Generated*/{
/*Generated*/  ARRAY_REF(slowEMABuffer);
/*Generated*/  ARRAY_REF(fastEMABuffer);
/*Generated*/  doublek1,k2;
/*Generated*/  ENUM_DECLARATION(RetCode)retCode;
/*Generated*/  inttempInteger;
/*Generated*/  VALUE_HANDLE_INT(outBegIdx1);
/*Generated*/  VALUE_HANDLE_INT(outNbElement1);
/*Generated*/  VALUE_HANDLE_INT(outBegIdx2);
/*Generated*/  VALUE_HANDLE_INT(outNbElement2);
/*Generated*/  intlookbackTotal,lookbackSignal;
/*Generated*/  inti;
/*Generated*/  if(optInSlowPeriod<optInFastPeriod)
/*Generated*/  {
/*Generated*/    tempInteger   =optInSlowPeriod;
/*Generated*/    optInSlowPeriod=optInFastPeriod;
/*Generated*/    optInFastPeriod=tempInteger;
/*Generated*/  }
/*Generated*/  if(optInSlowPeriod!=0)
/*Generated*/   k1=PER_TO_K(optInSlowPeriod);
/*Generated*/  else
/*Generated*/  {
/*Generated*/   optInSlowPeriod=26;
/*Generated*/   k1=(double)0.075; 
/*Generated*/  }
/*Generated*/  if(optInFastPeriod!=0)
/*Generated*/   k2=PER_TO_K(optInFastPeriod);
/*Generated*/  else
/*Generated*/  {
/*Generated*/   optInFastPeriod=12;
/*Generated*/   k2=(double)0.15; 
/*Generated*/  }
/*Generated*/  lookbackSignal=LOOKBACK_CALL(EMA)(optInSignalPeriod_2); 
/*Generated*/  lookbackTotal= lookbackSignal;
/*Generated*/  lookbackTotal+=LOOKBACK_CALL(EMA)(optInSlowPeriod);
/*Generated*/  if(startIdx<lookbackTotal)
/*Generated*/   startIdx=lookbackTotal;
/*Generated*/  if(startIdx>endIdx)
/*Generated*/  {
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
/*Generated*/   returnENUM_VALUE(RetCode,TA_SUCCESS,Success);
/*Generated*/  }
/*Generated*/  tempInteger=(endIdx-startIdx)+1+lookbackSignal;
/*Generated*/  ARRAY_ALLOC(fastEMABuffer,tempInteger);
/*Generated*/  #if!defined(_JAVA)
/*Generated*/   if(!fastEMABuffer)
/*Generated*/   {
/*Generated*/     VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
/*Generated*/     VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
/*Generated*/     returnENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr);
/*Generated*/   }
/*Generated*/  #endif
/*Generated*/  ARRAY_ALLOC(slowEMABuffer,tempInteger);
/*Generated*/  #if!defined(_JAVA)
/*Generated*/   if(!slowEMABuffer)
/*Generated*/   {
/*Generated*/     VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
/*Generated*/     VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
/*Generated*/     ARRAY_FREE(fastEMABuffer);
/*Generated*/     returnENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr);
/*Generated*/   }
/*Generated*/  #endif
/*Generated*/  tempInteger=startIdx-lookbackSignal;
/*Generated*/  retCode=FUNCTION_CALL(INT_EMA)(tempInteger,endIdx,
/*Generated*/                   inReal,optInSlowPeriod,k1,
/*Generated*/                   VALUE_HANDLE_OUT(outBegIdx1),VALUE_HANDLE_OUT(outNbElement1),slowEMABuffer);
/*Generated*/  if(retCode!=ENUM_VALUE(RetCode,TA_SUCCESS,Success))
/*Generated*/  {
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
/*Generated*/   ARRAY_FREE(fastEMABuffer);
/*Generated*/   ARRAY_FREE(slowEMABuffer);
/*Generated*/   returnretCode;
/*Generated*/  }
/*Generated*/  retCode=FUNCTION_CALL(INT_EMA)(tempInteger,endIdx,
/*Generated*/                   inReal,optInFastPeriod,k2,
/*Generated*/                   VALUE_HANDLE_OUT(outBegIdx2),VALUE_HANDLE_OUT(outNbElement2),fastEMABuffer);
/*Generated*/  if(retCode!=ENUM_VALUE(RetCode,TA_SUCCESS,Success))
/*Generated*/  {
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
/*Generated*/   ARRAY_FREE(fastEMABuffer);
/*Generated*/   ARRAY_FREE(slowEMABuffer);
/*Generated*/   returnretCode;
/*Generated*/  }
/*Generated*/  if((VALUE_HANDLE_GET(outBegIdx1)!=tempInteger)|| 
/*Generated*/    (VALUE_HANDLE_GET(outBegIdx2)!=tempInteger)|| 
/*Generated*/    (VALUE_HANDLE_GET(outNbElement1)!=VALUE_HANDLE_GET(outNbElement2))||
/*Generated*/    (VALUE_HANDLE_GET(outNbElement1)!=(endIdx-startIdx)+1+lookbackSignal))
/*Generated*/  {
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
/*Generated*/   ARRAY_FREE(fastEMABuffer);
/*Generated*/   ARRAY_FREE(slowEMABuffer);
/*Generated*/   returnTA_INTERNAL_ERROR(119);
/*Generated*/  }
/*Generated*/  for(i=0;i<VALUE_HANDLE_GET(outNbElement1);i++)
/*Generated*/   fastEMABuffer[i]=fastEMABuffer[i]-slowEMABuffer[i];
/*Generated*/  ARRAY_MEMMOVE(outMACD,0,fastEMABuffer,lookbackSignal,(endIdx-startIdx)+1);
/*Generated*/  retCode=FUNCTION_CALL_DOUBLE(INT_EMA)(0,VALUE_HANDLE_GET(outNbElement1)-1,
/*Generated*/                      fastEMABuffer,optInSignalPeriod_2,PER_TO_K(optInSignalPeriod_2), 
/*Generated*/                      VALUE_HANDLE_OUT(outBegIdx2),VALUE_HANDLE_OUT(outNbElement2),outMACDSignal);
/*Generated*/  ARRAY_FREE(fastEMABuffer);
/*Generated*/  ARRAY_FREE(slowEMABuffer);
/*Generated*/  if(retCode!=ENUM_VALUE(RetCode,TA_SUCCESS,Success))
/*Generated*/  {
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
/*Generated*/   VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
/*Generated*/   returnretCode;
/*Generated*/  }
/*Generated*/  for(i=0;i<VALUE_HANDLE_GET(outNbElement2);i++)
/*Generated*/   outMACDHist[i]=outMACD[i]-outMACDSignal[i];
/*Generated*/  VALUE_HANDLE_DEREF(outBegIdx)  =startIdx;
/*Generated*/  VALUE_HANDLE_DEREF(outNBElement) =VALUE_HANDLE_GET(outNbElement2);
/*Generated*/  returnENUM_VALUE(RetCode,TA_SUCCESS,Success);
/*Generated*/}
/*Generated*/ 
/*Generated*/#ifdefined(_MANAGED)
/*Generated*/}}}//ClosenamespaceTicTacTec.TA.Lib
/*Generated*/#endif

1 2  下一页

Tags:VC 开发 股票

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接