Exemple #1
0
void BARS::calculateMA (Indicator *output)
{
  if (maPeriod > 1)
  {
    PlotLine *in = data->getInput(maInput);
    if (in)
    {
      PlotLine *ma = getMA(in, maType, maPeriod);
      ma->setColor(maColor);
      ma->setType(maLineType);
      ma->setLabel(maLabel);
      output->addLine(ma);
      delete in;
    }
  }

  if (maPeriod2 > 1)
  {
    PlotLine *in = data->getInput(maInput2);
    if (in)
    {
      PlotLine *ma = getMA(in, maType2, maPeriod2);
      ma->setColor(maColor2);
      ma->setType(maLineType2);
      ma->setLabel(maLabel2);
      output->addLine(ma);
      delete in;
    }
  }

  if (maPeriod3 > 1)
  {
    PlotLine *in = data->getInput(maInput3);
    if (in)
    {
      PlotLine *ma = getMA(in, maType3, maPeriod3);
      ma->setColor(maColor3);
      ma->setType(maLineType3);
      ma->setLabel(maLabel3);
      output->addLine(ma);
      delete in;
    }
  }

  if (maPeriod4 > 1)
  {
    PlotLine *in = data->getInput(maInput4);
    if (in)
    {
      PlotLine *ma = getMA(in, maType4, maPeriod4);
      ma->setColor(maColor4);
      ma->setType(maLineType4);
      ma->setLabel(maLabel4);
      output->addLine(ma);
      delete in;
    }
  }
}
Exemple #2
0
Curve *
OHLC::getMA (Entity *settings, int num)
{
  QString key = "ma" + QString::number(num) + "Input";
  QVariant *input = settings->get(key);
  if (! input)
    return 0;
  
  key = "ma" + QString::number(num) + "Type";
  QVariant *type = settings->get(key);
  if (! type)
    return 0;
  
  key = "ma" + QString::number(num) + "Style";
  QVariant *style = settings->get(key);
  if (! style)
    return 0;
  
  key = "ma" + QString::number(num) + "Width";
  QVariant *width = settings->get(key);
  if (! width)
    return 0;
  
  key = "ma" + QString::number(num) + "Period";
  QVariant *period = settings->get(key);
  if (! period)
    return 0;
  
  key = "ma" + QString::number(num) + "Color";
  QVariant *color = settings->get(key);
  if (! color)
    return 0;
  
  key = "ma" + QString::number(num) + "Label";
  QVariant *label = settings->get(key);
  if (! label)
    return 0;

  MAType mat;
  if (! getMA(input->toString(), label->toString(), mat.stringToIndex(type->toString()), period->toInt()))
    return 0;
  
  Curve *curve = new Curve(QString("CurveLine"));
  curve->setLabel(label->toString());
  CurveLineType clt;
  curve->setStyle(clt.stringToIndex(style->toString()));
  curve->setPen(width->toInt());
  curve->setColor(QColor(color->toString()));
  curve->fill(label->toString(), QString(), QString(), QString(), QColor());

  return curve;
}
Exemple #3
0
Curve *
RSI::getMA (Entity *settings)
{
  QVariant *type = settings->get(QString("maType"));
  if (! type)
    return 0;
  
  QVariant *period = settings->get(QString("maPeriod"));
  if (! period)
    return 0;
  
  QVariant *var = settings->get(QString("maColor"));
  if (! var)
    return 0;
  QColor color(var->toString());
  
  QVariant *label = settings->get(QString("maLabel"));
  if (! label)
    return 0;
  
  QVariant *style = settings->get(QString("maStyle"));
  if (! style)
    return 0;
  
  QVariant *width = settings->get(QString("maWidth"));
  if (! width)
    return 0;
  
  QVariant *rsiLabel = settings->get(QString("label"));
  if (! rsiLabel)
    return 0;

  if (! getMA(rsiLabel->toString(), label->toString(), type->toInt(), period->toInt()))
    return 0;
  
  CurveLineType clt;
  Curve *curve = new Curve(QString("CurveLine"));
  curve->setLabel(label->toString());
  curve->setStyle(clt.stringToIndex(style->toString()));
  curve->setPen(width->toInt());
  curve->setColor(color);
  curve->fill(label->toString(), QString(), QString(), QString(), color);

  return curve;
}
Exemple #4
0
int
OHLC::runIndicator (PluginData *pd)
{
  if (! g_symbol)
    return 0;
  
  if (! pd->settings)
    return 0;
  
  QVariant *uc = pd->settings->get(QString("upColor"));
  if (! uc)
    return 0;
  
  QVariant *dc = pd->settings->get(QString("downColor"));
  if (! dc)
    return 0;
  
  QVariant *nc = pd->settings->get(QString("neutralColor"));
  if (! nc)
    return 0;
  
  QVariant *label = pd->settings->get(QString("label"));
  if (! label)
    return 0;
  
  QVariant *style = pd->settings->get(QString("style"));
  if (! style)
    return 0;
  
  Curve *ohlc = getOHLC(style->toString(), label->toString(), uc->toString(), dc->toString(), nc->toString());
  if (! ohlc)
    return 0;
  pd->curves << ohlc;
  
  for (int pos = 1; pos < 4; pos++)
  {
    Curve *ma = getMA(pd->settings, pos);
    if (! ma)
      continue;
    
    pd->curves << ma;
  }
  
  return 1;
}
Exemple #5
0
int
RSI::run (PluginData *pd)
{
  if (! g_symbol)
    return 0;
  
  QVariant *input = pd->settings->get(QString("input"));
  if (! input)
    return 0;
  
  QVariant *period = pd->settings->get(QString("period"));
  if (! period)
    return 0;
  
  QVariant *label = pd->settings->get(QString("label"));
  if (! label)
    return 0;
  
  if (! getRSI(input->toString(), period->toInt(), label->toString()))
    return 0;
  
  // rsi
  QVariant *show = pd->settings->get(QString("rsiShow"));
  if (! show)
    return 0;

  if (show->toBool())
  {
    QVariant *style = pd->settings->get(QString("style"));
    if (! style)
      return 0;
  
    QVariant *width = pd->settings->get(QString("width"));
    if (! width)
      return 0;
  
    QVariant *var = pd->settings->get(QString("color"));
    if (! var)
      return 0;
    QColor color(var->toString());

    CurveLineType clt;
    Curve *rsi = new Curve(QString("CurveLine"));
    rsi->setColor(color);
    rsi->setLabel(label->toString());
    rsi->setStyle(clt.stringToIndex(style->toString()));
    rsi->fill(label->toString(), QString(), QString(), QString(), color);
    rsi->setPen(width->toInt());
    pd->curves << rsi;
  }
  
  // ma
  show = pd->settings->get(QString("maShow"));
  if (! show)
    return 0;
  
  if (show->toBool())
  {
    Curve *ma = getMA(pd->settings);
    if (ma)
      pd->curves << ma;
  }
  
  // buy marker
  show = pd->settings->get(QString("buyMarkerShow"));
  if (! show)
    return 0;
  
  if (show->toBool())
  {
    QVariant *var = pd->settings->get(QString("buyMarkerColor"));
    if (! var)
      return 0;
    QColor color(var->toString());
    
    QVariant *price = pd->settings->get(QString("buyMarkerPrice"));
    if (! price)
      return 0;
    
    Marker *m = newMarker(color, price->toDouble());
    if (! m)
      return 0;
    
    pd->markers << m;
  }

  // sell marker
  show = pd->settings->get(QString("sellMarkerShow"));
  if (! show)
    return 0;
  
  if (show->toBool())
  {
    QVariant *var = pd->settings->get(QString("sellMarkerColor"));
    if (! var)
      return 0;
    QColor color(var->toString());
    
    QVariant *price = pd->settings->get(QString("sellMarkerPrice"));
    if (! price)
      return 0;
    
    Marker *m = newMarker(color, price->toDouble());
    if (! m)
      return 0;
    
    pd->markers << m;
  }
  
  return 1;
}
Exemple #6
0
int
Volume::run (PluginData *pd)
{
  if (! g_symbol)
    return 0;
  
  QVariant *var = pd->settings->get(QString("upColor"));
  if (! var)
    return 0;
  QColor uc(var->toString());
  
  var = pd->settings->get(QString("downColor"));
  if (! var)
    return 0;
  QColor dc(var->toString());
  
  var = pd->settings->get(QString("neutralColor"));
  if (! var)
    return 0;
  QColor nc(var->toString());
  
  QVariant *label = pd->settings->get(QString("label"));
  if (! label)
    return 0;

  Curve *vol = new Curve(QString("CurveHistogram"));
  vol->setStyle(CurveHistogramType::_BAR);
  vol->setLabel(label->toString());
  
  BarType bt;
  QList<int> keys = g_symbol->keys();
  vol->fill(bt.indexToString(BarType::_VOLUME), QString(), QString(), QString(), nc);
  
  for (int pos = 1; pos < keys.size(); pos++)
  {
    CBar *pbar = g_symbol->bar(keys.at(pos - 1));
    CBar *bar = g_symbol->bar(keys.at(pos));
    Bar *vbar = vol->bar(keys.at(pos));

    double yc = 0;
    if (! pbar->get(bt.indexToString(BarType::_CLOSE), yc))
      continue;

    double c = 0;
    if (! bar->get(bt.indexToString(BarType::_CLOSE), c))
      continue;
    
    if (c > yc)
      vbar->setColor(uc);
    else
    {
      if (c < yc)
        vbar->setColor(dc);
    }
  }  

  pd->curves << vol;
  
  Curve *ma = getMA(pd->settings);
  if (ma)
    pd->curves << ma;
  
  return 1;
}
Exemple #7
0
void THERM::getTHERM (QPtrList<PlotLine> &pll)
{
  PlotLine *therm = new PlotLine();
  int loop;
  double thermometer = 0;
  for (loop = 1; loop < (int) data->count(); loop++)
  {
    double high = fabs(data->getHigh(loop) - data->getHigh(loop - 1));
    double lo = fabs(data->getLow(loop - 1) - data->getLow(loop));
    
    if (high > lo)
      thermometer = high;
    else
      thermometer = lo;

    therm->append(thermometer);
  }

  if (smoothing > 1)
  {
    PlotLine *ma = getMA(therm, smoothType, smoothing);
    pll.append(ma);
    delete therm;
    therm = ma;
  }
  else
    pll.append(therm);

  PlotLine *therm_ma = getMA(therm, maType, maPeriod);
  therm_ma->setColor(maColor);
  therm_ma->setType(maLineType);
  therm_ma->setLabel(maLabel);
  pll.append(therm_ma);

  // assign the therm colors

  therm->setColorFlag(TRUE);
  therm->setType(lineType);
  therm->setLabel(label);

  int thermLoop = therm->getSize() - 1;
  int maLoop = therm_ma->getSize() - 1;
  while (thermLoop > -1)
  {
    if (maLoop > -1)
    {
      double thrm = therm->getData(thermLoop);
      double thrmma = therm_ma->getData(maLoop);

      if (thrm > (thrmma * threshold))
        therm->setColorBar(thermLoop, threshColor);
      else
      {
        if (thrm > thrmma)
          therm->setColorBar(thermLoop, upColor);
        else
          therm->setColorBar(thermLoop, downColor);
      }
    }
    else
      therm->setColorBar(thermLoop, downColor);

    thermLoop--;
    maLoop--;
  }
}