void getSineAll(double *& outSine, double *& outLeadSine, CandleData * data, long numSticks)
{
    double * csData = CandleData::getData(data, CandleData::CLOSE, numSticks);

    int outNbElement = 0;
    int outBeg = 0;

    double * dataOut1 = new double[numSticks];
    memset(dataOut1,0,numSticks * sizeof(double));

    double * dataOut2 = new double[numSticks];
    memset(dataOut2,0,numSticks * sizeof(double));

    TA_RetCode ret =
        TA_HT_SINE( 0,
                    numSticks-1,
                    csData,
                    &outBeg,
                    &outNbElement,
                    dataOut1,
                    dataOut2);


    outSine = new double[numSticks + outBeg];
    memset(outSine,0,(numSticks + outBeg) * sizeof(double));
    memcpy(&outSine[outBeg],dataOut1,numSticks*sizeof(double));

    outLeadSine = new double[numSticks + outBeg];
    memset(outLeadSine,0,(numSticks + outBeg) * sizeof(double));
    memcpy(&outLeadSine[outBeg],dataOut2,numSticks*sizeof(double));

    delete [] csData;
    delete [] dataOut1;
    delete [] dataOut2;
}
void getSine(double outSine, double outLeadSine, CandleData * data, long numSticks)
{
    outSine = 0.0;
    outLeadSine = 0.0;

    double * csData = CandleData::getData(data, CandleData::CLOSE, numSticks);

    int outNbElement = 0;
    int outBeg = 0;

    double * dataOut1 = new double[numSticks];
    memset(dataOut1,0,numSticks * sizeof(double));
    double * dataOut2 = new double[numSticks];
    memset(dataOut2,0,numSticks * sizeof(double));

    TA_RetCode ret =
        TA_HT_SINE( 0,
                    numSticks-1,
                    csData,
                    &outBeg,
                    &outNbElement,
                    dataOut1,
                    dataOut2);


    if(outNbElement != 0)
    {
        outSine = dataOut1[outNbElement - 1];
        outLeadSine = dataOut2[outNbElement - 1];
    }

    delete [] csData;
    delete [] dataOut1;
    delete [] dataOut2;
}
Exemple #3
0
/**** Local functions definitions.     ****/
static TA_RetCode rangeTestFunction( 
                              TA_Integer startIdx,
                              TA_Integer endIdx,
                              TA_Real *outputBuffer,
                              TA_Integer *outBegIdx,
                              TA_Integer *outNbElement,
                              TA_Integer *lookback,
                              void *opaqueData,
                              unsigned int outputNb )
{
   TA_RetCode retCode;
   TA_RangeTestParam *testParam;
   TA_Real *out1;
   TA_Real *out2;
   TA_Real *dummyOutput;
   (void)outputNb;
  
   testParam = (TA_RangeTestParam *)opaqueData;   

   dummyOutput = TA_Malloc( (endIdx-startIdx+1) * sizeof(TA_Real) );
                     
   if( outputNb == 0 )
   {
      out1 = outputBuffer;
      out2 = dummyOutput;
   }
   else
   {
      out1 = dummyOutput;
      out2 = outputBuffer;
   }

   switch( testParam->test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( startIdx,
                              endIdx,
                              testParam->price,
                              outBegIdx,
                              outNbElement,                          
                              out1, out2 );
      *lookback = TA_HT_PHASOR_Lookback();
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( startIdx,
                            endIdx,
                            testParam->price,
                            outBegIdx,
                            outNbElement,                          
                            out1, out2 );
      *lookback = TA_HT_SINE_Lookback();
      break;
   default:
      retCode = TA_INTERNAL_ERROR(132);
   }

   TA_Free(dummyOutput);
   return retCode;
}
Exemple #4
0
static ErrorNumber do_test( const TA_History *history,
                            const TA_Test *test )
{
   TA_RetCode retCode;
   ErrorNumber errNb;
   TA_Integer outBegIdx;
   TA_Integer outNbElement;
   TA_RangeTestParam testParam;
   const TA_Real *referenceInput;

   /* 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 );
   setInputBuffer( 2, history->close,  history->nbBars );

   /* Change the input to MEDPRICE for some tests. */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
   case TA_HT_SINE_TEST:
      TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low,
                   &outBegIdx, &outNbElement, gBuffer[0].in );

      TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low,
                   &outBegIdx, &outNbElement, gBuffer[1].in );

      /* Will be use as reference */
      TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low,
                   &outBegIdx, &outNbElement, gBuffer[2].in );

      referenceInput = gBuffer[2].in;
      break;
   default:
      referenceInput = history->close;
   }

   /* Make a simple first call. */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( test->startIdx,
                              test->endIdx,
                              gBuffer[0].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[0].out0,
                              gBuffer[0].out1 );
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( test->startIdx,
                            test->endIdx,
                            gBuffer[0].in,
                            &outBegIdx,
                            &outNbElement,
                            gBuffer[0].out0,
                            gBuffer[0].out1 );
      break;
   default:
      retCode = TA_INTERNAL_ERROR(133);
   }

   /* Check that the inputs were preserved. */
   errNb = checkDataSame( gBuffer[0].in, referenceInput, history->nbBars );
   if( errNb != TA_TEST_PASS )
      return errNb;

   errNb = checkDataSame( gBuffer[1].in, referenceInput, history->nbBars );
   if( errNb != TA_TEST_PASS )
      return errNb;

   CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 );
   CHECK_EXPECTED_VALUE( gBuffer[0].out1, 1 );

   outBegIdx = outNbElement = 0;

   /* Make another call where the input and the output 
    * are the same buffer.
    */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( test->startIdx,
                              test->endIdx,
                              gBuffer[0].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[0].in,
                              gBuffer[1].out1
                            );
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( test->startIdx,
                            test->endIdx,
                            gBuffer[0].in,
                            &outBegIdx,
                            &outNbElement,
                            gBuffer[0].in,
                            gBuffer[1].out1
                          );
      break;
   default:
      retCode = TA_INTERNAL_ERROR(134);
   }

   /* The previous call should have the same output
    * as this call.
    *
    * checkSameContent verify that all value different than NAN in
    * the first parameter is identical in the second parameter.
    */
   errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in );
   if( errNb != TA_TEST_PASS )
      return errNb;

   errNb = checkSameContent( gBuffer[0].out1, gBuffer[1].out1 );
   if( errNb != TA_TEST_PASS )
      return errNb;

   CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 );
   CHECK_EXPECTED_VALUE( gBuffer[1].out1, 1 );

   /* Make another call where the input and the output 
    * are the same buffer.
    */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( test->startIdx,
                              test->endIdx,
                              gBuffer[1].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[1].out0,
                              gBuffer[1].in
                            );
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( test->startIdx,
                              test->endIdx,
                              gBuffer[1].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[1].out0,
                              gBuffer[1].in
                            );
      break;
   default:
      retCode = TA_INTERNAL_ERROR(134);
   }

   /* The previous call should have the same output
    * as this call.
    *
    * checkSameContent verify that all value different than NAN in
    * the first parameter is identical in the second parameter.
    */
   errNb = checkSameContent( gBuffer[0].out1, gBuffer[1].in );
   if( errNb != TA_TEST_PASS )
      return errNb;

   errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].out0 );
   if( errNb != TA_TEST_PASS )
      return errNb;

   CHECK_EXPECTED_VALUE( gBuffer[1].in, 1 );
   CHECK_EXPECTED_VALUE( gBuffer[1].out0, 0 );

   /* Do a systematic test of most of the
    * possible startIdx/endIdx range.
    */
   testParam.test  = test;
   testParam.price = referenceInput;

   if( test->doRangeTestFlag )
   {
      switch( test->theFunction )
      {
      case TA_HT_PHASOR_TEST:
         errNb = doRangeTest( rangeTestFunction, 
                              TA_FUNC_UNST_HT_PHASOR,
                              (void *)&testParam, 1, 0 );
         break;
      case TA_HT_SINE_TEST:
         errNb = doRangeTest( rangeTestFunction, 
                              TA_FUNC_UNST_HT_SINE,
                              (void *)&testParam, 1, 10 );
         break;

      default:
         errNb = doRangeTest( rangeTestFunction, 
                              TA_FUNC_UNST_NONE,
                              (void *)&testParam, 1, 0 );
      }
      if( errNb != TA_TEST_PASS )
         return errNb;
   }

   return TA_TEST_PASS;
}