Esempio n. 1
0
void TALIB::setDefaults ()
{
  getIndicatorList(methodList);

  TA_RetCode rc = TA_Initialize();
  if (rc != TA_SUCCESS)
    qDebug("TALIB::setDefaults:error on TA_Initialize");
}
Esempio n. 2
0
int
RSI::getMA (QString inKey, QString outKey, int type, int period)
{
  if (! g_symbol)
    return 0;
  
  TA_RetCode rc = TA_Initialize();
  if (rc != TA_SUCCESS)
    qDebug() << "RSI::getMA: error on TA_Initialize";

  QList<int> keys = g_symbol->keys();

  TA_Real input[MAX_SIZE];
  TA_Real out[MAX_SIZE];
  TA_Integer outBeg;
  TA_Integer outNb;

  int dpos = 0;
  for (int kpos = 0; kpos < keys.size(); kpos++)
  {
    CBar *bar = g_symbol->bar(keys.at(kpos));
    
    double v;
    if (! bar->get(inKey, v))
      continue;
    
    input[dpos++] = (TA_Real) v;
  }

  rc = TA_MA(0, dpos - 1, &input[0], period, (TA_MAType) type, &outBeg, &outNb, &out[0]);
  
  if (rc != TA_SUCCESS)
  {
    qDebug() << "RSI::getMA: TA-Lib error" << rc;
    return 0;
  }

  int keyLoop = keys.size() - 1;
  int outLoop = outNb - 1;
  while (keyLoop > -1 && outLoop > -1)
  {
    CBar *bar = g_symbol->bar(keys.at(keyLoop));
    bar->set(outKey, out[outLoop]);
    keyLoop--;
    outLoop--;
  }
  
  return 1;
}
Esempio n. 3
0
/**** Global functions definitions.   ****/
ErrorNumber allocLib( TA_UDBase **uDBasePtr )
{
   TA_InitializeParam initializeParam;
   TA_RetCode retCode;
   TA_UDBase *uDBase;

   /* Initialize the library. */
   memset( &initializeParam, 0, sizeof( TA_InitializeParam ) );
   initializeParam.logOutput = stdout;

   retCode = TA_Initialize( &initializeParam );
   if( retCode != TA_SUCCESS )
   {
      printf( "TA_Initialize failed [%d]\n", retCode );
      return TA_TESTUTIL_INIT_FAILED;
   }
   
   /* Install a fatal error handler. */
   retCode = TA_SetFatalErrorHandler( myFatalHandler );
   if( retCode != TA_SUCCESS )
   {
      printf( "TA_SetFatalErrorHandler failed [%d]\n", retCode );
      TA_Shutdown();
      return TA_TESTUTIL_SET_FATAL_ERROR_FAILED;
   }
      
   /* Create an unified database. */
   retCode = TA_UDBaseAlloc( &uDBase );
   if( retCode != TA_SUCCESS )
   {
      printf( "TA_UDBaseAlloc failed [%d]\n", retCode );
      TA_Shutdown();
      return TA_TESTUTIL_UDBASE_ALLOC_FAILED;
   }

   *uDBasePtr = uDBase;

   return TA_TEST_PASS;
}
Esempio n. 4
0
int main( int argc, char **argv )
{
   TA_RetCode retCode;
   int retValue;

   /* Verify the parameters. */
   if( argc != 2 )
   {
      print_usage( "Bad Parameter" );
      return -1;
   }

   /* Initialize TA-LIB. */
   retCode = TA_Initialize( NULL );
   if( retCode != TA_SUCCESS )
   {
      print_error( retCode );
      return -1;
   }

   /* Fetch and display the WebPage. */
   retCode = TA_WebFetch( argv[1], stdout );

   if( retCode != TA_SUCCESS )
   {
      print_error( retCode );
      retValue = -1;
   }
   else
      retValue = 0;
      
   /* Clean-up and exit. */
   TA_Shutdown();

   return retValue;
}
Esempio n. 5
0
int
AROON::getAROON (int period, QString ukey, QString dkey)
{
  if (! g_symbol)
    return 0;

  TA_RetCode rc = TA_Initialize();
  if (rc != TA_SUCCESS)
    qDebug() << "AROON::AROON: error on TA_Initialize";

  QList<int> keys = g_symbol->keys();

  TA_Real high[MAX_SIZE];
  TA_Real low[MAX_SIZE];
  TA_Real out[MAX_SIZE];
  TA_Real out2[MAX_SIZE];
  TA_Integer outBeg;
  TA_Integer outNb;

  BarType bt;
  QString highKey = bt.indexToString(BarType::_HIGH);
  QString lowKey = bt.indexToString(BarType::_LOW);

  int dpos = 0;
  for (int kpos = 0; kpos < keys.size(); kpos++)
  {
    CBar *bar = g_symbol->bar(keys.at(kpos));

    double h;
    if (! bar->get(highKey, h))
      continue;

    double l;
    if (! bar->get(lowKey, l))
      continue;

    high[dpos] = (TA_Real) h;
    low[dpos] = (TA_Real) l;
    dpos++;
  }

  rc = TA_AROON(0, dpos - 1, &high[0], &low[0], period, &outBeg, &outNb, &out[0], &out2[0]);

  if (rc != TA_SUCCESS)
  {
    qDebug() << "AROON::getAROON: TA-Lib error" << rc;
    return 0;
  }

  int keyLoop = keys.size() - 1;
  int outLoop = outNb - 1;
  while (keyLoop > -1 && outLoop > -1)
  {
    CBar *bar = g_symbol->bar(keys.at(keyLoop));
    bar->set(dkey, out[outLoop]);
    bar->set(ukey, out2[outLoop]);
    keyLoop--;
    outLoop--;
  }

  return 1;
}
Esempio n. 6
0
Datum ta_f( PG_FUNCTION_ARGS)
{

	// Declare for TA
	TA_RetCode retCode;
	TA_Real *closePrice = NULL;
	TA_Real *out;

	TA_Integer outBeg;
	TA_Integer outNbElement;

	// Declare for postgres
	FuncCallContext *funcctx;
	int call_cntr;
	int max_calls;
	Datum *result = NULL;
	int dim;
	int z;
	ArrayType *ur = PG_GETARG_ARRAYTYPE_P(0);

	if (array_contains_nulls(ur))
	{
		ereport(ERROR,
				( errcode(ERRCODE_ARRAY_ELEMENT_ERROR), errmsg("cannot work with arrays containing NULLs") ));
	}

	dim = ARRNELEMS(ur);
	closePrice = ARRPTR(ur);

	if (SRF_IS_FIRSTCALL())
	{
		MemoryContext oldcontext;

		funcctx = SRF_FIRSTCALL_INIT();
		oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
		/* One-time setup code appears here: */
		retCode = TA_Initialize();
		if (retCode != TA_SUCCESS)
		{
			ereport(ERROR,
					( errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("Cannot initialize TA-Lib (%d)!\n", retCode) ));
		}

		out = palloc(dim * sizeof(TA_Real));

		retCode = TA_MA(0, dim - 1, &closePrice[0], 5, TA_MAType_SMA, &outBeg,
				&outNbElement, &out[0]);

		result = palloc(outNbElement * sizeof(Datum));

		// Error log for debugging
		/*
		ereport(NOTICE,
				(errmsg("dims %d,  outBeg: %d, outNbElement %d\n", dim, outBeg, outNbElement)));
		*/
		for (z = 0; z < dim; z++)
		{
			// Error log for debugging
			//ereport(NOTICE, (errmsg("z: %d, out[z]: %5.1f", z, out[z])));
			if(z > outBeg-1) {
				result[z] = Float8GetDatum(out[z-outBeg]);
				continue;
			}
			result[z] = NULL;
		}
		TA_Shutdown();

		funcctx->max_calls = dim;
		funcctx->user_fctx = result;
		MemoryContextSwitchTo(oldcontext);
	}

	/* stuff done on every call of the function */
	funcctx = SRF_PERCALL_SETUP();

	call_cntr = funcctx->call_cntr;
	max_calls = funcctx->max_calls;

	if (call_cntr < max_calls)
	{
		if(((Datum *) funcctx->user_fctx)[call_cntr]) {
			SRF_RETURN_NEXT(funcctx, ((Datum *) funcctx->user_fctx)[call_cntr]);
		}
		SRF_RETURN_NEXT_NULL(funcctx);
	}
	SRF_RETURN_DONE(funcctx);
}
Esempio n. 7
0
static ErrorNumber testHistoryAlloc( void )
{
   TA_UDBase *unifiedDatabase;
   TA_History *data;
   TA_RetCode retCode;
   TA_InitializeParam param;
   TA_AddDataSourceParam addParam;
   TA_HistoryAllocParam histParam;

   memset( &param, 0, sizeof( TA_InitializeParam ) );
   param.logOutput = stdout;
   retCode = TA_Initialize( &param );

   if( retCode != TA_SUCCESS )
   {
      printf( "Cannot initialize TA-LIB (%d)!", retCode );
      return TA_REGTEST_HISTORYALLOC_0;
   }

   /* Create an unified database. */
   if( TA_UDBaseAlloc( &unifiedDatabase ) != TA_SUCCESS )
   {
      TA_Shutdown();
      return TA_REGTEST_HISTORYALLOC_1;
   }
   
   /* USE SIMULATOR DATA */
   memset( &addParam, 0, sizeof( TA_AddDataSourceParam ) );
   addParam.id = TA_SIMULATOR;

   addParam.flags = TA_NO_FLAGS;
   retCode = TA_AddDataSource( unifiedDatabase, &addParam );

   /* Now, display all daily close price available
    * for the DAILY_REF_0 symbol.
    */
   if( retCode != TA_SUCCESS )
      return TA_REGTEST_ADDDSOURCE_FAILED;

   #if defined __BORLANDC__
      #pragma warn -ccc
      #pragma warn -rch
   #endif
      
   #define CHECK_FIELDSUBSET(field_par) \
         { \
            memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) ); \
            histParam.category = "TA_SIM_REF"; \
            histParam.symbol   = "DAILY_REF_0"; \
            histParam.field    = field_par; \
            histParam.period   = TA_DAILY; \
            retCode = TA_HistoryAlloc( unifiedDatabase, &histParam, &data ); \
            if( retCode == TA_SUCCESS ) \
            { \
               if( (field_par) & TA_OPEN ) \
               { \
                  if( !data->open ) \
                     return TA_REGTEST_HISTORYALLOC_2; \
                  if( data->open[0] != 92.5 ) \
                     return TA_REGTEST_HISTORYALLOC_3; \
               } \
               else \
               { \
                  if( data->open ) \
                     return TA_REGTEST_HISTORYALLOC_4; \
               } \
               if( (field_par) & TA_HIGH ) \
               { \
                  if( !data->high ) \
                     return TA_REGTEST_HISTORYALLOC_5; \
                  if( data->high[0] != 93.25 ) \
                     return TA_REGTEST_HISTORYALLOC_6; \
               } \
               else \
               { \
                  if( data->high ) \
                     return TA_REGTEST_HISTORYALLOC_7; \
               } \
               if( (field_par) & TA_LOW ) \
               { \
                  if( !data->low ) \
                     return TA_REGTEST_HISTORYALLOC_8; \
                  if( data->low[0] != 90.75 ) \
                     return TA_REGTEST_HISTORYALLOC_9; \
               } \
               else \
               { \
                  if( data->low ) \
                     return TA_REGTEST_HISTORYALLOC_10; \
               } \
               if( (field_par) & TA_CLOSE ) \
               { \
                  if( !data->close ) \
                     return TA_REGTEST_HISTORYALLOC_11; \
                  if( data->close[0] != 91.50 ) \
                     return TA_REGTEST_HISTORYALLOC_12; \
               } \
               else \
               { \
                  if( data->close ) \
                     return TA_REGTEST_HISTORYALLOC_13; \
               } \
               if( (field_par) & TA_VOLUME ) \
               { \
                  if( !data->volume ) \
                     return TA_REGTEST_HISTORYALLOC_14; \
                  if( data->volume[0] != 4077500) \
                     return TA_REGTEST_HISTORYALLOC_15; \
               } \
               else \
               { \
                  if( data->volume ) \
                     return TA_REGTEST_HISTORYALLOC_16; \
               } \
               if( (field_par) & TA_TIMESTAMP ) \
               { \
                  if( !data->timestamp ) \
                     return TA_REGTEST_HISTORYALLOC_17; \
               } \
               else \
               { \
                  if( data->timestamp ) \
                     return TA_REGTEST_HISTORYALLOC_18; \
               } \
               TA_HistoryFree( data ); \
            } \
            else \
            { \
               printf( "Cannot TA_HistoryAlloc for TA_SIM_REF (%d)!\n", retCode ); \
               return TA_REGTEST_HISTORYALLOC_19; \
            } \
         } 
         /* 6 Fields */
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)

         /* 5 Fields */
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_HIGH|TA_VOLUME)

         /* 4 Fields */
         CHECK_FIELDSUBSET(TA_CLOSE|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_LOW)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE|TA_HIGH)

         /* 3 Fields */
         CHECK_FIELDSUBSET(TA_HIGH|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_CLOSE|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_CLOSE|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_CLOSE|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_OPEN|TA_LOW|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH|TA_LOW)

         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_VOLUME)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_LOW)

         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE|TA_HIGH)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_HIGH)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_LOW)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_LOW)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_LOW|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_LOW|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE|TA_VOLUME)

         /* Two field. */
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_OPEN)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_HIGH)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_LOW)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_TIMESTAMP|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_OPEN|TA_HIGH)
         CHECK_FIELDSUBSET(TA_OPEN|TA_LOW)
         CHECK_FIELDSUBSET(TA_OPEN|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_OPEN|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_HIGH|TA_LOW)
         CHECK_FIELDSUBSET(TA_HIGH|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_HIGH|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_LOW|TA_CLOSE)
         CHECK_FIELDSUBSET(TA_LOW|TA_VOLUME)

         CHECK_FIELDSUBSET(TA_CLOSE|TA_VOLUME)

         /* One Field */
         CHECK_FIELDSUBSET(TA_TIMESTAMP);
         CHECK_FIELDSUBSET(TA_OPEN);
         CHECK_FIELDSUBSET(TA_HIGH)
         CHECK_FIELDSUBSET(TA_LOW)
         CHECK_FIELDSUBSET(TA_CLOSE)
         CHECK_FIELDSUBSET(TA_VOLUME)

   #undef CHECK_FIELDSUBSET

   /* Clean-up and exit. */
   TA_UDBaseFree( unifiedDatabase );
   TA_Shutdown();
   return TA_SUCCESS;
}
Esempio n. 8
0
void Init_talib()
{
  TA_Initialize();

  /*
   * Ruby extension for technical functions library api.
   */
  rb_mTaLib = rb_define_module("TaLib");

  rb_define_const(rb_mTaLib, "TA_Input_Price", INT2FIX(TA_Input_Price));
  rb_define_const(rb_mTaLib, "TA_Input_Real", INT2FIX(TA_Input_Real));
  rb_define_const(rb_mTaLib, "TA_Input_Integer", INT2FIX(TA_Input_Integer));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_OPEN", INT2FIX(TA_IN_PRICE_OPEN));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_HIGH", INT2FIX(TA_IN_PRICE_HIGH));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_LOW", INT2FIX(TA_IN_PRICE_LOW));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_CLOSE", INT2FIX(TA_IN_PRICE_CLOSE));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_VOLUME", INT2FIX(TA_IN_PRICE_VOLUME));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_OPENINTEREST", INT2FIX(TA_IN_PRICE_OPENINTEREST));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_TIMESTAMP", INT2FIX(TA_IN_PRICE_TIMESTAMP));
  rb_define_const(rb_mTaLib, "TA_OptInput_RealRange", INT2FIX(TA_OptInput_RealRange));
  rb_define_const(rb_mTaLib, "TA_OptInput_RealList", INT2FIX(TA_OptInput_RealList));
  rb_define_const(rb_mTaLib, "TA_OptInput_IntegerRange", INT2FIX(TA_OptInput_IntegerRange));
  rb_define_const(rb_mTaLib, "TA_OptInput_IntegerList", INT2FIX(TA_OptInput_IntegerList));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_PERCENT", INT2FIX(TA_OPTIN_IS_PERCENT));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_DEGREE", INT2FIX(TA_OPTIN_IS_DEGREE));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_CURRENCY", INT2FIX(TA_OPTIN_IS_CURRENCY));
  rb_define_const(rb_mTaLib, "TA_OPTIN_ADVANCED", INT2FIX(TA_OPTIN_ADVANCED));
  rb_define_const(rb_mTaLib, "TA_Output_Real", INT2FIX(TA_Output_Real));
  rb_define_const(rb_mTaLib, "TA_Output_Integer", INT2FIX(TA_Output_Integer));
  rb_define_const(rb_mTaLib, "TA_OUT_LINE", INT2FIX(TA_OUT_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DOT_LINE", INT2FIX(TA_OUT_DOT_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DASH_LINE", INT2FIX(TA_OUT_DASH_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DOT", INT2FIX(TA_OUT_DOT));
  rb_define_const(rb_mTaLib, "TA_OUT_HISTO", INT2FIX(TA_OUT_HISTO));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_BOOL", INT2FIX(TA_OUT_PATTERN_BOOL));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_BULL_BEAR", INT2FIX(TA_OUT_PATTERN_BULL_BEAR));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_STRENGTH", INT2FIX(TA_OUT_PATTERN_STRENGTH));
  rb_define_const(rb_mTaLib, "TA_OUT_POSITIVE", INT2FIX(TA_OUT_POSITIVE));
  rb_define_const(rb_mTaLib, "TA_OUT_NEGATIVE", INT2FIX(TA_OUT_NEGATIVE));
  rb_define_const(rb_mTaLib, "TA_OUT_ZERO", INT2FIX(TA_OUT_ZERO));
  rb_define_const(rb_mTaLib, "TA_OUT_UPPER_LIMIT", INT2FIX(TA_OUT_UPPER_LIMIT));
  rb_define_const(rb_mTaLib, "TA_OUT_LOWER_LIMIT", INT2FIX(TA_OUT_LOWER_LIMIT));
  rb_define_const(rb_mTaLib, "TA_MAType_SMA", INT2FIX((int)(TA_MAType_SMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_EMA", INT2FIX((int)(TA_MAType_EMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_WMA", INT2FIX((int)(TA_MAType_WMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_DEMA", INT2FIX((int)(TA_MAType_DEMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_TEMA", INT2FIX((int)(TA_MAType_TEMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_TRIMA", INT2FIX((int)(TA_MAType_TRIMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_KAMA", INT2FIX((int)(TA_MAType_KAMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_MAMA", INT2FIX((int)(TA_MAType_MAMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_T3", INT2FIX((int)(TA_MAType_T3)));

  rb_struct_define("TA_RealRange", "min", "max", "precision", NULL);
  rb_struct_define("TA_IntegerRange", "min", "max", NULL );
  rb_struct_define("TA_RealDataPair", "value", "string", NULL );
  rb_struct_define("TA_IntegerDataPair", "value", "string", NULL );
  rb_struct_define("TA_RealList", "data", "nb_element", NULL );
  rb_struct_define("TA_IntegerList", "data", "nb_element", NULL );

  rb_sInParamInfo = rb_struct_define("TA_InputParameterInfo", "type", "param_name", "flags", NULL );
  rb_sOptInParamInfo = rb_struct_define("TA_OutInputParameterInfo", "type", "param_name", "flags", "display_name", "data_set", "default_value", "hint", "help_file", NULL );
  rb_sOutParamInfo = rb_struct_define("TA_OutputParameterInfo", "type", "param_name", "flags", NULL );

  /*
   * Class for technical analysis function.
   */
  rb_cTAFunction = rb_define_class_under(rb_mTaLib, "Function", rb_cObject);
  rb_define_alloc_func(rb_cTAFunction, ta_func_alloc);
  rb_define_method(rb_cTAFunction, "initialize", ta_func_initialize, 1);
  rb_define_attr(rb_cTAFunction, "result", 1, 1);

  rb_define_module_function( rb_cTAFunction, "groups",          ta_func_get_groups,             0 );
  rb_define_module_function( rb_cTAFunction, "functions", ta_func_get_functions,        0 );

  rb_define_method( rb_cTAFunction, "ins",  ta_func_get_input_count,                      0 );
  rb_define_method( rb_cTAFunction, "outs", ta_func_get_output_count,             0 );
  rb_define_method( rb_cTAFunction, "opts", ta_func_get_option_input_count, 0 );

  rb_define_method( rb_cTAFunction, "in",  ta_func_input_param_info,  1);
  rb_define_method( rb_cTAFunction, "opt", ta_func_option_param_info, 1);
  rb_define_method( rb_cTAFunction, "out", ta_func_output_param_info, 1);

  rb_define_method( rb_cTAFunction, "in_int",   ta_func_setup_in_integer, 2);
  rb_define_method( rb_cTAFunction, "in_real",  ta_func_setup_in_real,          2);
  rb_define_method( rb_cTAFunction, "in_price",   ta_func_setup_in_price, 7);
  rb_define_method( rb_cTAFunction, "opt_int",  ta_func_setup_opt_in_integer, 2);
  rb_define_method( rb_cTAFunction, "opt_real", ta_func_setup_opt_in_real,              2);
  rb_define_method( rb_cTAFunction, "out_int",  ta_func_setup_out_integer,              2);
  rb_define_method( rb_cTAFunction, "out_real", ta_func_setup_out_real,                         2);

  rb_define_method( rb_cTAFunction, "lookback", ta_func_lookback, 0);
  rb_define_method( rb_cTAFunction, "call", ta_func_call, 2);
}