📄 test_ma.c
字号:
{ 0, TA_ANY_MA_TEST, 0, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_DEFAULT, TA_SUCCESS, 1, 93.75, 9, 243 }, { 0, TA_ANY_MA_TEST, 0, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_DEFAULT, TA_SUCCESS, 20, 86.46, 9, 243 }, { 0, TA_ANY_MA_TEST, 0, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_DEFAULT, TA_SUCCESS, 242, 108.97, 9, 243 }, /* Last Value */ /*******************************/ /* EMA TEST - Metastock */ /*******************************/ /* No output value. */ { 0, TA_ANY_MA_TEST, 0, 1, 1, 14, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 0, 0, 0},#ifndef TA_FUNC_NO_RANGE_CHECK { 0, TA_ANY_MA_TEST, 0, 0, 251, 0, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_BAD_PARAM, 0, 0, 0, 0 },#endif /* Test with 1 unstable price bar. Test for period 2, 10 */ { 1, TA_ANY_MA_TEST, 1, 0, 251, 2, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 94.15, 1+1, 251-1 }, /* First Value */ { 0, TA_ANY_MA_TEST, 1, 0, 251, 2, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 94.78, 1+1, 251-1 }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 2, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 250-1, 108.21, 1+1, 251-1 }, /* Last Value */ { 1, TA_ANY_MA_TEST, 1, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 93.24, 9+1, 243-1 }, /* First Value */ { 0, TA_ANY_MA_TEST, 1, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 93.97, 9+1, 243-1 }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 20, 86.23, 9+1, 243-1 }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 242-1, 108.97, 9+1, 243-1 }, /* Last Value */ /* Test with 2 unstable price bar. Test for period 2, 10 */ { 0, TA_ANY_MA_TEST, 2, 0, 251, 2, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 94.78, 1+2, 251-2 }, /* First Value */ { 0, TA_ANY_MA_TEST, 2, 0, 251, 2, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 94.11, 1+2, 251-2 }, { 0, TA_ANY_MA_TEST, 2, 0, 251, 2, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 250-2, 108.21, 1+2, 251-2 }, /* Last Value */ { 0, TA_ANY_MA_TEST, 2, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 93.97, 9+2, 243-2 }, /* First Value */ { 0, TA_ANY_MA_TEST, 2, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 94.79, 9+2, 243-2 }, { 0, TA_ANY_MA_TEST, 2, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 20, 86.39, 9+2, 243-2 }, { 0, TA_ANY_MA_TEST, 2, 0, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 242-2, 108.97, 9+2, 243-2 }, /* Last Value */ /* Last 3 value with 1 unstable, period 10 */ { 0, TA_ANY_MA_TEST, 1, 249, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 109.22, 249, 3 }, { 0, TA_ANY_MA_TEST, 1, 249, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 2, 108.97, 249, 3 }, /* Last 3 value with 2 unstable, period 10 */ { 0, TA_ANY_MA_TEST, 2, 249, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 2, 108.97, 249, 3 }, /* Last 3 value with 3 unstable, period 10 */ { 0, TA_ANY_MA_TEST, 3, 249, 251, 10, TA_MAType_EMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 2, 108.97, 249, 3 }, /*******************************/ /* DEMA TEST - Metastock */ /*******************************/ /* No output value. */ { 0, TA_ANY_MA_TEST, 0, 1, 1, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 0, 0, 0},#ifndef TA_FUNC_NO_RANGE_CHECK { 0, TA_ANY_MA_TEST, 0, 0, 251, 0, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_BAD_PARAM, 0, 0, 0, 0 },#endif /* Test with period 14 */ { 0, TA_ANY_MA_TEST, 0, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 83.785, 26, 252-26 }, /* First Value */ { 0, TA_ANY_MA_TEST, 0, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 84.768, 26, 252-26 }, { 0, TA_ANY_MA_TEST, 0, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 252-27, 109.467, 26, 252-26 }, /* Last Value */ /* Test with 1 unstable price bar. Test for period 2, 14 */ { 1, TA_ANY_MA_TEST, 1, 0, 251, 2, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 93.960, 4, 252-4 }, /* First Value */ { 0, TA_ANY_MA_TEST, 1, 0, 251, 2, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 94.522, 4, 252-4 }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 2, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 252-5, 107.94, 4, 252-4 }, /* Last Value */ { 1, TA_ANY_MA_TEST, 1, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 84.91, (13*2)+2, 252-((13*2)+2) }, /* First Value */ { 0, TA_ANY_MA_TEST, 1, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 84.97, (13*2)+2, 252-((13*2)+2) }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 2, 84.80, (13*2)+2, 252-((13*2)+2) }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 3, 85.14, (13*2)+2, 252-((13*2)+2) }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 20, 89.83, (13*2)+2, 252-((13*2)+2) }, { 0, TA_ANY_MA_TEST, 1, 0, 251, 14, TA_MAType_DEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 252-((13*2)+2+1), 109.4676, (13*2)+2, 252-((13*2)+2) }, /* Last Value */ /*******************************/ /* TEMA TEST - Metastock */ /*******************************/ /* No output value. */ { 0, TA_ANY_MA_TEST, 0, 1, 1, 14, TA_MAType_TEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 0, 0, 0},#ifndef TA_FUNC_NO_RANGE_CHECK { 0, TA_ANY_MA_TEST, 0, 0, 251, 0, TA_MAType_TEMA, TA_COMPATIBILITY_METASTOCK, TA_BAD_PARAM, 0, 0, 0, 0 },#endif /* Test with period 14 */ { 1, TA_ANY_MA_TEST, 0, 0, 251, 14, TA_MAType_TEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 0, 84.721, 39, 252-39 }, /* First Value */ { 0, TA_ANY_MA_TEST, 0, 0, 251, 14, TA_MAType_TEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 1, 84.089, 39, 252-39 }, { 0, TA_ANY_MA_TEST, 0, 0, 251, 14, TA_MAType_TEMA, TA_COMPATIBILITY_METASTOCK, TA_SUCCESS, 252-40, 108.418, 39, 252-39 }, /* Last Value */};#define NB_TEST (sizeof(tableTest)/sizeof(TA_Test))/**** Global functions definitions. ****/ErrorNumber test_func_ma( TA_History *history ){ unsigned int i; ErrorNumber retValue; /* Re-initialize all the unstable period to zero. */ TA_SetUnstablePeriod( TA_FUNC_UNST_ALL, 0 ); for( i=0; i < NB_TEST; i++ ) { if( (int)tableTest[i].expectedNbElement > (int)history->nbBars ) { printf( "TA_MA Failed Bad Parameter for Test #%d (%d,%d)\n", i, tableTest[i].expectedNbElement, history->nbBars ); return TA_TESTUTIL_TFRR_BAD_PARAM; } retValue = do_test_ma( history, &tableTest[i], 0 ); if( retValue != 0 ) { printf( "TA_MA Failed Test #%d (Code=%d)\n", i, retValue ); return retValue; } /* If TA_ANY_MA_TEST. repeat test with TA_MAVP */ if( tableTest[i].id == TA_ANY_MA_TEST ) { retValue = do_test_ma( history, &tableTest[i], 1 ); if( retValue != 0 ) { printf( "TA_MAVP Failed Test #%d (Code=%d)\n", i, retValue ); return retValue; } } } /* Re-initialize all the unstable period to zero. */ TA_SetUnstablePeriod( TA_FUNC_UNST_ALL, 0 ); /* All test succeed. */ return TA_TEST_PASS; }/**** Local functions definitions. ****/static TA_RetCode rangeTestFunction( TA_Integer startIdx, TA_Integer endIdx, TA_Real *outputBuffer, TA_Integer *outputBufferInt, TA_Integer *outBegIdx, TA_Integer *outNbElement, TA_Integer *lookback, void *opaqueData, unsigned int outputNb, unsigned int *isOutputInteger ){ TA_RetCode retCode; TA_RangeTestParam *testParam; TA_Real *dummyBuffer; (void)outputBufferInt; *isOutputInteger = 0; testParam = (TA_RangeTestParam *)opaqueData; switch( testParam->test->optInMAType_1 ) { case TA_MAType_MAMA: dummyBuffer = TA_Malloc( sizeof(TA_Real)*(endIdx-startIdx+600) ); if( outputNb == 0 ) { retCode = TA_MAMA( startIdx, endIdx, testParam->close, 0.5, 0.05, outBegIdx, outNbElement, outputBuffer, &dummyBuffer[300] ); } else { retCode = TA_MAMA( startIdx, endIdx, testParam->close, 0.5, 0.05, outBegIdx, outNbElement, &dummyBuffer[300], outputBuffer ); } TA_Free( dummyBuffer ); *lookback = TA_MAMA_Lookback( 0.5, 0.05 ); break; default: if( testParam->testMAVP ) { retCode = TA_MAVP( startIdx, endIdx, testParam->close, testParam->mavpPeriod, 2,testParam->test->optInTimePeriod, (TA_MAType)testParam->test->optInMAType_1, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_MAVP_Lookback( 2, testParam->test->optInTimePeriod, (TA_MAType)testParam->test->optInMAType_1 ); } else { /* Test for the TA_MA function. All the MA can be done * through that function. */ retCode = TA_MA( startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod, (TA_MAType)testParam->test->optInMAType_1, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_MA_Lookback( testParam->test->optInTimePeriod, (TA_MAType)testParam->test->optInMAType_1 ); } break; } return retCode;}static ErrorNumber do_test_ma( const TA_History *history, const TA_Test *test, int testMAVP ){ TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; TA_Integer temp, temp2; const TA_Real *referenceInput; /* TA_MAVP is tested only for TA_ANY_MA_TEST */ if( testMAVP && (test->id != TA_ANY_MA_TEST) ) { return TA_TEST_PASS; } TA_SetCompatibility( (TA_Compatibility)test->compatibility ); /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); if( testMAVP ) { setInputBufferValue( 2, test->optInTimePeriod, history->nbBars ); } /* Re-initialize all the unstable period to zero. */ TA_SetUnstablePeriod( TA_FUNC_UNST_ALL, 0 ); /* Set the unstable period requested for that test. */ switch( test->optInMAType_1 ) { case TA_MAType_TEMA: case TA_MAType_DEMA: case TA_MAType_EMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_EMA, test->unstablePeriod ); break; case TA_MAType_KAMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_KAMA, test->unstablePeriod ); break; case TA_MAType_MAMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MAMA, test->unstablePeriod ); break; case TA_MAType_T3:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -