| | |
| | | #include <QJsonObject> |
| | | #include <QJsonArray> |
| | | #include <QLibrary> // 用于加载dll动态库的类 |
| | | #include <QDateTime> |
| | | |
| | | |
| | | #pragma execution_character_set("utf-8") |
| | | |
| | | GetStockList::GetStockList(QWidget *parent) : |
| | | QMainWindow(parent), |
| | |
| | | ui->pushButton_get->hide(); |
| | | ui->statusbar->hide(); |
| | | |
| | | // 注册元类型 |
| | | qRegisterMetaType<QVector<QVector<QString>>>("QVector<QVector<QString>> &"); |
| | | // 方案2: |
| | | // 如果https 访问的时候,还是爬取失败,可以代码加载动态库来支持 |
| | | // 前提条件是把2个dll动态库拷贝的生成目录中:libeay32.dll 和 ssleay32.dll |
| | | // 拷贝到生成目录,就可以直接加载 |
| | | // 若是msvc 64bit的编译器,需要下载对应位数的dll库来拷贝即可 -- openssl-1.0.2q-x64_86-win64.zip |
| | | |
| | | QLibrary lb("libeay32.dll"); |
| | | if(lb.load()){ |
| | | qDebug()<<"load libeay32.dll 成功"; |
| | |
| | | QStringList labels; |
| | | labels<<"股票名字"<<"股票代号"<<"总市值(亿)"<<"流通市值(亿)"<<"涨跌幅(%)"<<"收盘价"<<"成交额(亿)"<<"成交量(手)"<<"换手率(%)"<<"市盈率"; |
| | | m_model->setHorizontalHeaderLabels(labels); // 设置模型的列标签名 |
| | | ui->tableView->setModel(m_model); // 将模型和视图关联 |
| | | m_customModel = new CustomSortProxyModel; |
| | | m_customModel->setSourceModel(m_model); // 设置源模型 |
| | | |
| | | //ui->tableView->setModel(m_model); // 将模型和视图关联 |
| | | ui->tableView->setModel(m_customModel); // 设置自定义排序的模型 |
| | | ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); // 设置内容自适应,拉伸 |
| | | |
| | | // 给表格视图添加右击自定义菜单 |
| | |
| | | m_menu = new QMenu(this); |
| | | |
| | | QMenu *dateMenu = new QMenu("设置周期"); |
| | | QAction *m30Action = dateMenu->addAction("设置为30分"); |
| | | QAction *m60Action = dateMenu->addAction("设置为60分"); |
| | | QAction *m120Action = dateMenu->addAction("设置为120分"); |
| | | QAction *dayAction = dateMenu->addAction("设置为日"); |
| | | QAction *weekAction = dateMenu->addAction("设置为周"); |
| | | QAction *monthAction = dateMenu->addAction("设置为月"); |
| | | QAction *yearAction = dateMenu->addAction("设置为年"); |
| | | m_menu->addMenu(dateMenu); |
| | | |
| | | connect(m30Action,&QAction::triggered,this,[&]{ m_dateType = "30m";}); |
| | | connect(m60Action,&QAction::triggered,this,[&]{ m_dateType = "60m";}); |
| | | connect(m120Action,&QAction::triggered,this,[&]{ m_dateType = "120m";}); |
| | | connect(dayAction,&QAction::triggered,this,[&]{ m_dateType = "day";}); |
| | | connect(weekAction,&QAction::triggered,this,[&]{ m_dateType = "week";}); // 修改日期类型 |
| | | connect(monthAction,&QAction::triggered,this,[&]{ m_dateType = "month";}); |
| | | connect(yearAction,&QAction::triggered,this,[&]{ m_dateType = "year";}); |
| | |
| | | connect(pre1000Action,&QAction::triggered,this,[&]{ m_maTestNum = 1000;}); |
| | | connect(pre5000Action,&QAction::triggered,this,[&]{ m_maTestNum = 5000;}); |
| | | |
| | | QMenu *timerMenu = new QMenu("设置轮询执行策略"); |
| | | QAction *timerMultiResonateAction = timerMenu->addAction("轮询多策略共振"); |
| | | |
| | | m_menu->addMenu(timerMenu); |
| | | |
| | | m_pollMultiTimer = new QTimer(this); |
| | | connect(m_pollMultiTimer,SIGNAL(timeout()),this,SLOT(pollMultiSlot())); |
| | | |
| | | connect(timerMultiResonateAction,&QAction::triggered,this,[&] { |
| | | static int cnt=0; |
| | | if(cnt % 2 == 0){ |
| | | m_pollMultiTimer->start(1000*60); |
| | | qDebug()<<"启动轮询多策略共振的定时器"; |
| | | }else{ |
| | | m_pollMultiTimer->stop(); |
| | | qDebug()<<"停止轮询多策略共振策略"; |
| | | } |
| | | }); // 轮询多策略共振 |
| | | |
| | | |
| | | QAction *policy = m_menu->addAction("策略分析"); |
| | | QAction *price = m_menu->addAction("最新价格"); |
| | | QAction *maPolicy = m_menu->addAction("MA策略"); |
| | | QAction *macdPolicy = m_menu->addAction("MACD策略"); |
| | | QAction *maTest100 = m_menu->addAction("MA策略-回测"); |
| | | QAction *buttomToUpPolicy = m_menu->addAction("底部反转策略"); |
| | | QAction *multiResonatePolicy = m_menu->addAction("多策略共振"); |
| | | QAction *multiResonateTest100 = m_menu->addAction("多策略共振-回测"); |
| | | QAction *oneUpCrossFourPolicy = m_menu->addAction("一阳穿四线策略"); |
| | | QAction *oneUpCrossFourTest100 = m_menu->addAction("一阳穿四线策略-回测"); |
| | | |
| | | |
| | | |
| | |
| | | connect(maPolicy,SIGNAL(triggered(bool)),this,SLOT(maPolicySlot())); // MA均线策略 |
| | | connect(macdPolicy,SIGNAL(triggered(bool)),this,SLOT(macdPolicySlot())); // MA均线策略 |
| | | connect(maTest100,SIGNAL(triggered(bool)),this,SLOT(maTest100Slot())); // MA回测前100名 |
| | | |
| | | connect(buttomToUpPolicy,SIGNAL(triggered(bool)),this,SLOT(buttomToUpPolicySlot())); // 底部反转策略 |
| | | connect(multiResonatePolicy,SIGNAL(triggered(bool)),this,SLOT(multiResonatePolicySlot())); // 多策略共振 |
| | | connect(multiResonateTest100,SIGNAL(triggered(bool)),this,SLOT(multiResonateTest100Slot())); // 多策略共振回测 |
| | | connect(oneUpCrossFourPolicy,SIGNAL(triggered(bool)),this,SLOT(oneUpCrossFourSlot())); // 一阳穿四线策略 |
| | | connect(oneUpCrossFourTest100,SIGNAL(triggered(bool)),this,SLOT(oneUpCrossFourTest100Slot())); // 一阳穿四线回测 |
| | | |
| | | |
| | | // 处理数据爬取的操作 |
| | |
| | | on_pushButton_get_clicked(); |
| | | |
| | | // 表格列排序 |
| | | ui->tableView->setSortingEnabled(false); |
| | | ui->tableView->horizontalHeader()->setSortIndicatorShown(false); |
| | | connect(ui->tableView->horizontalHeader(),&QHeaderView::sortIndicatorChanged,this,[=](int index,Qt::SortOrder order){ |
| | | qDebug()<<"sort:"<<index<<order; |
| | | m_model->sort(index,order); |
| | | ui->tableView->horizontalHeader()->setSortIndicatorShown(true); |
| | | ui->tableView->setSortingEnabled(true); |
| | | // ui->tableView->setSortingEnabled(false); |
| | | // ui->tableView->horizontalHeader()->setSortIndicatorShown(false); |
| | | // connect(ui->tableView->horizontalHeader(),&QHeaderView::sortIndicatorChanged,this,[=](int index,Qt::SortOrder order){ |
| | | // qDebug()<<"sort:"<<index<<order; |
| | | // //m_model->sort(index,order); |
| | | // m_customModel->sort(index,order); |
| | | // ui->tableView->horizontalHeader()->setSortIndicatorShown(true); |
| | | |
| | | }); |
| | | // }); |
| | | |
| | | // 定时获取股票代号的定时器相关 |
| | | m_getCodeTimer = new QTimer(this); |
| | | connect(m_getCodeTimer,SIGNAL(timeout()),this,SLOT(getCodeSlot())); |
| | | |
| | | // 支持编辑框的模糊匹配 |
| | | m_completer = new QCompleter(this); |
| | | m_completer->setModel(m_customModel); // 关联包含所有匹配内容的模型或者字符串链表 |
| | | m_completer->setCaseSensitivity(Qt::CaseInsensitive); // 不区分大小写 |
| | | m_completer->setCompletionMode(QCompleter::PopupCompletion); // 自动显示下拉框 |
| | | m_completer->setFilterMode(Qt::MatchContains); // 前缀匹配、包含、后缀 |
| | | ui->lineEdit_search->setCompleter(m_completer); // 关联匹配的控件 |
| | | |
| | | } |
| | | |
| | |
| | | rowItems.append(new QStandardItem(symbol)); |
| | | rowItems.append(new QStandardItem(QString::number(market_capital,'f',2))); |
| | | rowItems.append(new QStandardItem(QString::number(float_market_capital))); |
| | | //rowItems.append(new CustomItem(QString::number(float_market_capital))); |
| | | QStandardItem *percentItem = new QStandardItem(QString::number(percent)); |
| | | if(percent > 0){ |
| | | percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 |
| | |
| | | m_model->appendRow(rowItems); |
| | | } |
| | | } |
| | | |
| | | // 发射信号 |
| | | emit sendCodeNames(m_codeNames); |
| | | } |
| | | |
| | | |
| | |
| | | macd_buy = 1; |
| | | oldVolume = volume; |
| | | } |
| | | } |
| | | }else if(m_menuIndex == 4){ |
| | | // 底部反转策略,提前的感知的时间会更早,得到更好的预判趋势 |
| | | // qDebug()<<"底部反转策略"; |
| | | if(i > 0){ |
| | | double volume_cur = jArr.at(i).toArray().at(1).toDouble(); |
| | | double volume_old = jArr.at(i-1).toArray().at(1).toDouble(); |
| | | double volume_rate = volume_cur / volume_old; |
| | | if(volume_rate > 2){ |
| | | qDebug()<<"底部反转策略:量能比"<<volume_rate<<code <<curDateTime<<"价格:" <<close; |
| | | QString info = QString("<font size=8 color=red> %4 底部反转策略:量能 时间:%1 价格:%2 量能比值=%3 </font>").arg(curDateTime).arg(close).arg(volume_rate).arg(code); |
| | | emit sendInfoMess(info); |
| | | } |
| | | } |
| | | |
| | | }else if(m_menuIndex == 5){ |
| | | // 多策略共振:量能、MACD、MA、BOLL |
| | | |
| | | int cnt = 0; |
| | | // 量能 |
| | | if(i > 0){ |
| | | double volume_cur = jArr.at(i).toArray().at(1).toDouble(); |
| | | double volume_old = jArr.at(i-1).toArray().at(1).toDouble(); |
| | | double volume_rate = volume_cur / volume_old; |
| | | if(volume_rate > 2){ |
| | | cnt++; |
| | | qDebug()<<"多策略共振:量能比"<<volume_rate<<code <<curDateTime<<"价格:" <<close; |
| | | QString info = QString("<font size=8 color=red> %4 多策略共振:量能策略 时间:%1 价格:%2 量能比值=%3 共振值:%5</font>").arg(curDateTime).arg(close).arg(volume_rate).arg(code).arg(cnt); |
| | | emit sendInfoMess(info); |
| | | } |
| | | } |
| | | |
| | | // MACD策略 结合成交量来判断会更好:买入点成交量继续放大则持有,缩小则离场 |
| | | double dea = jArr.at(i).toArray().at(16).toVariant().toDouble(); |
| | | double dif = jArr.at(i).toArray().at(17).toVariant().toDouble(); |
| | | double macd = jArr.at(i).toArray().at(18).toVariant().toDouble(); |
| | | |
| | | if(macd_buy == 1 && oldVolume > volume){ |
| | | QString info = QString("<font size=8 color=green> %4 MACD 成交量初次见顶 离场1:%1 价格:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); |
| | | emit sendInfoMess(info); |
| | | macd_buy = 0; |
| | | oldVolume = 0; |
| | | |
| | | } |
| | | if(i > 0){ |
| | | double dea_old = jArr.at(i-1).toArray().at(16).toVariant().toDouble(); |
| | | double dif_old = jArr.at(i-1).toArray().at(17).toVariant().toDouble(); |
| | | double macd_old = jArr.at(i-1).toArray().at(18).toVariant().toDouble(); |
| | | |
| | | if(dif_old > dea_old && dif <= dea){ |
| | | // 死叉 |
| | | qDebug()<<"MACD死叉:"<<curDateTime<<" 价格:"<<close <<"MACD="<<macd ; |
| | | QString info=QString("<font size=8 color=green> %4 MACD死叉:%1 价格:%2 MACD=%3 </font>").arg(curDateTime).arg(close).arg(macd).arg(code); |
| | | emit sendInfoMess(info); |
| | | }else if(dif_old < dea_old && dif >= dea){ |
| | | // 金叉 |
| | | cnt++; |
| | | qDebug()<<"MACD金叉:"<<curDateTime<<" 价格:"<<close <<"MACD="<<macd <<"建议记录当前金叉MACD的值,若后面有低于此值,关注离场提示"; |
| | | QString info=QString("<font size=9 color=red> %4 MACD金叉:%1 价格:%2 MACD=%3 共振值:%5 </font>").arg(curDateTime).arg(close).arg(macd).arg(code).arg(cnt); |
| | | emit sendInfoMess(info); |
| | | |
| | | macd_buy = 1; |
| | | oldVolume = volume; |
| | | } |
| | | } |
| | | |
| | | |
| | | // MA ma10交ma20 金叉,ma10交ma60 死叉 |
| | | double ma5 = jArr.at(i).toArray().at(12).toVariant().toDouble(); |
| | | double ma10 = jArr.at(i).toArray().at(13).toVariant().toDouble(); |
| | | double ma20 = jArr.at(i).toArray().at(14).toVariant().toDouble(); |
| | | double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); |
| | | //qDebug()<<"MA5-10-20-30"<<ma5<<ma10<<ma20<<ma30; |
| | | if(i>0){ |
| | | double ma5_old = jArr.at(i-1).toArray().at(12).toVariant().toDouble(); |
| | | double ma10_old = jArr.at(i-1).toArray().at(13).toVariant().toDouble(); |
| | | double ma20_old = jArr.at(i-1).toArray().at(14).toVariant().toDouble(); |
| | | double ma30_old = jArr.at(i-1).toArray().at(15).toVariant().toDouble(); |
| | | |
| | | // if(ma5_old > ma20_old && ma5 <= ma20){ |
| | | // // 死叉 |
| | | // qDebug()<<"MA5-20死叉:"<<curDateTime<<" 价格:"<<close; |
| | | // }else if(ma5_old < ma20_old && ma5 >= ma20){ |
| | | // // 金叉 |
| | | // qDebug()<<"MA5-20金叉:"<<curDateTime<<" 价格:"<<close; |
| | | // } |
| | | |
| | | if(ma10_old > ma20_old && ma10 <= ma20){ |
| | | // 死叉 |
| | | qDebug()<<"MA10-20死叉:"<<curDateTime<<" 价格:"<<close; |
| | | if(buy_price == 0) buy_price = close; |
| | | double tmp_rate = (close-buy_price)/buy_price; |
| | | rate_all += tmp_rate; |
| | | |
| | | QString info = QString("<font size=8 color=green> %3 %6 MA10-20死叉:%1 价格:%2 盈利比:%4 总盈利:%5</font>").arg(curDateTime).arg(close).arg(code) |
| | | .arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)).arg(m_codeNames[code]); |
| | | emit sendInfoMess(info); |
| | | //buy_price = close; // 死叉买入的情况 |
| | | }else if(ma10_old < ma20_old && ma10 >= ma20){ |
| | | // 金叉 |
| | | cnt++; |
| | | buy_price = close; // 金叉买入的情况 |
| | | |
| | | qDebug()<<"MA10-20金叉:"<<curDateTime<<" 价格:"<<close; |
| | | QString info = QString("<font size=8 color=red> %3 %4 MA10-20金叉:%1 价格:%2 共振值:%5 </font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(cnt); |
| | | //.arg(QString::number(tmp_rate*100)).arg(QString::number(rate_all*100)); |
| | | emit sendInfoMess(info); |
| | | |
| | | } |
| | | } |
| | | |
| | | }else if(m_menuIndex == 6){ |
| | | // 一阳穿四线 |
| | | |
| | | double ma5 = jArr.at(i).toArray().at(12).toVariant().toDouble(); |
| | | double ma10 = jArr.at(i).toArray().at(13).toVariant().toDouble(); |
| | | double ma20 = jArr.at(i).toArray().at(14).toVariant().toDouble(); |
| | | double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); |
| | | |
| | | double open = jArr.at(i).toArray().at(2).toVariant().toDouble(); |
| | | long long market_cap = jArr.at(i).toArray().at(22).toVariant().toLongLong(); |
| | | |
| | | double volume_rate = 0; |
| | | if(i > 0){ // 计算量能比 |
| | | double volume_cur = jArr.at(i).toArray().at(1).toDouble(); |
| | | double volume_old = jArr.at(i-1).toArray().at(1).toDouble(); |
| | | volume_rate = volume_cur / volume_old; |
| | | } |
| | | |
| | | if(ma5 >= open && ma10 >= open && ma20 >= open && ma30 >= open |
| | | && ma5 <= close && ma10 <= close && ma20 <= close && ma30 <= close){ |
| | | qDebug()<<"一阳穿四线:"<< code <<curDateTime<<" 价格:"<<close << "量能比:"<<volume_rate; |
| | | if(volume_rate > 4){ |
| | | QString info = QString("<font size=8 color=blue> %3 %4 一阳穿四线:%1 价格:%2 量能比:%5 周期:%6 市值:%7亿</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) |
| | | .arg(m_dateType).arg(market_cap/100000000.0); |
| | | emit sendInfoMess(info); |
| | | }else{ |
| | | QString info = QString("<font size=8 color=red> %3 %4 一阳穿四线:%1 价格:%2 量能比:%5 周期:%6 市值:%7亿</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) |
| | | .arg(m_dateType).arg(market_cap/100000000.0); |
| | | emit sendInfoMess(info); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | if(m_model->rowCount() == 0)return; // 防止异常 |
| | | |
| | | int row = ui->tableView->currentIndex().row(); // 取出菜单所在的行号 |
| | | QString symbol = m_model->item(row,1)->text(); // 取当前行所在的股票代号 |
| | | // QString symbol = m_model->item(row,1)->text(); // 取当前行所在的股票代号 |
| | | QString symbol = m_customModel->data(m_customModel->index(row,1)).toString(); |
| | | qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 |
| | | m_numsCnt = 30; // 这里是设置获取单个股票的数据量 |
| | | QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=week&type=before&count=-%3&indicator=kline").arg(symbol).arg(begin).arg(m_numsCnt); |
| | | qDebug()<<urlStr; |
| | | qDebug()<<"当前股票:"<<symbol<<m_model->item(row,0)->text(); |
| | | // qDebug()<<"当前股票:"<<symbol<<m_model->item(row,0)->text(); |
| | | qDebug()<<"当前股票:"<<symbol<<m_customModel->data(m_customModel->index(row,0)).toString(); |
| | | // 下一步就是根据url请求到的数据,进行分析 |
| | | m_menuIndex = 0; // 第一个菜单 |
| | | m_request.setUrl(QUrl(urlStr)); // 设置新的网址 |
| | |
| | | qDebug()<<"最新价格"; |
| | | if(m_model->rowCount() == 0)return; |
| | | int row = ui->tableView->currentIndex().row(); |
| | | QString symbol = m_model->item(row,1)->text(); // 取当前行所在的股票代号 |
| | | // QString symbol = m_model->item(row,1)->text(); // 取当前行所在的股票代号 |
| | | QString symbol = m_customModel->data(m_customModel->index(row,1)).toString(); |
| | | qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 |
| | | int numsCnt = 20; |
| | | QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=day&type=before&count=-%3&indicator=kline").arg(symbol).arg(begin).arg(numsCnt); |
| | |
| | | qDebug()<<"执行MA策略"; |
| | | emit sendInfoMess("<font size=12 color=pink>执行MA策略 </font>"); |
| | | int curRow = ui->tableView->currentIndex().row(); |
| | | QString symbol = m_model->item(curRow,1)->text(); |
| | | // QString symbol = m_model->item(curRow,1)->text(); |
| | | QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); |
| | | qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 |
| | | int numsCnt = 300; |
| | | QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,ma").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); |
| | | qDebug()<<urlStr; |
| | | qDebug()<<"当前股票:"<<symbol<<m_model->item(curRow,0)->text(); |
| | | // qDebug()<<"当前股票:"<<symbol<<m_model->item(curRow,0)->text(); |
| | | qDebug()<<"当前股票:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); |
| | | // 下一步就是根据url请求到的数据,进行分析 |
| | | m_menuIndex = 2; // 第三个菜单项 |
| | | m_request.setUrl(QUrl(urlStr)); |
| | |
| | | |
| | | void GetStockList::maTest100Slot() |
| | | { |
| | | for(int i=0;i<m_model->rowCount() && i < m_maTestNum;++i){ |
| | | ui->tableView->setCurrentIndex(m_model->index(i,0)); // 设置当前表格索引,主要是为了设置行 |
| | | // for(int i=0;i<m_model->rowCount() && i < m_maTestNum;++i){ |
| | | // ui->tableView->setCurrentIndex(m_model->index(i,0)); // 设置当前表格索引,主要是为了设置行 |
| | | // maPolicySlot(); // 调用MA策略去回测 |
| | | // } |
| | | |
| | | for(int i=0;i<m_customModel->rowCount() && i < m_maTestNum;++i){ |
| | | ui->tableView->setCurrentIndex(m_customModel->index(i,0)); // 设置当前表格索引,主要是为了设置行 |
| | | maPolicySlot(); // 调用MA策略去回测 |
| | | } |
| | | } |
| | | |
| | | void GetStockList::multiResonateTest100Slot() |
| | | { |
| | | for(int i=0;i<m_customModel->rowCount() && i < m_maTestNum;++i){ |
| | | ui->tableView->setCurrentIndex(m_customModel->index(i,0)); // 设置当前表格索引,主要是为了设置行 |
| | | multiResonatePolicySlot(); // 调用多策略共振策略去回测 |
| | | } |
| | | } |
| | | |
| | |
| | | qDebug()<<"执行MACD策略"; |
| | | emit sendInfoMess("<font size=12 color=pink>执行MACD策略 </font>"); |
| | | int curRow = ui->tableView->currentIndex().row(); |
| | | QString symbol = m_model->item(curRow,1)->text(); |
| | | // QString symbol = m_model->item(curRow,1)->text(); |
| | | |
| | | QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); |
| | | qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 |
| | | int numsCnt = 300; |
| | | QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=week&type=before&count=-%3&indicator=kline,macd").arg(symbol).arg(begin).arg(numsCnt); |
| | | qDebug()<<urlStr; |
| | | qDebug()<<"当前股票:"<<symbol<<m_model->item(curRow,0)->text(); |
| | | qDebug()<<"当前股票:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); |
| | | // 下一步就是根据url请求到的数据,进行分析 |
| | | m_menuIndex = 3; // 第四个菜单项 |
| | | m_request.setUrl(QUrl(urlStr)); |
| | | m_manager.get(m_request); |
| | | |
| | | } |
| | | |
| | | void GetStockList::buttomToUpPolicySlot() |
| | | { |
| | | /* |
| | | 复盘之前的月线突破情况,放量上涨,5倍左右,并且在60日均线上冲高,不回落,大概率可以继续冲 |
| | | 关注好冲的形态,加上很好的换手率80%+,甚至100%+,说明充分换手了,突破会更好,有就会赚多倍 |
| | | 并且多日查看,比例值一直在放大,说明很靠谱,就是有一个数值比例的爬升过程,那就可以重仓买入等收益了,可以绘制一条曲线来观察情况 |
| | | */ |
| | | |
| | | qDebug()<<"执行底部反转策略"; |
| | | emit sendInfoMess("<font size=12 color=pink>执行底部反转策略 </font>"); |
| | | int curRow = ui->tableView->currentIndex().row(); |
| | | // QString symbol = m_model->item(curRow,1)->text(); |
| | | |
| | | QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); |
| | | qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 |
| | | int numsCnt = 300; |
| | | QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,macd").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); |
| | | qDebug()<<urlStr; |
| | | qDebug()<<"当前股票:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); |
| | | // 下一步就是根据url请求到的数据,进行分析 |
| | | m_menuIndex = 4; // 第五个菜单项 |
| | | m_request.setUrl(QUrl(urlStr)); |
| | | m_manager.get(m_request); |
| | | } |
| | | |
| | | void GetStockList::multiResonatePolicySlot() |
| | | { |
| | | qDebug()<<"多策略共振:量能、MACD、MA、BOLL"; |
| | | emit sendInfoMess("<font size=12 color=pink>执行多策略共振 </font>"); |
| | | int curRow = ui->tableView->currentIndex().row(); |
| | | // QString symbol = m_model->item(curRow,1)->text(); |
| | | |
| | | QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); |
| | | qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 |
| | | int numsCnt = 200; |
| | | QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,macd,ma,boll").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); |
| | | qDebug()<<urlStr; |
| | | qDebug()<<"当前股票:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); |
| | | // 下一步就是根据url请求到的数据,进行分析 |
| | | m_menuIndex = 5; // 第六个菜单项 |
| | | m_request.setUrl(QUrl(urlStr)); |
| | | m_manager.get(m_request); |
| | | } |
| | | |
| | | void GetStockList::oneUpCrossFourSlot() |
| | | { |
| | | /* 一阳穿四线 |
| | | K线出现了大阳线并且贯穿4条均线,说明在猛涨了,并且量能也跟上的话,就说明强劲 |
| | | |
| | | 日K、周K、月K就很明显。 |
| | | 大趋势以周、月为主,适合中长线处理 |
| | | --------------------------- |
| | | 也非常适合超短线的处理,30分、60分、120分的大穿阳线也很明显 |
| | | --------------------------- |
| | | 就是开盘价和收盘价包含了一个区间,这个区间内都把Ma5 Ma10 Ma20 Ma30给包住了,说明触发了一阳穿四线 |
| | | */ |
| | | qDebug()<<"一阳穿四线策略"; |
| | | emit sendInfoMess("<font size=12 color=pink>执行一阳穿四线策略 </font>"); |
| | | int curRow = ui->tableView->currentIndex().row(); |
| | | // QString symbol = m_model->item(curRow,1)->text(); |
| | | |
| | | QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); |
| | | qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 |
| | | int numsCnt = 200; |
| | | QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,macd,ma,boll,market_capital").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); |
| | | qDebug()<<urlStr; |
| | | qDebug()<<"当前股票:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); |
| | | // 下一步就是根据url请求到的数据,进行分析 |
| | | m_menuIndex = 6; // 第七个菜单项 |
| | | m_request.setUrl(QUrl(urlStr)); |
| | | m_manager.get(m_request); |
| | | |
| | | } |
| | | |
| | | void GetStockList::oneUpCrossFourTest100Slot() |
| | | { |
| | | for(int i=0;i<m_customModel->rowCount() && i < m_maTestNum;++i){ |
| | | ui->tableView->setCurrentIndex(m_customModel->index(i,0)); // 设置当前表格索引,主要是为了设置行 |
| | | oneUpCrossFourSlot(); // 调用一阳穿四线去回测 |
| | | } |
| | | } |
| | | |
| | | void GetStockList::getCodeSlot() |
| | |
| | | |
| | | } |
| | | |
| | | void GetStockList::pollMultiSlot() |
| | | { |
| | | multiResonateTest100Slot(); // 多策略共振回测 |
| | | } |
| | | |
| | | void GetStockList::on_pushButton_industry_clicked() |
| | | { |
| | | // 获取行业信息,能拿到 行业代码和名字,简写等 |
| | |
| | | m_manager.get(m_request); |
| | | |
| | | } |
| | | |
| | | void GetStockList::getLastClosePrice(QString name) |
| | | { |
| | | for(int i=0;i<m_model->rowCount();++i){ |
| | | if(m_model->item(i,0)->text() == name){ |
| | | QString closePrice = m_model->item(i,5)->text(); |
| | | emit sendClosePrice(name,closePrice); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void GetStockList::on_pushButton_filterCap_clicked() |
| | | { |
| | | double begin = ui->lineEdit_beginCap->text().toDouble(); |
| | | double end = ui->lineEdit_endCap->text().toDouble(); |
| | | int rows = m_customModel->rowCount(); |
| | | for(int i=rows - 1;i > 0;--i){ |
| | | double allCap = m_customModel->data(m_customModel->index(i,2)).toDouble(); |
| | | if( allCap < begin || allCap > end){ |
| | | m_customModel->removeRow(i); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void GetStockList::on_pushButton_search_clicked() |
| | | { |
| | | ui->tableView->clearSelection(); |
| | | QString condition = ui->lineEdit_search->text(); |
| | | for(int i =0;i<m_customModel->rowCount();++i){ |
| | | if(m_customModel->data(m_customModel->index(i,0)).toString() == condition |
| | | || m_customModel->data(m_customModel->index(i,1)).toString() == condition) |
| | | { |
| | | //ui->tableView->setCurrentIndex(m_customModel->index(i,0)); |
| | | ui->tableView->selectRow(i); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | void GetStockList::on_lineEdit_search_returnPressed() |
| | | { |
| | | on_pushButton_search_clicked(); |
| | | } |
| | | |
| | | void GetStockList::showHistoryModelData(QVector<QVector<QString>> &model) // 从历史那边将数据发过来 |
| | | { |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | m_model->setRowCount(0); |
| | | for(int i=0;i<model.size();++i){ |
| | | //qDebug()<<"i="<<i; |
| | | QList<QStandardItem*> items; |
| | | m_codeNames[model[i][1]] = model[i][0]; |
| | | for(int j=0;j<model.at(0).size();++j){ |
| | | items.append(new QStandardItem(model[i][j])); |
| | | |
| | | if(j==2){ |
| | | items.append(new QStandardItem(model[i][j])); |
| | | } |
| | | if(j==3){ |
| | | QStandardItem *percentItem = items.back(); |
| | | if(percentItem->text().toDouble() > 0){ |
| | | percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 |
| | | percentItem->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 |
| | | items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 |
| | | } |
| | | else if(percentItem->text().toDouble() < 0){ |
| | | percentItem->setData(QColor("green"),Qt::BackgroundColorRole); |
| | | items.at(0)->setData(QColor("green"),Qt::TextColorRole); |
| | | } |
| | | } |
| | | |
| | | } |
| | | m_model->appendRow(items); |
| | | } |
| | | qDebug()<<"历史到信息赋值完成 行数:"<<m_model->rowCount(); |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | } |
| | | |
| | | void GetStockList::showHistoryModelData(QStandardItemModel *model) |
| | | { |
| | | |
| | | // qDebug()<<QDateTime::currentDateTime(); |
| | | // //ui->tableView->setModel(model); |
| | | // QVector<QVector<QString>> vec; |
| | | // for(int i=0;i<model->rowCount();++i){ |
| | | // //QString row; |
| | | // QVector<QString> tmp; |
| | | |
| | | // m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); |
| | | |
| | | // for(int j=0;j<model->columnCount();++j){ |
| | | // //row+=model->item(i,j)->text()+" "; |
| | | // tmp.append(model->item(i,j)->text()); |
| | | // } |
| | | // //qDebug()<<i<<row; |
| | | // vec.append(tmp); |
| | | // } |
| | | // qDebug()<<"vec size:"<<vec.size(); |
| | | |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | m_model->setRowCount(0); |
| | | for(int i=0;i<model->rowCount();++i){ |
| | | QList<QStandardItem*> items; |
| | | m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); |
| | | for(int j=0;j<model->columnCount();++j){ |
| | | items.append(new QStandardItem(model->item(i,j)->text())); |
| | | if(j==2){ |
| | | items.append(new QStandardItem(model->item(i,j)->text())); |
| | | } |
| | | if(j==3){ |
| | | QStandardItem *percentItem = items.back(); |
| | | if(percentItem->text().toDouble() > 0){ |
| | | percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 |
| | | percentItem->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 |
| | | items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 |
| | | } |
| | | else if(percentItem->text().toDouble() < 0){ |
| | | percentItem->setData(QColor("green"),Qt::BackgroundColorRole); |
| | | items.at(0)->setData(QColor("green"),Qt::TextColorRole); |
| | | } |
| | | } |
| | | } |
| | | m_model->appendRow(items); |
| | | } |
| | | qDebug()<<"历史到信息赋值完成 条数:"<<m_model->rowCount(); |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | } |