예제 #1
0
Indicator * BARS::calculate ()
{
  Indicator *output = new Indicator;
  output->setDateFlag(dateFlag);
  output->setLogScale(logScale);

  if (! method.compare("OHLC"))
  {
    output->addLine(calculateOHLC());
    calculateMA(output);
  }

  if (! method.compare("Candle"))
  {
    output->addLine(calculateCandle());
    calculateMA(output);
  }

  if (! method.compare("HACandle"))
  {
    output->addLine(calculateHACandle());
    calculateMA(output);
  }

  if (! method.compare("PF"))
    output->addLine(calculatePF());

  return output;
}
예제 #2
0
Indicator * ExScript::calculate ()
{
  Indicator *output = new Indicator;
  output->setDateFlag(dateFlag);
  output->setLogScale(logScale);

  output->addLine(doScript());

  return output;
}
예제 #3
0
Indicator * THERM::calculate ()
{
  Indicator *output = new Indicator;
  output->setDateFlag(dateFlag);
  output->setLogScale(logScale);

  QPtrList<PlotLine> pll;
  pll.setAutoDelete(FALSE);
  getTHERM(pll);

  int loop;
  for (loop = 0; loop < (int) pll.count(); loop++)
    output->addLine(pll.at(loop));

  return output;
}
예제 #4
0
Indicator * LOWPASS::calculate ()
{
  Indicator *output = new Indicator;
  output->setDateFlag(dateFlag);
  output->setLogScale(logScale);

  PlotLine *in = data->getInput(input);
  if (! in)
  {
    qDebug("LOWPASS::calculate: no input");
    return output;
  }

  PlotLine *line = getLowpass(in, freq, width);
  line->setColor(color);
  line->setType(lineType);
  line->setLabel(label);
  output->addLine(line);
  delete in;
  return output;
}
예제 #5
0
Indicator * TALIB::calculate ()
{
  Indicator *output = new Indicator;
  output->setDateFlag(dateFlag);
  output->setLogScale(logScale);

  // open a TALIB handle
  const TA_FuncHandle *handle;
  QString ts = "method";
  QString ts2;
  parms.getData(ts, ts2);
  TA_RetCode retCode = TA_GetFuncHandle(ts2, &handle);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::calculate:can't open handle");
    return output;
  }

  // get info on the function
  const TA_FuncInfo *theInfo;
  retCode = TA_GetFuncInfo(handle, &theInfo);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::calculate:can't get function info");
    return output;
  }

  // create parm holder
  TA_ParamHolder *parmHolder;
  retCode = TA_ParamHolderAlloc(handle, &parmHolder);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::calculate:can't create parm holder");
    return output;
  }

  // create and populate the input arrays
  int loop = data->count();
  TA_Real open[loop];
  TA_Real high[loop];
  TA_Real low[loop];
  TA_Real close[loop];
  TA_Real volume[loop];
  TA_Real oi[loop];
  for (loop = 0; loop < data->count(); loop++)
  {
    open[loop] = (TA_Real) data->getOpen(loop);
    high[loop] = (TA_Real) data->getHigh(loop);
    low[loop] = (TA_Real) data->getLow(loop);
    close[loop] = (TA_Real) data->getClose(loop);
    volume[loop] = (TA_Real) data->getVolume(loop);
    oi[loop] = (TA_Real) data->getOI(loop);
  }

  // setup the input arrays
  const TA_InputParameterInfo *inputParms;
  for (loop = 0; loop < (int) theInfo->nbInput; loop++ )
  {
    TA_GetInputParameterInfo(theInfo->handle, loop, &inputParms);
    QString s;
    int tint = 3;
    switch (inputParms->type)
    {
      case TA_Input_Price:
        retCode = TA_SetInputParamPricePtr(parmHolder, loop, &open[0], &high[0], &low[0],
                                           &close[0], &volume[0], &oi[0]);
        if (retCode != TA_SUCCESS)
          qDebug("TALIB::calculate:cannot set input prices");
        break;
      case TA_Input_Real:
        s = QObject::tr("input") + QString::number(loop + 1);
        tint = parms.getInt(s);
        switch (tint)
        {
          case 0:
            retCode = TA_SetInputParamRealPtr(parmHolder, loop, &open[0]);
            if (retCode != TA_SUCCESS)
              qDebug("TALIB::calculate:cannot set real price");
            break;
          case 1:
            retCode = TA_SetInputParamRealPtr(parmHolder, loop, &high[0]);
            if (retCode != TA_SUCCESS)
              qDebug("TALIB::calculate:cannot set real price");
            break;
          case 2:
            retCode = TA_SetInputParamRealPtr(parmHolder, loop, &low[0]);
            if (retCode != TA_SUCCESS)
              qDebug("TALIB::calculate:cannot set real price");
            break;
          case 3:
            retCode = TA_SetInputParamRealPtr(parmHolder, loop, &close[0]);
            if (retCode != TA_SUCCESS)
              qDebug("TALIB::calculate:cannot set real price");
            break;
          case 4:
            retCode = TA_SetInputParamRealPtr(parmHolder, loop, &volume[0]);
            if (retCode != TA_SUCCESS)
              qDebug("TALIB::calculate:cannot set integer price");
            break;
          case 5:
            retCode = TA_SetInputParamRealPtr(parmHolder, loop, &oi[0]);
            if (retCode != TA_SUCCESS)
              qDebug("TALIB::calculate:cannot set integer price");
            break;
          default:
            break;
        }
        break;
      case TA_Input_Integer:
        break;
      default:
        break;
    }
  }

  // setup the optinput parms
  const TA_OptInputParameterInfo *optInfo;
  for (loop = 0; loop < (int) theInfo->nbOptInput; loop++ )
  {
    TA_GetOptInputParameterInfo(theInfo->handle, loop, &optInfo);
    QString s = optInfo->displayName;
    switch (optInfo->type)
    {
      case TA_OptInput_RealRange:
        retCode = TA_SetOptInputParamReal(parmHolder, loop, (TA_Real) parms.getDouble(s));
        if (retCode != TA_SUCCESS)
          qDebug("TALIB::calculate:cannot set inputopt real");
        break;
      case TA_OptInput_IntegerRange:
        retCode = TA_SetOptInputParamInteger(parmHolder, loop, (TA_Integer) parms.getInt(s));
        if (retCode != TA_SUCCESS)
          qDebug("TALIB::calculate:cannot set inputopt integer");
        break;
      case TA_OptInput_IntegerList:
        retCode = TA_SetOptInputParamInteger(parmHolder, loop, (TA_Integer) parms.getInt(s));
        if (retCode != TA_SUCCESS)
          qDebug("TALIB::calculate:cannot set inputopt integerlist");
        break;
      default:
        break;
    }
  }

  // setup the output arrays
  TA_Real out1[data->count()];
  TA_Real out2[data->count()];
  TA_Real out3[data->count()];
  TA_Integer out4[data->count()];
  const TA_OutputParameterInfo *outInfo;
  for (loop = 0; loop < (int) theInfo->nbOutput; loop++)
  {
    retCode = TA_GetOutputParameterInfo(handle, loop, &outInfo);
    if (retCode != TA_SUCCESS)
    {
      qDebug("TALIB::calculate:cannot get output info");
      continue;
    }

    switch (loop)
    {
      case 0:
        if (outInfo->type == TA_Output_Integer)
        {
          retCode = TA_SetOutputParamIntegerPtr(parmHolder, loop, &out4[0]);
          if (retCode != TA_SUCCESS)
            qDebug("TALIB::calculate:cannot set output4");
        }
        else
        {
          retCode = TA_SetOutputParamRealPtr(parmHolder, loop, &out1[0]);
          if (retCode != TA_SUCCESS)
            qDebug("TALIB::calculate:cannot set output1");
        }
        break;      
      case 1:
        retCode = TA_SetOutputParamRealPtr(parmHolder, loop, &out2[0]);
        if (retCode != TA_SUCCESS)
          qDebug("TALIB::calculate:cannot set output2");
        break;      
      case 2:
        retCode = TA_SetOutputParamRealPtr(parmHolder, loop, &out3[0]);
        if (retCode != TA_SUCCESS)
          qDebug("TALIB::calculate:cannot set output3");
        break;
      default:
        break;
    }
  }

  // call the function
  TA_Integer start = 0;
  TA_Integer end = data->count() - 1;
  TA_Integer outstart;
  TA_Integer count;
  retCode = TA_CallFunc(parmHolder, start, end, &outstart, &count);
  if (retCode != TA_SUCCESS)
    qDebug("TALIB::calculate:call function failed");
  else
  {
    // create the plotlines
    const TA_OutputParameterInfo *outInfo;
    for (loop = 0; loop < (int) theInfo->nbOutput; loop++ )
    {
      TA_GetOutputParameterInfo(theInfo->handle, loop, &outInfo);
      QString base = outInfo->paramName;
      base = base.right(base.length() - 3);
      if (! base.left(4).compare("Real"))
        base = base.right(base.length() - 4);
      if (! base.left(7).compare("Integer"))
        base = base.right(base.length() - 7);
      if (! base.length())
        base = QObject::tr("Plot");

      PlotLine *line = new PlotLine;

      QString s = base + " " + QObject::tr("Color");
      parms.getData(s, ts);
      QColor color(ts);
      line->setColor(color);

      s = base + " " + QObject::tr("Label");
      parms.getData(s, ts);
      line->setLabel(ts);

      s = base + " " + QObject::tr("Line Type");
      line->setType((PlotLine::LineType)parms.getInt(s));

      retCode = TA_GetOutputParameterInfo(handle, loop, &outInfo);
      if (retCode != TA_SUCCESS)
      {
        qDebug("TALIB::calculate:cannot get output info");
        delete line;
        continue;
      }

      int loop2;
      switch (loop)
      {
        case 0:
          if (outInfo->type == TA_Output_Integer)
          {
            for (loop2 = 0; loop2 < count; loop2++)
              line->append((double) out4[loop2]);
          }
          else
          {
            for (loop2 = 0; loop2 < count; loop2++)
              line->append((double) out1[loop2]);
          }
          break;      
        case 1:
          for (loop2 = 0; loop2 < count; loop2++)
            line->append((double) out2[loop2]);
          break;      
        case 2:
          for (loop2 = 0; loop2 < count; loop2++)
            line->append((double) out3[loop2]);
          break;
        default:
          break;
      }

      if (line->getType() == PlotLine::Histogram || line->getType() == PlotLine::HistogramBar)
        output->prependLine(line);
      else
        output->addLine(line);
    }
  }

  retCode = TA_ParamHolderFree(parmHolder);
  if (retCode != TA_SUCCESS)
    qDebug("TALIB::calculate:can't delete parm holder");

  return output;
}