1.技术指标的计算
技术指标的计算在StkLib库中。
Technique.h 技术指标类定义
分别由下面的文件来实现。
TechCL.cpp 自有技术指标
TechEnergy.cpp 能量类技术指标
TechKLine.cpp K线叠加类技术指标
Technique.cpp 技术指标基类
TechSwing.cpp 摆动类技术指标
TechTrend.cpp 趋势类技术指标
TechOther.cpp 其它类技术指标
2.画技术指标
G:\stock\TskingVS2019\src\Client\StkUI\View\DrawTech.cpp
此文件是CStockGraph的类实现的一部分,专门负责画技术指标。
在CStockGraph类中,定义的一个技术指标的变量CTechParameters m_techparam; // 指标参数
void CStockGraph::DrawTechMA( CDC * pDC, CRect rect, BOOL bDrawTitle, double dMin, double dMax )
{
CKData & kdata = m_CurStock.GetKData(m_nCurKType);
m_techparam.ma.AttachParameters( AfxGetProfile().GetTechParameters().ma );
DrawTechUtil( pDC, rect, bDrawTitle, dMin, dMax, STT_MA, &(m_techparam.ma), &kdata, m_techparam.ma.m_adwMADays );
}
G:\stock\TskingVS2019\src\Client\StkUI\View\StrategyView.h
第二部分 股票策略对象的创建和使用
2.1 新建策略对话框
G:\stock\TskingVS2019\src\Client\StkUI\StkUI.cpp
//新建策略对话框 by freeman
void CStkUIApp::OnStrategyNew()
{
// TODO: Add your command handler code here
CStrategy * pStrategy = new CStrategy();
if( NULL == pStrategy )
{
AfxMessageBox( IDS_STRATEGY_FAILED, MB_OK | MB_ICONINFORMATION );
return;
}
CSetPrpt firstPage( NULL, IDS_STRATEGY_SETPRPT, NULL );
firstPage.m_dwButtonFlags = PSWIZB_NEXT | PSWIZB_DISABLEDFINISH;
firstPage.SetStrategy( pStrategy );
CSelectStk selectStk(NULL, IDS_STRATEGY_SELECTSTK, NULL);
selectStk.m_dwButtonFlags = PSWIZB_BACK | PSWIZB_NEXT | PSWIZB_DISABLEDFINISH;
CSetRule setrule(NULL, IDS_STRATEGY_SETRULE, NULL);
setrule.m_dwButtonFlags = PSWIZB_BACK | PSWIZB_NEXT | PSWIZB_DISABLEDFINISH;
setrule.SetTechParameters( &(pStrategy->GetTechParametersBuy()), &(pStrategy->GetSelectedTechsBuy()) );
CSetRate setrate(NULL, IDS_STRATEGY_SETRATE, NULL);
setrate.m_dwButtonFlags = PSWIZB_BACK | PSWIZB_FINISH;
setrate.SetStrategy( pStrategy );
CPropertySheetEx sht;
sht.AddPage( &firstPage );
sht.AddPage( &selectStk );
sht.AddPage( &setrule );
sht.AddPage( &setrate );
sht.SetWizardMode( );
sht.m_psh.dwFlags |= ( PSH_WIZARD97 | PSH_WIZARDHASFINISH /* | PSH_HEADER /*Header Bitmap*/ );
//CBitmap bmp;
//bmp.LoadBitmap( IDB_BALANG );
//sht.SetBitmap( (HBITMAP)bmp.GetSafeHandle() );
if( ID_WIZFINISH == sht.DoModal() )
{
pStrategy->SetStocks( selectStk.m_domainTemp );
pStrategy->SaveStrategyFile( firstPage.GetPathName() );
AddStrategy( pStrategy );
AfxSwitchToStaticView( RUNTIME_CLASS(CSimuView) );
}
else
{
delete pStrategy;
}
}
2.2 技术指标对象的创建
G:\stock\TskingVS2019\src\Client\StkLib\Src\Technique.cpp
根据技术指标对象的ID号来创建
// 创建新的技术指标对象
CTechnique * CTechnique::CreateTechnique( UINT nTech, CKData * pKData )
{
CTechnique * pTech = NULL;
switch( nTech )
{
case STT_MA: pTech = new CMA( pKData ); break;
case STT_BBI: pTech = new CBBI( pKData ); break;
case STT_BOLL: pTech = new CBOLL( pKData ); break;
case STT_PV: pTech = new CPV( pKData ); break;
case STT_SAR: pTech = new CSAR( pKData ); break;
case STT_DJ: pTech = new CDJ( pKData ); break;
case STT_CW: pTech = new CCW( pKData ); break;
2.3 技术指标的自动创建
G:\stock\TskingVS2019\src\Client\StkLib\Src\Strategy.cpp
/////////////////////////////////////////////////////////////////////////
// Cache
// 准备数据,读取K线数据,长周期K线数据,生成技术指标对象
BOOL CStrategy::PrepareData( SIMULATION_CALLBACK fnCallback, void * cookie )
{
if( m_techstocks.GetSize() == m_stocks.GetSize() )
return TRUE;
ClearCache( );
// m_techstocks.m_kdataIndex m_techstocks.m_infoIndex
if( m_opparam.m_bIndexTrend ) // 指数K线数据
{
CStockInfo infoIndex;
if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAIN, &infoIndex ) )
{
m_techstocks.m_infoIndex = infoIndex;
CStock stockIndex;
stockIndex.SetStockInfo( &infoIndex );
stockIndex.SetDatabase( &AfxGetDB() );
stockIndex.PrepareData( CStock::dataK, m_opparam.m_nKTypeIndex );
CKData & kdataIndex = stockIndex.GetKData(m_opparam.m_nKTypeIndex);
kdataIndex.SetMaindataType( m_opparam.m_nMaindataType );
m_techstocks.m_kdataIndex = kdataIndex;
// m_techstocks.m_techsIndex
for( int j=0; j<m_anTechsIndexTrend.GetSize(); j++ ) //创建技术指标对象
{
CTechnique * pTech = CTechnique::CreateTechnique( m_anTechsIndexTrend[j], &(m_techstocks.m_kdataIndex) );
m_paramIndexTrend.FindParameters( m_anTechsIndexTrend[j], pTech );
m_techstocks.m_techsIndex.Add( pTech );
}
}
}
G:\stock\TskingVS2019\src\Client\StkUI\View\SelectorView.cpp
void CStkUIApp::OnStrategyClose()
{
// TODO: Add your command handler code here
CSimuView * pSimuView = AfxGetSimuView();
CStrategy * pActive = AfxGetActiveStrategy();
CStrategyView * pStrategyView = AfxGetStrategyView();
第三部份 股票策略的应用
1.股票策略选股
G:\stock\TskingVS2019\src\Client\StkLib\Src\Container.cpp
//股票列表底部菜单分类、策略选股 by freeman
BOOL CStockContainer::RetrieveFromStatic( int nType, LPCTSTR lpszDomain, CStrategy * pStrategy, DWORD dwDate )
{
CSPMutex::Scoped l(m_mutex);
....
case typeStrategy:
{
if( pStrategy )
RetrieveSpecify( pStrategy->GetStocks() );
}
break;
.....
}
2.新建股票策略,添加到股票策略列表
G:\stock\TskingVS2019\src\Client\StkUI\StkUI.cpp
//打开股票策略文件 by freeman
CStrategy* CStkUIApp::OpenStrategyFile( LPCTSTR lpszPathName )
{
....
//新建一个股票策略
CStrategy * pStrategy = new CStrategy();
if( NULL == pStrategy )
return NULL;
char szErr[256];
if( !pStrategy->OpenStrategyFile( szPath, szErr, sizeof(szErr)-1 ) )
{
AfxMessageBox( szErr, MB_OK|MB_ICONINFORMATION );
delete pStrategy;
return NULL;
}
//加入股票策略列表
AddStrategy( pStrategy );
return pStrategy;
}
G:\stock\TskingVS2019\src\Client\StkUI\resource.h
#define ID_VIEW_TECHKLINE 33275 //K线图指标显示 id定义
股票策略源代码 c++