double * getAllPSAR(const double acceleration, const double maximum, CandleData * data, long numSticks)
{
	double * highData = 0;
	double * lowData = 0;

	highData = CandleData::getData(data, CandleData::HIGH, numSticks);
	lowData = CandleData::getData(data, CandleData::LOW, numSticks);

	int outNbElement = 0;
	int outBeg = 0;

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

	TA_RetCode atrRet =
		TA_SAR(0,
			  numSticks - 1,
			  highData,
			  lowData,
			  acceleration,
			  maximum,
			  &outBeg,
		      &outNbElement,
		      psarDataOut);

	double * ret = new double[outNbElement + outBeg];
	memset(ret,0,(outNbElement + outBeg) * sizeof(double));
	memcpy(&ret[outBeg],psarDataOut,outNbElement*sizeof(double));

	delete [] highData;
	delete [] lowData;
	delete [] psarDataOut;

	return ret;
}
Esempio n. 2
0
TA_RetCode TA_SAR_FramePP( TA_Libc            *libHandle,
                          TA_Integer          startIdx,
                          TA_Integer          endIdx,
                          TA_Integer         *outBegIdx,
                          TA_Integer         *outNbElement,
                          TA_ParamHolderPriv  in[],
                          TA_ParamHolderPriv  optIn[],
                          TA_ParamHolderPriv  out[] )
{
   return TA_SAR( libHandle,
            startIdx,
            endIdx,
            in[0].p.in.data.inReal, /* inReal_0 */
            optIn[0].p.optIn.data.optInInteger, /* optInTimePeriod_0 */
            outBegIdx, 
            outNbElement, 
            out[0].p.out.data.outReal /*  outReal_0 */ );
}
double getPSAR(const double acceleration, const double maximum, CandleData * data, long numSticks)
{
	double psar = 0.0;

	double * highData = 0;
	double * lowData = 0;
	highData = CandleData::getData(data, CandleData::HIGH, numSticks);
	lowData = CandleData::getData(data, CandleData::LOW, numSticks);

	int outNbElement = 0;
	int outBeg = 0;

	double * psarDataOut = new double[numSticks];

	TA_RetCode ret =
		TA_SAR( 0,
			  numSticks - 1,
			  highData,
			  lowData,
			  acceleration,
			  maximum,
			  &outBeg,
		      &outNbElement,
		      psarDataOut);

	if(outNbElement == 0)
	{
		psar = 0.0;
	}
	else
	{
		psar = psarDataOut[outNbElement - 1];
	}

	delete [] highData;
	delete [] lowData;
	delete [] psarDataOut;
	
	return psar;
}
Esempio n. 4
0
static ErrorNumber do_test( TA_Libc *libHandle,
                            const TA_History *history,
                            const TA_Test *test )
{
   TA_RetCode retCode;
   ErrorNumber errNb;
   TA_Integer outBegIdx;
   TA_Integer outNbElement;

   const TA_Real *highPtr;
   const TA_Real *lowPtr;
   TA_Integer nbPriceBar;

   /* Set to NAN all the elements of the gBuffers.  */
   clearAllBuffers();

   /* Build the input. */
   if( test->useWilderData )
   {
      highPtr = wilderHigh;
      lowPtr  = wilderLow;
      nbPriceBar = WILDER_NB_BAR;
   }
   else
   {
      highPtr = history->high;
      lowPtr  = history->low;
      nbPriceBar = history->nbBars;
   }

   setInputBuffer( 0, highPtr,  nbPriceBar );
   setInputBuffer( 1, lowPtr,   nbPriceBar );

   /* Make a simple first call. */
   retCode = TA_SAR( libHandle,
                     test->startIdx,
                     test->endIdx,
                     gBuffer[0].in,
                     gBuffer[1].in,
                     test->optInAcceleration,
                     test->optInMaximum,
                     &outBegIdx,
                     &outNbElement,
                     gBuffer[0].out0 );

   errNb = checkDataSame( gBuffer[0].in, highPtr, nbPriceBar );
   if( errNb != TA_TEST_PASS )
      return errNb;
   errNb = checkDataSame( gBuffer[1].in, lowPtr, nbPriceBar );
   if( errNb != TA_TEST_PASS )
      return errNb;

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

   outBegIdx = outNbElement = 0;

   /* Make another call where the input and the output are the
    * same buffer.
    */
   retCode = TA_SAR( libHandle,
                     test->startIdx,
                     test->endIdx,
                     gBuffer[0].in,
                     gBuffer[1].in,
                     test->optInAcceleration,
                     test->optInMaximum,
                     &outBegIdx,
                     &outNbElement,
                     gBuffer[1].in );

   /* 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[1].in );
   if( errNb != TA_TEST_PASS )
      return errNb;

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

   if( errNb != TA_TEST_PASS )
      return errNb;

   /* Make sure the other input is untouched. */
   errNb = checkDataSame( gBuffer[0].in, highPtr, nbPriceBar );
   if( errNb != TA_TEST_PASS )
      return errNb;

   /* Repeat that last test but with the first parameter this time. */

   /* Set to NAN all the elements of the gBuffers.  */
   clearAllBuffers();

   /* Build the input. */
   setInputBuffer( 0, highPtr,  nbPriceBar );
   setInputBuffer( 1, lowPtr,   nbPriceBar );

   /* Make another call where the input and the output are the
    * same buffer.
    */
   retCode = TA_SAR( libHandle,
                     test->startIdx,
                     test->endIdx,
                     gBuffer[0].in,
                     gBuffer[1].in,
                     test->optInAcceleration,
                     test->optInMaximum,
                     &outBegIdx,
                     &outNbElement,
                     gBuffer[0].in );

   /* 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;

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

   if( errNb != TA_TEST_PASS )
      return errNb;

   /* Make sure the other input is untouched. */
   errNb = checkDataSame( gBuffer[1].in, lowPtr, nbPriceBar);
   if( errNb != TA_TEST_PASS )
      return errNb;

   return TA_TEST_PASS;
}