00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "PP.h"
00023 #include "PrefDialog.h"
00024 #include <qdict.h>
00025 #include <qobject.h>
00026
00027 PP::PP ()
00028 {
00029 pluginName = "PP";
00030 helpFile = "pp.html";
00031
00032 ppList.append("FR");
00033 ppList.append("SR");
00034 ppList.append("TR");
00035 ppList.append("FS");
00036 ppList.append("SS");
00037 ppList.append("TS");
00038
00039 resColorLabel = "resColor";
00040 supColorLabel = "supColor";
00041 resLineTypeLabel = "resLineType";
00042 supLineTypeLabel = "supLineType";
00043 resLabelLabel = "resLabel";
00044 resLabel2Label = "resLabel2";
00045 resLabel3Label = "resLabel3";
00046 supLabelLabel = "supLabel";
00047 supLabel2Label = "supLabel2";
00048 supLabel3Label = "supLabel3";
00049 labelLabel = "label";
00050 pluginLabel = "plugin";
00051
00052 formatList.append(FormatString);
00053
00054 setDefaults();
00055 }
00056
00057 PP::~PP ()
00058 {
00059 }
00060
00061 void PP::setDefaults ()
00062 {
00063 resColor.setNamedColor("yellow");
00064 supColor.setNamedColor("red");
00065 resLineType = PlotLine::Horizontal;
00066 supLineType = PlotLine::Horizontal;
00067 supLabel = QObject::tr("PP FS");
00068 supLabel2 = QObject::tr("PP SS");
00069 supLabel3 = QObject::tr("PP TS");
00070 resLabel = QObject::tr("PP FR");
00071 resLabel2 = QObject::tr("PP SR");
00072 resLabel3 = QObject::tr("PP TR");
00073 label = pluginName;
00074 }
00075
00076 Indicator * PP::calculate ()
00077 {
00078 Indicator *output = new Indicator;
00079 output->setDateFlag(dateFlag);
00080 output->setLogScale(logScale);
00081
00082 QPtrList<PlotLine> pll;
00083 pll.setAutoDelete(FALSE);
00084 getPP(pll);
00085
00086 int loop;
00087 for (loop = 0; loop < (int) pll.count(); loop++)
00088 output->addLine(pll.at(loop));
00089
00090 return output;
00091 }
00092
00093 void PP::getPP (QPtrList<PlotLine> &pll)
00094 {
00095 double high = data->getHigh(data->count() - 1);
00096 double low = data->getLow(data->count() - 1);
00097 double close = data->getClose(data->count() - 1);
00098
00099 PlotLine *fr = new PlotLine();
00100 fr->setColor(resColor);
00101 fr->setType(resLineType);
00102 fr->setLabel(resLabel);
00103 double pp = (high + low + close) / 3;
00104 double t = (2 * pp) - low;
00105 fr->append(t);
00106
00107 PlotLine *sr = new PlotLine();
00108 sr->setColor(resColor);
00109 sr->setType(resLineType);
00110 sr->setLabel(resLabel2);
00111 pp = (high + low + close) / 3;
00112 t = pp + (high - low);
00113 sr->append(t);
00114
00115 PlotLine *thr = new PlotLine();
00116 thr->setColor(resColor);
00117 thr->setType(resLineType);
00118 thr->setLabel(resLabel3);
00119 pp = (high + low + close) / 3;
00120 t = (2 * pp) + (high - (2 * low));
00121 thr->append(t);
00122
00123 PlotLine *fs = new PlotLine();
00124 fs->setColor(supColor);
00125 fs->setType(supLineType);
00126 fs->setLabel(supLabel);
00127 pp = (high + low + close) / 3;
00128 t = (2 * pp) - high;
00129 fs->append(t);
00130
00131 PlotLine *ss = new PlotLine();
00132 ss->setColor(supColor);
00133 ss->setType(supLineType);
00134 ss->setLabel(supLabel2);
00135 pp = (high + low + close) / 3;
00136 t = pp - (high - low);
00137 ss->append(t);
00138
00139 PlotLine *ts = new PlotLine();
00140 ts->setColor(supColor);
00141 ts->setType(supLineType);
00142 ts->setLabel(supLabel3);
00143 pp = (high + low + close) / 3;
00144 t = (2 * pp) - ((2 * high) - low);
00145 ts->append(t);
00146
00147 pll.append(fr);
00148 pll.append(sr);
00149 pll.append(thr);
00150 pll.append(fs);
00151 pll.append(ss);
00152 pll.append(ts);
00153 }
00154
00155 int PP::indicatorPrefDialog (QWidget *w)
00156 {
00157 QString pl = QObject::tr("Support");
00158 QString scl = QObject::tr("Support Color");
00159 QString lfsl = QObject::tr("Label First Support");
00160 QString lssl = QObject::tr("Label Second Support");
00161 QString ltsl = QObject::tr("Label Third Support");
00162 QString pl2 = QObject::tr("Resistance");
00163 QString rcl = QObject::tr("Resistance Color");
00164 QString lfrl = QObject::tr("Label First Resistance");
00165 QString lsrl = QObject::tr("Label Second Resistance");
00166 QString ltrl = QObject::tr("Label Third Resistance");
00167
00168 PrefDialog *dialog = new PrefDialog(w);
00169 dialog->setCaption(QObject::tr("PP Indicator"));
00170 dialog->setHelpFile(helpFile);
00171
00172 dialog->createPage (pl);
00173 dialog->addColorItem(scl, pl, supColor);
00174 dialog->addTextItem(lfsl, pl, supLabel);
00175 dialog->addTextItem(lssl, pl, supLabel2);
00176 dialog->addTextItem(ltsl, pl, supLabel3);
00177
00178 dialog->createPage (pl2);
00179 dialog->addColorItem(rcl, pl2, resColor);
00180 dialog->addTextItem(lfrl, pl2, resLabel);
00181 dialog->addTextItem(lsrl, pl2, resLabel2);
00182 dialog->addTextItem(ltrl, pl2, resLabel3);
00183
00184 int rc = dialog->exec();
00185
00186 if (rc == QDialog::Accepted)
00187 {
00188 dialog->getColor(scl, supColor);
00189 dialog->getColor(rcl, resColor);
00190 dialog->getText(lfsl, supLabel);
00191 dialog->getText(lssl, supLabel2);
00192 dialog->getText(ltsl, supLabel3);
00193 dialog->getText(lfrl, resLabel);
00194 dialog->getText(lsrl, resLabel2);
00195 dialog->getText(ltrl, resLabel3);
00196 rc = TRUE;
00197 }
00198 else
00199 rc = FALSE;
00200
00201 delete dialog;
00202 return rc;
00203 }
00204
00205 void PP::setIndicatorSettings (Setting &dict)
00206 {
00207 setDefaults();
00208
00209 if (! dict.count())
00210 return;
00211
00212 QString s;
00213 dict.getData(resColorLabel, s);
00214 if (s.length())
00215 resColor.setNamedColor(s);
00216
00217 dict.getData(supColorLabel, s);
00218 if (s.length())
00219 supColor.setNamedColor(s);
00220
00221 dict.getData(resLineTypeLabel, s);
00222 if (s.length())
00223 resLineType = (PlotLine::LineType) s.toInt();
00224
00225 dict.getData(supLineTypeLabel, s);
00226 if (s.length())
00227 supLineType = (PlotLine::LineType) s.toInt();
00228
00229 dict.getData(resLabelLabel, s);
00230 if (s.length())
00231 resLabel = s;
00232
00233 dict.getData(resLabel2Label, s);
00234 if (s.length())
00235 resLabel2 = s;
00236
00237 dict.getData(resLabel3Label, s);
00238 if (s.length())
00239 resLabel3 = s;
00240
00241 dict.getData(supLabelLabel, s);
00242 if (s.length())
00243 supLabel = s;
00244
00245 dict.getData(supLabel2Label, s);
00246 if (s.length())
00247 supLabel2 = s;
00248
00249 dict.getData(supLabel3Label, s);
00250 if (s.length())
00251 supLabel3 = s;
00252
00253 dict.getData(labelLabel, s);
00254 if (s.length())
00255 label = s;
00256 }
00257
00258 void PP::getIndicatorSettings (Setting &dict)
00259 {
00260 QString ts = resColor.name();
00261 dict.setData(resColorLabel, ts);
00262 ts = supColor.name();
00263 dict.setData(supColorLabel, ts);
00264 ts = QString::number(resLineType);
00265 dict.setData(resLineTypeLabel, ts);
00266 ts = QString::number(supLineType);
00267 dict.setData(supLineTypeLabel, ts);
00268 dict.setData(resLabelLabel, resLabel);
00269 dict.setData(resLabel2Label, resLabel2);
00270 dict.setData(resLabel3Label, resLabel3);
00271 dict.setData(supLabelLabel, supLabel);
00272 dict.setData(supLabel2Label, supLabel2);
00273 dict.setData(supLabel3Label, supLabel3);
00274 dict.setData(labelLabel, label);
00275 dict.setData(pluginLabel, pluginName);
00276 }
00277
00278 PlotLine * PP::calculateCustom (QString &p, QPtrList<PlotLine> &d)
00279 {
00280
00281 if (checkFormat(p, d, 1, 1))
00282 return 0;
00283
00284 int t = ppList.findIndex(formatStringList[0]);
00285 if (t == -1)
00286 {
00287 qDebug("PP::calculateCustom: invalid PP_TYPE parm");
00288 return 0;
00289 }
00290
00291 QPtrList<PlotLine> pll;
00292 pll.setAutoDelete(TRUE);
00293 getPP(pll);
00294
00295 PlotLine *line = new PlotLine;
00296 PlotLine *tline = pll.at(t);
00297 line->copy(tline);
00298
00299 return line;
00300 }
00301
00302 void PP::formatDialog (QStringList &, QString &rv, QString &rs)
00303 {
00304 rs.truncate(0);
00305 rv.truncate(0);
00306 QString pl = QObject::tr("Parms");
00307 QString vnl = QObject::tr("Variable Name");
00308 QString ppl = QObject::tr("PP Level");
00309 PrefDialog *dialog = new PrefDialog(0);
00310 dialog->setCaption(QObject::tr("PP Format"));
00311 dialog->createPage (pl);
00312 dialog->setHelpFile(helpFile);
00313
00314 QString s;
00315 dialog->addTextItem(vnl, pl, s);
00316 dialog->addComboItem(ppl, pl, ppList, 0);
00317
00318 int rc = dialog->exec();
00319
00320 if (rc == QDialog::Accepted)
00321 {
00322 dialog->getText(vnl, rv);
00323 dialog->getCombo(ppl, rs);
00324 }
00325
00326 delete dialog;
00327 }
00328