コード例 #1
0
ファイル: THERM.cpp プロジェクト: botvs/FinancialAnalytics
PlotLine * THERM::calculateCustom (QString &p, QPtrList<PlotLine> &d)
{
  // format1: MA_TYPE, MA_PERIOD, THRESHOLD, SMOOTHING_TYPE, SMOOTHING_PERIOD

  if (checkFormat(p, d, 5, 5))
    return 0;

  QStringList mal;
  getMATypes(mal);
  maType = mal.findIndex(formatStringList[0]);
  maPeriod = formatStringList[1].toInt();
  threshold = formatStringList[2].toDouble();
  smoothType = mal.findIndex(formatStringList[3]);
  smoothing = formatStringList[4].toInt();

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

  int loop;
  for (loop = pll.count() - 1; loop > 0; loop--)
    pll.remove(loop);

  return pll.at(0);
}
コード例 #2
0
ファイル: THERM.cpp プロジェクト: botvs/FinancialAnalytics
void THERM::formatDialog (QStringList &, QString &rv, QString &rs)
{
  rs.truncate(0);
  rv.truncate(0);
  QString pl = QObject::tr("Parms");
  QString vnl = QObject::tr("Variable Name");
  QString tl = QObject::tr("Threshold");
  QString sl = QObject::tr("Smoothing");
  QString stl = QObject::tr("Smoothing Type");
  QString mpl = QObject::tr("MA Period");
  QString mtl = QObject::tr("MA Type");
  PrefDialog *dialog = new PrefDialog(0);
  dialog->setCaption(QObject::tr("THERM Format"));
  dialog->createPage (pl);
  dialog->setHelpFile(helpFile);

  QString s;
  QStringList l;
  getMATypes(l);
  dialog->addTextItem(vnl, pl, s);
  dialog->addComboItem(mtl, pl, l, maType);
  dialog->addIntItem(mpl, pl, maPeriod, 0, 99999999);
  dialog->addDoubleItem(tl, pl, threshold, 1, 99999999);
  dialog->addComboItem(stl, pl, l, smoothType);
  dialog->addIntItem(sl, pl, smoothing, 0, 99999999);

  int rc = dialog->exec();
  
  if (rc == QDialog::Accepted)
  {
    dialog->getText(vnl, rv);

    dialog->getCombo(mtl, rs);

    int t = dialog->getInt(mpl);
    rs.append("," + QString::number(t));

    double d = dialog->getDouble(tl);
    rs.append("," + QString::number(d));

    dialog->getCombo(stl, s);
    rs.append("," + s);

    t = dialog->getInt(sl);
    rs.append("," + QString::number(t));
  }

  delete dialog;
}
コード例 #3
0
bool IndicatorPlugin::checkFormat (QString &p, QPtrList<PlotLine> &d, int hrange, int lrange)
{
  formatStringList = QStringList::split(",", p, FALSE);

  if ((int) formatStringList.count() < lrange || (int) formatStringList.count() > hrange)
  {
    qDebug("%s::checkFormat: invalid parm count", pluginName.latin1());
    return TRUE;
  }

  int loop;
  for (loop = 0; loop < (int) formatList.count(); loop++)
  {
    if (formatList[loop] == FormatInputArray)
    {
      if (! d.count())
      {
        qDebug("%s::checkFormat: parm #%i invalid, no INPUT_ARRAY found", pluginName.latin1(), loop+1);
        return TRUE;
      }
      continue;
    }

    if (formatList[loop] == FormatInputArray2)
    {
      if (d.count() != 2)
      {
        qDebug("%s::checkFormat: parm #%i invalid, no INPUT_ARRAY2 found", pluginName.latin1(), loop+1);
        return TRUE;
      }
      continue;
    }

    if (formatList[loop] == FormatInteger)
    {
      bool ok;
      formatStringList[loop].toInt(&ok);
      if (! ok)
      {
        qDebug("%s::checkFormat: parm #%i invalid, not an INTEGER", pluginName.latin1(), loop + 1);
        return TRUE;
      }
      continue;
    }

    if (formatList[loop] == FormatDouble)
    {
      bool ok;
      formatStringList[loop].toDouble(&ok);
      if (! ok)
      {
        qDebug("%s::checkFormat: parm #%i invalid, not a DOUBLE", pluginName.latin1(), loop + 1);
        return TRUE;
      }
      continue;
    }

    if (formatList[loop] == FormatMAType)
    {
      QStringList mal;
      getMATypes(mal);
      if (mal.findIndex(formatStringList[loop]) == -1)
      {
        qDebug("%s::checkFormat: parm #%i invalid, not an MA_TYPE", pluginName.latin1(), loop + 1);
        return TRUE;
      }
      continue;
    }

    if (formatList[loop] == FormatBool)
    {
      if (! formatStringList[loop].compare("TRUE"))
        continue;
      else
      {
        if (! formatStringList[loop].compare("FALSE"))
          continue;
        else
        {
          qDebug("%s::checkFormat: parm #%i invalid, not a BOOL", pluginName.latin1(), loop + 1);
          return TRUE;
        }
      }
    }
  }

  return FALSE;
}
コード例 #4
0
ファイル: BARS.cpp プロジェクト: DigitalPig/qtstalker-qt4
int BARS::indicatorPrefDialog (QWidget *w)
{
  bool newFlag = FALSE;
  if (! method.length())
    newFlag = TRUE;

  if (newFlag)
  {
    bool ok;
    QString s = QInputDialog::getItem(QObject::tr("BARS type Selection"),
                                      QObject::tr("Select a bar type:"),
                                      methodList,
                                      0,
                                      TRUE,
                                      &ok,
                                      w);
    if (ok)
    {
      method = s;
      label = method;
    }
    else
      return FALSE;
  }

  QString pl = QObject::tr("Parms");
  QString ucl = QObject::tr("Up Color");
  QString dcl = QObject::tr("Down Color");
  QString ncl = QObject::tr("Neutral Color");
  QString ccl = QObject::tr("Candle Color");
  QString ll = QObject::tr("Label");

  QString pfxcl = QObject::tr("X Color");
  QString pfocl = QObject::tr("O Color");
  QString pfrl = QObject::tr("Reversal");
  QString pfbsl = QObject::tr("Box Size");
  QString pfml = QObject::tr("Method");

  QString pl2 = QObject::tr("MA");
  QString macl = QObject::tr("MA Color");
  QString mall = QObject::tr("MA Label");
  QString maltl = QObject::tr("MA Line Type");
  QString mapl = QObject::tr("MA Period");
  QString matl = QObject::tr("MA Type");
  QString mail = QObject::tr("MA Input");

  QString pl3 = QObject::tr("MA2");
  QString ma2cl = QObject::tr("MA2 Color");
  QString ma2ll = QObject::tr("MA2 Label");
  QString ma2ltl = QObject::tr("MA2 Line Type");
  QString ma2pl = QObject::tr("MA2 Period");
  QString ma2tl = QObject::tr("MA2 Type");
  QString ma2il = QObject::tr("MA2 Input");

  QString pl4 = QObject::tr("MA3");
  QString ma3cl = QObject::tr("MA3 Color");
  QString ma3ll = QObject::tr("MA3 Label");
  QString ma3ltl = QObject::tr("MA3 Line Type");
  QString ma3pl = QObject::tr("MA3 Period");
  QString ma3tl = QObject::tr("MA3 Type");
  QString ma3il = QObject::tr("MA3 Input");

  QString pl5 = QObject::tr("MA4");
  QString ma4cl = QObject::tr("MA4 Color");
  QString ma4ll = QObject::tr("MA4 Label");
  QString ma4ltl = QObject::tr("MA4 Line Type");
  QString ma4pl = QObject::tr("MA4 Period");
  QString ma4tl = QObject::tr("MA4 Type");
  QString ma4il = QObject::tr("MA4 Input");

  PrefDialog *dialog = new PrefDialog(w);
  dialog->setCaption(QObject::tr("BARS Indicator"));
  dialog->createPage (pl);
  dialog->setHelpFile(helpFile);

  if (! method.compare("OHLC"))
  {
    dialog->setCaption(QObject::tr("OHLC Bars"));
    dialog->addColorItem(ucl, pl, barUpColor);
    dialog->addColorItem(dcl, pl, barDownColor);
    dialog->addColorItem(ncl, pl, barNeutralColor);
  }

  if (! method.compare("Candle"))
  {
    dialog->setCaption(QObject::tr("Japanese Candlesticks"));
    dialog->addColorItem(ucl, pl, barUpColor);
    dialog->addColorItem(dcl, pl, barDownColor);
    dialog->addColorItem(ncl, pl, barNeutralColor);
  }

  if (! method.compare("HACandle"))
  {
    dialog->setCaption(QObject::tr("Heiken Ashi Candlesticks"));
    dialog->addColorItem(ucl, pl, barUpColor);
    dialog->addColorItem(dcl, pl, barDownColor);
    dialog->addColorItem(ncl, pl, barNeutralColor);
  }

  if (! method.compare("PF"))
  {
    dialog->setCaption(QObject::tr("P&F Indicator"));

    QStringList l;
    l.append(QObject::tr("Default"));
    l.append(QObject::tr("Custom"));
    dialog->addComboItem(pfml, pl, l, pfMethod);

    dialog->addColorItem(pfxcl, pl, pfXColor);
    dialog->addColorItem(pfocl, pl, pfOColor);

    double bs = pfBoxSize;
    int rv = pfReversal;

    if (! pfMethod.compare(QObject::tr("Custom")))
    {
      QString s;
      Config config;
      config.getData(Config::CurrentChart, s);
      QFileInfo fi(s);
      s = fi.fileName();

      DBBase db;
      if (! db.open(dbPath))
      {
        QString s2;
        db.getData(s, s2);
        if (s2.length())
        {
          QStringList l = QStringList::split(",", s2, FALSE);
          bs = l[0].toDouble();
          rv = l[1].toInt();
        }
        db.close();
      }
    }

    dialog->addDoubleItem(pfbsl, pl, bs, 0.0001, 999999.0);
    dialog->addIntItem(pfrl, pl, rv, 1, 99);
  }

  dialog->addTextItem(ll, pl, label);

  QStringList mal;
  getMATypes(mal);

  if (! method.compare("OHLC") || ! method.compare("Candle") || ! method.compare("HACandle"))
  {
    dialog->createPage (pl2);
    dialog->addColorItem(macl, pl2, maColor);
    dialog->addTextItem(mall, pl2, maLabel);
    dialog->addComboItem(maltl, pl2, lineTypes, maLineType);
    dialog->addComboItem(matl, pl2, mal, maType);
    dialog->addIntItem(mapl, pl2, maPeriod, 1, 999999);
    dialog->addComboItem(mail, pl2, inputTypeList, maInput);

    dialog->createPage (pl3);
    dialog->addColorItem(ma2cl, pl3, maColor2);
    dialog->addTextItem(ma2ll, pl3, maLabel2);
    dialog->addComboItem(ma2ltl, pl3, lineTypes, maLineType2);
    dialog->addComboItem(ma2tl, pl3, mal, maType2);
    dialog->addIntItem(ma2pl, pl3, maPeriod2, 1, 999999);
    dialog->addComboItem(ma2il, pl3, inputTypeList, maInput2);

    dialog->createPage (pl4);
    dialog->addColorItem(ma3cl, pl4, maColor3);
    dialog->addTextItem(ma3ll, pl4, maLabel3);
    dialog->addComboItem(ma3ltl, pl4, lineTypes, maLineType3);
    dialog->addComboItem(ma3tl, pl4, mal, maType3);
    dialog->addIntItem(ma3pl, pl4, maPeriod3, 1, 999999);
    dialog->addComboItem(ma3il, pl4, inputTypeList, maInput3);

    dialog->createPage (pl5);
    dialog->addColorItem(ma4cl, pl5, maColor4);
    dialog->addTextItem(ma4ll, pl5, maLabel4);
    dialog->addComboItem(ma4ltl, pl5, lineTypes, maLineType4);
    dialog->addComboItem(ma4tl, pl5, mal, maType4);
    dialog->addIntItem(ma4pl, pl5, maPeriod4, 1, 999999);
    dialog->addComboItem(ma4il, pl5, inputTypeList, maInput4);
  }

  int rc = dialog->exec();

  if (rc == QDialog::Accepted)
  {
    if (! method.compare("OHLC"))
    {
      dialog->getColor(ucl, barUpColor);
      dialog->getColor(dcl, barDownColor);
      dialog->getColor(ncl, barNeutralColor);
      lineType = PlotLine::Bar;
    }

    if (! method.compare("Candle") || ! method.compare("HACandle"))
    {
      dialog->getColor(ucl, barUpColor);
      dialog->getColor(dcl, barDownColor);
      dialog->getColor(ncl, barNeutralColor);
      lineType = PlotLine::Candle;
    }

    if (! method.compare("PF"))
    {
      dialog->getCombo(pfml, pfMethod);
      dialog->getColor(pfxcl, pfXColor);
      dialog->getColor(pfocl, pfOColor);
      pfReversal = dialog->getInt(pfrl);

      if (! pfMethod.compare(QObject::tr("Custom")) && data)
      {
        double d = dialog->getDouble(pfbsl);
        QString s;
        Config config;
        config.getData(Config::CurrentChart, s);
        QFileInfo fi(s);
        s = fi.fileName();
        DBBase db;
        if (! db.open(dbPath))
        {
          QString s2 = QString::number(d) + "," + QString::number(pfReversal);
          db.setData(s, s2);
          db.close();
        }
      }

      lineType = PlotLine::PF;
    }

    dialog->getText(ll, label);

    if (! method.compare("OHLC") || ! method.compare("Candle") || ! method.compare("HACandle"))
    {
      dialog->getColor(macl, maColor);
      maLineType = (PlotLine::LineType) dialog->getComboIndex(maltl);
      maPeriod = dialog->getInt(mapl);
      dialog->getText(mall, maLabel);
      maType = dialog->getComboIndex(matl);
      maInput = (BarData::InputType) dialog->getComboIndex(mail);

      dialog->getColor(ma2cl, maColor2);
      maLineType2 = (PlotLine::LineType) dialog->getComboIndex(ma2ltl);
      maPeriod2 = dialog->getInt(ma2pl);
      dialog->getText(ma2ll, maLabel2);
      maType2 = dialog->getComboIndex(ma2tl);
      maInput2 = (BarData::InputType) dialog->getComboIndex(ma2il);


      dialog->getColor(ma3cl, maColor3);
      maLineType3 = (PlotLine::LineType) dialog->getComboIndex(ma3ltl);
      maPeriod3 = dialog->getInt(ma3pl);
      dialog->getText(ma3ll, maLabel3);
      maType3 = dialog->getComboIndex(ma3tl);
      maInput3 = (BarData::InputType) dialog->getComboIndex(ma3il);

      dialog->getColor(ma4cl, maColor4);
      maLineType4 = (PlotLine::LineType) dialog->getComboIndex(ma4ltl);
      maPeriod4 = dialog->getInt(ma4pl);
      dialog->getText(ma4ll, maLabel4);
      maType4 = dialog->getComboIndex(ma4tl);
      maInput4 = (BarData::InputType) dialog->getComboIndex(ma4il);
    }

    rc = TRUE;
  }
  else
    rc = FALSE;

  delete dialog;
  return rc;
}
コード例 #5
0
ファイル: TALIB.cpp プロジェクト: botvs/FinancialAnalytics
void TALIB::formatDialog (QStringList &vl, QString &rv, QString &rs)
{
  rs.truncate(0);
  rv.truncate(0);

  const TA_FuncHandle *handle;
  const TA_FuncInfo *theInfo;
 
  // open a TALIB handle
  TA_RetCode retCode = TA_GetFuncHandle(formatMethod, &handle);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::getFormatList:can't open handle");
    return;
  }

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

  QString pl = QObject::tr("Parms");
  QString vnl = QObject::tr("Variable Name");
  PrefDialog *dialog = new PrefDialog(0);
  dialog->setCaption(QObject::tr("TALIB Format"));
  dialog->createPage (pl);
  dialog->setHelpFile(helpFile);

  QString s;
  dialog->addTextItem(vnl, pl, s);

  // check for any array inputs
  const TA_InputParameterInfo *inputParms;
  int loop;
  for (loop = 0; loop < (int) theInfo->nbInput; loop++ )
  {
    s = QObject::tr("Input") + QString::number(loop + 1);
    TA_GetInputParameterInfo(theInfo->handle, loop, &inputParms);
    switch (inputParms->type)
    {
      case TA_Input_Real:
        dialog->addComboItem(s, pl, vl, (int) BarData::Close);
        break;
      default:
        break;
    }
  }

  QStringList mal;
  getMATypes(mal);
  mal.remove("Wilder");

  // get the input parms
  const TA_OptInputParameterInfo *optInfo;
  for (loop = 0; loop < (int) theInfo->nbOptInput; loop++ )
  {
    TA_GetOptInputParameterInfo(theInfo->handle, loop, &optInfo);
    s = optInfo->displayName;
    switch (optInfo->type)
    {
      case TA_OptInput_RealRange:
        dialog->addDoubleItem(s, pl, (double) optInfo->defaultValue, 0, 99999999);
        break;
      case TA_OptInput_IntegerRange:
        dialog->addIntItem(s, pl, (int) optInfo->defaultValue, 1, 999999);
        break;
      case TA_OptInput_IntegerList:
        dialog->addComboItem(s, pl, mal, (int) optInfo->defaultValue);
        break;
      case TA_OptInput_RealList:
        break;
      default:
        break;
    }
  }

  if (theInfo->nbOutput > 1)
  {
    s = "Plot";
    dialog->addIntItem(s, pl, 1, 1, theInfo->nbOutput);
  }

  int rc = dialog->exec();
  
  if (rc == QDialog::Accepted)
  {
    dialog->getText(vnl, rv);
    rs = formatMethod;

    QString ts;
    for (loop = 0; loop < (int) theInfo->nbInput; loop++ )
    {
      s = QObject::tr("Input") + QString::number(loop + 1);
      TA_GetInputParameterInfo(theInfo->handle, loop, &inputParms);
      switch (inputParms->type)
      {
        case TA_Input_Real:
          dialog->getCombo(s, ts);
          rs.append("," + ts);
          break;
        default:
          break;
      }
    }

    double d = 0;
    int t = 0;
    for (loop = 0; loop < (int) theInfo->nbOptInput; loop++ )
    {
      TA_GetOptInputParameterInfo(theInfo->handle, loop, &optInfo);
      s = optInfo->displayName;
      switch (optInfo->type)
      {
        case TA_OptInput_RealRange:
          d = dialog->getDouble(s);
          rs.append("," + QString::number(d));
          break;
        case TA_OptInput_IntegerRange:
          t = dialog->getInt(s);
          rs.append("," + QString::number(t));
          break;
        case TA_OptInput_IntegerList:
          dialog->getCombo(s, ts);
          rs.append("," + ts);
          break;
        case TA_OptInput_RealList:
          break;
        default:
          break;
      }
    }

    if (theInfo->nbOutput > 1)
    {
      s = "Plot";
      t = dialog->getInt(s);
      rs.append("," + QString::number(t));
    }
  }

  delete dialog;
}
コード例 #6
0
ファイル: TALIB.cpp プロジェクト: botvs/FinancialAnalytics
PlotLine * TALIB::calculateCustom (QString &p, QPtrList<PlotLine> &d)
{
  // format: METHOD, ..., ...., ..... etc (first parm must be the method)

  QStringList l = QStringList::split(",", p, FALSE);

  if (! l.count())
  {
    qDebug("TALIB::calculateCustom: no method parm");
    return 0;
  }
  
  TA_Integer start = 0;
  TA_Integer end = data->count() - 1;
  if (d.count())
    end = d.at(0)->getSize() - 1;
  TA_Integer outstart;
  TA_Integer count;
  PlotLine *line = new PlotLine;
  // sometimes are not enough data available
  // to calc anything
  if(end < 0) 
    return line;
  
  // open a TALIB handle
  const TA_FuncHandle *handle;
  TA_RetCode retCode = TA_GetFuncHandle(l[0], &handle);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::calculateCustom:can't open handle");
    return 0;
  }

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

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

  // create and 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];
  TA_Real treal[loop];

  int sparmIndex = 1;

  // setup the input arrays
  const TA_InputParameterInfo *inputParms;
  for (loop = 0; loop < (int) theInfo->nbInput; loop++ )
  {
    TA_GetInputParameterInfo(theInfo->handle, loop, &inputParms);

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

      retCode = TA_SetInputParamPricePtr(parmHolder, loop, &open[0], &high[0], &low[0], &close[0],
                                         &volume[0], &oi[0]);
      if (retCode != TA_SUCCESS)
      {
        qDebug("TALIB::calculateCustom:cannot set input prices");
        return 0;
      }
    }

    if (inputParms->type == TA_Input_Real)
    {
      if (! d.count())
      {
        qDebug("TALIB::calculateCustom: no input");
        return 0;
      }

      if (sparmIndex >= (int) l.count())
      {
        qDebug("TALIB::calculateCustom: input invalid number of parms");
        return 0;
      }

      PlotLine *line =  d.at(0);
      int loop2;
      for (loop2 = 0; loop2 < line->getSize(); loop2++)
        treal[loop2] = (TA_Real) line->getData(loop2);

      retCode = TA_SetInputParamRealPtr(parmHolder, loop, &treal[0]);
      if (retCode != TA_SUCCESS)
      {
        qDebug("TALIB::calculateCustom:cannot set real price");
        return 0;
      }

      sparmIndex++;
    }
  }

  if (sparmIndex < (int) l.count())
  {
    QStringList mal;
    getMATypes(mal);
    mal.remove("Wilder");
    int t = 0;

    // setup the optinput parms
    const TA_OptInputParameterInfo *optInfo;
    for (loop = 0; loop < (int) theInfo->nbOptInput; loop++ )
    {
      TA_GetOptInputParameterInfo(theInfo->handle, loop, &optInfo);
      switch (optInfo->type)
      {
        case TA_OptInput_RealRange:
          if (sparmIndex >= (int) l.count())
          {
            qDebug("TALIB::calculateCustom: optinput real invalid number of parms");
            return 0;
          }

          retCode = TA_SetOptInputParamReal(parmHolder, loop, (TA_Real) l[sparmIndex].toDouble());
          if (retCode != TA_SUCCESS)
          {
            qDebug("TALIB::calculateCustom:cannot set inputopt real");
            return 0;
          }
          sparmIndex++;
          break;
        case TA_OptInput_IntegerRange:
          if (sparmIndex >= (int) l.count())
          {
            qDebug("TALIB::calculateCustom: optinput integer invalid number of parms");
            return 0;
          }

          retCode = TA_SetOptInputParamInteger(parmHolder, loop, (TA_Integer) l[sparmIndex].toInt());
          if (retCode != TA_SUCCESS)
          {
            qDebug("TALIB::calculateCustom:cannot set inputopt integer");
            return 0;
          }
          sparmIndex++;
          break;

        case TA_OptInput_IntegerList:
          if (sparmIndex >= (int) l.count())
          {
            qDebug("TALIB::calculateCustom: optinput integerList invalid number of parms");
            return 0;
          }
    
          t = mal.findIndex(l[sparmIndex]);
          if (t == -1)
            t = 0;
          retCode = TA_SetOptInputParamInteger(parmHolder, loop, (TA_Integer) t);
          if (retCode != TA_SUCCESS)
          {
            qDebug("TALIB::calculateCustom:cannot set inputopt integer");
            return 0;
          }
          sparmIndex++;
          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::calculateCustom:cannot get output info");
      return 0;
    }

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

  // call the function
  /*
  TA_Integer start = 0;
  TA_Integer end = data->count() - 1;
  if (d.count())
    end = d.at(0)->getSize() - 1;
  TA_Integer outstart;
  TA_Integer count;
  PlotLine *line = new PlotLine;
  */
  retCode = TA_CallFunc(parmHolder, start, end, &outstart, &count);
  if (retCode != TA_SUCCESS)
  {
    printError(QString("TALIB::calculateCustom:TA_CallFunc"), retCode);
    qDebug("p=%s  start=%d  end=%d",p.ascii(), start, end);
  }
  else
  {
    // create the plotlines
    int loop2;
    retCode = TA_GetOutputParameterInfo(handle, 0, &outInfo);
    if (retCode != TA_SUCCESS)
    {
      qDebug("TALIB::calculateCustom:cannot get output info");
      return 0;
    }
    
    if (outInfo->type == TA_Output_Integer)
    {
      for (loop2 = 0; loop2 < count; loop2++)
        line->append((double) out4[loop2]);
    }
    else
    {
      if (theInfo->nbOutput > 1)
      {
        bool ok;
        l[l.count() - 1].toInt(&ok);
        if (! ok)
        {
          qDebug("TALIB::calculateCustom: parm #%i invalid, not an INTEGER", loop + 1);
          return 0;
        }

        switch (l[l.count() - 1].toInt(&ok))
        {
          case 2:
            for (loop2 = 0; loop2 < count; loop2++)
              line->append((double) out2[loop2]);
            break;
          case 3:
            for (loop2 = 0; loop2 < count; loop2++)
              line->append((double) out3[loop2]);
            break;
          default:
            for (loop2 = 0; loop2 < count; loop2++)
              line->append((double) out1[loop2]);
            break;
        }
      }
      else
      {
        for (loop2 = 0; loop2 < count; loop2++)
          line->append((double) out1[loop2]);
      }
    }
  }

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

  return line;
}
コード例 #7
0
ファイル: TALIB.cpp プロジェクト: botvs/FinancialAnalytics
int TALIB::indicatorPrefDialog (QWidget *w)
{
  const TA_FuncHandle *handle;
  const TA_FuncInfo *theInfo;
 
  // open a TALIB handle
  QString ts = "method";
  QString ts2;
  parms.getData(ts, ts2);
  TA_RetCode retCode = TA_GetFuncHandle(ts2, &handle);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::indicatorPrefDialog:can't open handle");
    return FALSE;
  }

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

  QString pl = QObject::tr("Parms");
  PrefDialog *dialog = new PrefDialog(w);
  dialog->setCaption(QObject::tr("TALIB Indicator"));
  dialog->createPage (pl);
  dialog->setHelpFile(helpFile);

  QStringList mal;
  getMATypes(mal);
  mal.remove("Wilder");

  // get the input parms
  const TA_OptInputParameterInfo *optInfo;
  int loop;
  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:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addDoubleItem(s, pl, (double) optInfo->defaultValue, 0, 99999999);
          ts = QString::number((double) optInfo->defaultValue);
          parms.setData(s, ts);
        }
        else
          dialog->addDoubleItem(s, pl, parms.getDouble(s), 0, 99999999);
        break;
      case TA_OptInput_IntegerRange:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addIntItem(s, pl, (int) optInfo->defaultValue, 1, 999999);
          ts = QString::number((int) optInfo->defaultValue);
          parms.setData(s, ts);
        }
        else
          dialog->addIntItem(s, pl, parms.getInt(s), 1, 999999);
        break;
      case TA_OptInput_IntegerList:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addComboItem(s, pl, mal, (int) optInfo->defaultValue);
          ts = QString::number((int) optInfo->defaultValue);
          parms.setData(s, ts);
        }
        else
          dialog->addComboItem(s, pl, mal, parms.getInt(s));
        break;
      case TA_OptInput_RealList:
        break;
      default:
        break;
    }
  }

  // check for any array inputs
  const TA_InputParameterInfo *inputParms;
  for (loop = 0; loop < (int) theInfo->nbInput; loop++ )
  {
    QString s = QObject::tr("input") + QString::number(loop + 1);
    TA_GetInputParameterInfo(theInfo->handle, loop, &inputParms);
    switch (inputParms->type)
    {
      case TA_Input_Real:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addComboItem(s, pl, inputTypeList, (int) BarData::Close);
          ts = QString::number(BarData::Close);
          parms.setData(s, ts);
        }
        else
          dialog->addComboItem(s, pl, inputTypeList, parms.getInt(s));
        break;
      default:
        break;
    }
  }

  // setup the output plots
  const TA_OutputParameterInfo *outInfo;
  for (loop = 0; loop < (int) theInfo->nbOutput; loop++ )
  {
    TA_GetOutputParameterInfo(theInfo->handle, loop, &outInfo);

    pl = outInfo->paramName;
    pl = pl.right(pl.length() - 3);
    if (! pl.left(4).compare("Real"))
      pl = pl.right(pl.length() - 4);
    if (! pl.left(7).compare("Integer"))
      pl = pl.right(pl.length() - 7);
    if (! pl.length())
      pl = QObject::tr("Plot");
    dialog->createPage (pl);

    QString s = pl + " " + QObject::tr("Color");
    QColor color;
    if (loop == 0)
      color.setNamedColor("red");
    else
    {
      if (loop == 1)
        color.setNamedColor("yellow");
      else
        color.setNamedColor("blue");
    }
    parms.getData(s, ts);
    if (! ts.length())
    {
      dialog->addColorItem(s, pl, color);
      ts = color.name();
      parms.setData(s, ts);
    }
    else
    {
      parms.getData(s, ts);
      color.setNamedColor(ts);
      dialog->addColorItem(s, pl, color);
    }

    s = pl + " " + QObject::tr("Label");
    parms.getData(s, ts);
    if (! ts.length())
    {
      dialog->addTextItem(s, pl, pl);
      parms.setData(s, pl);
    }
    else
    {
      parms.getData(s, ts);
      dialog->addTextItem(s, pl, ts);
    }

    s = pl + " " + QObject::tr("Line Type");
    parms.getData(s, ts);
    if (! ts.length()) 
    {
      switch (outInfo->flags)
      {
        case TA_OUT_DOT_LINE:
          ts = QString::number(PlotLine::Dot);
          break;
        case TA_OUT_DASH_LINE:
          ts = QString::number(PlotLine::Dash);
          break;
        case TA_OUT_HISTO:
          ts = QString::number(PlotLine::Histogram);
          break;
        default:
          ts = QString::number(PlotLine::Line);
          break;
      }

      dialog->addComboItem(s, pl, lineTypes, ts.toInt());
      parms.setData(s, ts);
    }
    else
      dialog->addComboItem(s, pl, lineTypes, parms.getInt(s));
  }

  int rc = dialog->exec();
  
  if (rc == QDialog::Accepted)
  {
    QStringList l;
    parms.getKeyList(l);
    int loop;
    for (loop = 0; loop < (int) l.count(); loop++)
    {
      QString s;
      dialog->getItem(l[loop], s);
      if (s.length())
        parms.setData(l[loop], s);
    }

    rc = TRUE;
  }
  else
    rc = FALSE;
  
  delete dialog;
  return rc;
}
コード例 #8
0
ファイル: THERM.cpp プロジェクト: botvs/FinancialAnalytics
int THERM::indicatorPrefDialog (QWidget *w)
{
  QString pl = QObject::tr("THERM Parms");
  QString pl2 = QObject::tr("MA Parms");
  QString cal = QObject::tr("Color Above MA");
  QString cbl = QObject::tr("Color Below MA");
  QString ctl = QObject::tr("Color Threshold");
  QString ll = QObject::tr("Label");
  QString tl = QObject::tr("Threshold");
  QString sl = QObject::tr("Smoothing");
  QString stl = QObject::tr("Smoothing Type");
  QString mcl = QObject::tr("MA Color");
  QString mltl = QObject::tr("MA Line Type");
  QString mll = QObject::tr("MA Label");
  QString mpl = QObject::tr("MA Period");
  QString mtl = QObject::tr("MA Type");

  PrefDialog *dialog = new PrefDialog(w);
  dialog->setCaption(QObject::tr("THERM Indicator"));
  dialog->setHelpFile(helpFile);

  dialog->createPage (pl);
  dialog->addColorItem(cal, pl, upColor);
  dialog->addColorItem(cbl, pl, downColor);
  dialog->addColorItem(ctl, pl, threshColor);
  dialog->addTextItem(ll, pl, label);
  dialog->addDoubleItem(tl, pl, threshold, 1, 99999999);
  dialog->addIntItem(sl, pl, smoothing, 0, 99999999);
  QStringList l;
  getMATypes(l);
  dialog->addComboItem(stl, pl, l, smoothType);
  
  dialog->createPage (pl2);
  dialog->addColorItem(mcl, pl2, maColor);
  dialog->addComboItem(mltl, pl2, lineTypes, maLineType);
  dialog->addTextItem(mll, pl2, maLabel);
  dialog->addIntItem(mpl, pl2, maPeriod, 0, 99999999);
  dialog->addComboItem(mtl, pl2, l, maType);
  
  int rc = dialog->exec();
  
  if (rc == QDialog::Accepted)
  {
    dialog->getColor(cal, upColor);
    dialog->getColor(cbl, downColor);
    dialog->getColor(ctl, threshColor);
    dialog->getText(ll, label);
    threshold = dialog->getDouble(tl);
    smoothing = dialog->getInt(sl);
    smoothType = dialog->getComboIndex(stl);
    
    dialog->getColor(mcl, maColor);
    maLineType = (PlotLine::LineType) dialog->getComboIndex(mltl);
    dialog->getText(mll, maLabel);
    maPeriod = dialog->getInt(mpl);
    maType = dialog->getComboIndex(mtl);
    rc = TRUE;
  }
  else
    rc = FALSE;
  
  delete dialog;
  return rc;
}