Advanced Strategy C++ SDK - Trading
Framework
(Professional
Software Solutions) Feb
18th, 2015
Welcome to the advanced Strategy C++ SDK - a
Trading Framework from Professional Software Solutions which allows
you to:
- Manage PARALLEL and OVERLAPPING Strategy setups
- Offline Test Module for Bar by Bar testing and debugging
- Detailed diagnostic for each Strategy Setup - Example:
Setup_VXX_1Min.txt
Create a new Strategy Module
Turbo backtesting using the BTSeqMgr Engine
How to create a PSS Strategy Logic Module:
Name: Create a module name(Max 8): TRD_XXX | |||||
Delete DLLMain() | |||||
Add PATHs: C++/Preprocessor: ..\..\..\..\Core\Utilities,..\..\..\..\Core\Graph,..\..\TS\LIB | |||||
Adjust StdAfx.h: XXStdAfx.h DLL_LOG_NAME, BCM_BASE | |||||
Create Strategy Module from:: XXStrat.h and XXStrat.cpp | |||||
Create Parameter List: XX_Par.txt
in C:\Database\TRD_XX\XX_Par.txt 10/Lookback|10 11/EntryOffsetL|0 12/EntryOffsetS|12 13/TargetOffsetL|100 14/TargetOffsetS|100 15/StopOffsetL|100 16/StopOffsetS|100 17/MaxEntryWait|20 18/PosAge|20 0/LastBarOnChart|0 1/MinMove|0.01 2/BigPointAmt|1 3/Comm|2 4/Slip|0 5/Strat|101 6/BGMode|0 7/MaxData|20 8/StockPosAmt|5000 9/nBTWFMgrExport|2 |
|||||
Add DLL entry points to DLL Main module: XXDLL.cpp | |||||
You can add a new Functions: XXDLLFU.cpp PSS_Func1() - Bar Info in Arguments - EasyLanguage Example: XXFun1.txt PSS_Func2() - Bar Info and parameters in float array- Example: XXFun2.txt - (works only in TS) PSS_Func3() - Bar Info and parameters in array and accessed via EL Global Object - EasyLanguage Example: XXFun3.txt |
|||||
Add low level function modules: CTxt, DLLUtil, DLLTempl, DateTime, GetDateLong, HttpGet, LaunchFile, RamFile, REG, ShowProgress, SPtrArray, TS: BarMgr, IF Strategy: BarCalcMgr, PosAnaMgr, DataVal |
|||||
Define the In/Out Array Size: #define PSSTRD_MAXIN 50 // Max 50 Inputs #define PSSTRD_MAXOUT 100 // Max 100 Outputs float farrValIn[PSSTRD_MAXIN]; float farrValOut[PSSTRD_MAXOUT]; ZAP0(farrValIn,sizeof(farrValIn)); ZAP0(farrValOut,sizeof(farrValOut)); |
|||||
Strategy Module Parameter Load: int CMSStrat::OnStratSetInputs() m_nLookback = GetStratParInt(10); m_pBGM->m_bLoadGlobPar = FALSE/TRUE; |
|||||
Strategy Module Calculate Indicator
Tracks: m_pBCM1->GetIBCMStrat()->OnCalcTracks(nDataTrack,pBar,bAdd); int CMSStrat::OnCalcTracks(int nDataTrack,CBarCalcData *pBar,BOOL bAdd) |
|||||
Strategy Module Bar Processing Logic: int ret = m_pBCM1->GetIBCMStrat()->OnProcessNewBar(pValOut); int CMSStrat::OnProcessNewBar(float *pValOut) |
|||||
MAIN Strategy Module Logic: int CMSStrat::OnCalcSetup(CTrdSetup *pSetup,float *pValOut) int nStage = pSetup->GetStage(); switch (nStage) { case 1,2,3: case BCM_SET_ENTRYSTAGE: // still trying to enter (10) case BCM_SET_ENTRYSTAGE+1: // have entered (11) |
|||||
Check for Entry: add Strategy Entry logic in CXXXStrat::OnCheckForNewSetup() pSetLast = AddSetup( 1,GetBarLast1(),txtData,m_txtColHdr); |
|||||
Process Position Entry: int CTrdSetup::AddSetupBar(CBarCalcData *pBar,float *pValOut) If Filled - call: SetEntry(pBarNew->m_Bar.m_fO); // Market Order - entry at open price int CTrdSetup::SetEntry(float fPrcE) m_fPrcEGot and m_nBarNbrE and m_nDTE |
|||||
Check for Exit: int CTrdSetup::CheckExit(float *pValOut) |
|||||
How to add Indicator Value(s)
(RSI, Stochastic etc) to your Strategy:
|
|||||
- add calculation if live values in CXXXStrat::CalcNewBar() - add strategy input assignments in CXXXStrat::OnStratSetInputs() - add Bar Calc Tracks in CXXXStrat::OnCalcTracks() - add Startegy Stage and entry logic in CXXXStrat::OnCalcSetup() - set Strategy Par Text file in CXXXoStrat::OnStratInit() - setup Strategy Par Text file M:\srcpss\Apps\StockData\TS\BTSeqMgr\DC_Par.txt\XXX_Par.txt let copy to C:\Database\HWLC - Define Parameter file in "m_txtFnGlobPar/m_arrGlobParTxt" - used in CBarCalcGlobalMgr::LoadGlobPar() define in CVAStrat::OnStratInit() via txtFnPar.Format("%s/VA_Par.txt",VA_BASE); GetBGM()->SetGlobParFn(txtFnPar); |
|||||
Fast Backtest (StratBT):
|
Detailed Strategy diagnostic Example
Detailed diagnostic for
each Strategy Setup - Example 1Min VXX - Setup_VXX_1Min.txt Setup#0016|Long |VXX_I1_T1_STRATSNA_12H |Date |Time |BarNbr|Open |High |Low |Close |VolumeUp |VolumeDown|Dir|SeqNbr|Stage|Age |Profit$| Stop| Target| Entry|Size|EBar |TarPrc |StopPrc |SUBar |PivBar |PrcWant |PivSeq | Start |03/03/2014|12:17:00| 117| | | | | | | | | | | | | | | |03/03/2014|12:17:00| 117| 46.64| 46.69| 46.57| 46.60| 589| 536|L | 16| 10| 0| 0.0$| 46.24| 46.66| 46.46| 400|0 |46.66 |46.24 |117 |115 |46.46 |1 | | | |Sufficient Price Change: Pivot Bar#115(2014-03-03 12:15:00), Change=2.05% Want=1.20%(L),2.40%(S)| | | |Set EntryPrc to 46.46| | | |Changed Stop 0.00 -> 46.24| | | |Set Target 0.00(NotYetSet) -> (46.66)| | | |400 Shares Limit Entry @ 46.46, Stop=46.24, Target=46.66 (Ref=46.4100, Entry=46.4600, Target=46.6600, Stop=46.2400 Size=400, Wait=900Sec, PosExit=1080Sec)| |03/03/2014|12:18:00| 118| 46.58| 46.69| 46.58| 46.63| 602| 364|L | 16| 10| 1| 0.0$| 46.24| 46.66| 46.46| 400|1 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:19:00| 119| 46.65| 46.70| 46.58| 46.64| 537| 626|L | 16| 10| 2| 0.0$| 46.24| 46.66| 46.46| 400|2 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:20:00| 120| 46.64| 46.85| 46.61| 46.83| 818| 529|L | 16| 10| 3| 0.0$| 46.24| 46.66| 46.46| 400|3 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:21:00| 121| 46.84| 46.85| 46.68| 46.70| 473| 554|L | 16| 10| 4| 0.0$| 46.24| 46.66| 46.46| 400|4 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:22:00| 122| 46.71| 46.72| 46.55| 46.63| 396| 499|L | 16| 10| 5| 0.0$| 46.24| 46.66| 46.46| 400|5 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:23:00| 123| 46.62| 46.65| 46.49| 46.53| 454| 382|L | 16| 10| 6| 0.0$| 46.24| 46.66| 46.46| 400|6 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:24:00| 124| 46.53| 46.68| 46.49| 46.66| 405| 270|L | 16| 10| 7| 0.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:25:00| 125| 46.65| 46.65| 46.44| 46.44| 156| 334|L | 16| 11| 8| -8.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | | | |Entered @ 46.46 (Want=46.46, ShouldCross=1, Exact=1, IsStopE=0, Bar#=125)| |03/03/2014|12:26:00| 126| 46.45| 46.47| 46.32| 46.38| 474| 476|L | 16| 11| 9| -32.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:27:00| 127| 46.39| 46.57| 46.38| 46.56| 308| 200|L | 16| 11| 10| 40.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:28:00| 128| 46.56| 46.60| 46.47| 46.49| 280| 259|L | 16| 11| 11| 12.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:29:00| 129| 46.49| 46.58| 46.46| 46.53| 274| 146|L | 16| 11| 12| 28.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:30:00| 130| 46.52| 46.66| 46.51| 46.61| 312| 203|L | 16| 11| 13| 60.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:31:00| 131| 46.63| 46.64| 46.49| 46.58| 252| 322|L | 16| 11| 14| 48.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:32:00| 132| 46.59| 46.65| 46.54| 46.58| 191| 197|L | 16| 11| 15| 48.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:33:00| 133| 46.58| 46.58| 46.49| 46.54| 262| 177|L | 16| 11| 16| 32.0$| 46.24| 46.66| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | |03/03/2014|12:34:00| 134| 46.54| 46.68| 46.54| 46.61| 241| 170|L | 16| 20| 17| 80.0$| 0.00| 0.00| 46.46| 400|7 |46.66 |46.24 |117 |115 |46.46 |1 | | | |Reached Target @ 46.66 (ShouldCross=1)| End |03/03/2014|12:34:00| 134| | | | | | | | | | | | | | | |
You an add a
commentary - so the Strategy/Indicator can talk in
the Chart! via: View/Analysis Commentary - then
click on a bar
{====== SHOW BAR COMMENT =============================================} IF AtCommentaryBar and CommentaryEnabled THEN BEGIN Vars: cmt(""); cmt = cmt + "Bar#" + numtostr(barnumber,0) + " Close=" + numtostr(C,5) + " High=" + numtostr(H,5) + " Low=" + numtostr(L,5) + newline; cmt = cmt + "Pos="+numtostr(marketposition,0) + " PosAge=" + numtostr(BarsSinceEntry,0) + " Left=" + numtostr(CurrentContracts,0) + " Entry=" + numtostr(EntryPrice,5) + " ExitAge=" + numtostr(BarsSinceExit(1),0) + newline; commentary(cmt); END; |
To check live values during processing add a Print
Debug message - and view via: View/Print Log: print(BarNumber:5:0,"# D=",Mod(Date,1000000):6:0," T=",Time:4:0," oPeakBar=",oPeakBar:4:0," oTRWid=",oTRWid:7:2," peak=",PeakStrength:7:2," Drop=",nDropPer:7:2," nAvgTR=",nAvgTR:7:2); |
Entry/Exits: Buy("LE") next bar LEVal limit; SellShort("SE") next bar SEVal limit; Sell ("LEx") next bar Market; Sell("LTar") next bar TargetPrc limit; Sell("LStp") next bar StopPrc stop; Buy to Cover("STar") next bar TargetPrc limit; Buy to Cover("SStp") next bar StopPrc stop; |
Advanced Turbo Backtesting using BTSeqMgr Engine
Ultimately the Stratgy will be used in TS/MC to
execute automated trades. The BTSeqMgr offers a much faster way to backtest than TS or MC, because the strategy logic is integrated and compiled as a C++ Object/Module! Below you will find the steps to add and run a backtest using BTSeqMgr |
|||||
Add Strategy Logic Module to BTSeqMgr
Workspace (into new Branch):![]() Add the XXStrat.h also to the StdAfx.h: #if SEQ_HW == 1 #include "..\PSS_SNA\SnaStrat.h" #include "..\..\TRD\TRD_MS\MSStrat.h" ... #endif |
|||||
Add Strategy Name to Class Factory: CBTSeqMgrDlg::ThreadBTRun() if (StringCompare(pDlg->m_BTS.GetStratName(),"MS",1) == 0) { CMSStrat *pMS = new CMSStrat; pDlg->m_BTS.SetTopStrat(pMS); pMS->SetBTSes(&pDlg->m_BTS); } |
|||||
Create special Seq *.hws File: Create a *.hws
file with the specifics Example: Workspace= Symbols=VXX EndDate=5/6/2014 StratName=MS Template= Intra/1|1/1/2013 OptSet= 10/PivLeftL|8 11/PivRight|2 12/EntryOffsetL|5 13/MaxEntryWait|15 14/TargetOffsetL|18,19,20 15/StopOffsetL|22,30 16/MinPriceChangeL|1.00,1.05,1.10,1.15,1.20 17/LSFilter|0 18/PivSeq|1 19/PosAgeL|18 20/PivLeftS|10,11,12 21/EntryOffsetS|5 22/TargetOffsetS|16,18,20,22 23/StopOffsetS|16 24/MinPriceChangeS|2.4,2.5,2.6 25/ChgLeftL|10 26/ChgLeftS|8 27/FixedTrdSize|0 28/OppPivotExitWait|10 29/PosAgeS|0 30/TimeStart|93000 31/TimeEnd|153000 32/DayEnd|155000 9/nBTWFMgrExport|0 SymVXX= 1/MinMove/ParFlt|0.0100 2/BigPointAmt/ParFlt|1.0000 3/Comm/ParFlt|1.00 4/Slip/ParFlt|0 5/StratNbr|101 8/TrdCapital|10000 |
|||||
BackTest execution in: int CBTSession::RunScript(const char *pFn,CTxt &txtErr) | |||||
Creates BT Base folder: "C:/Database/BT/MS_ALL/SES_0001"
- Debug: "C:/Database/BT/MS_ALL/SESSION" Command Execution: int ret_ = RunBTCmd(pCmd"OptSet;@C:\Database\MktScan\MS_20150226.txt;Intra/1|1/1/2013|01/02/1900;",txtErr); |
|||||
BackTest Reversals - turn Event Sorting OFF
|
|||||
OLD (join with Top)
TS Reserved Variables:
|
||||||||||
How To Add Strat.txt - New Folder for strat def (M:\srcpss\Apps\StockData\TS\MyIdeas\DCGo) - Clone: (ST_TRD.txt, ST.cpp, ST.h) - New Seq Def Files: ST.hws (M:\srcpss\Apps\StockData\TS\BTSeqMgr) StratName=VA defines the name used in: m:\srcpss\Apps\StockData\TS\BTSeqMgr\BTSeqMgrDlg.cpp(1020) if (StringCompare(pDlg->m_BTS.GetStratName(),"VA",1) == 0) CVAStrat *pVA = new CVAStrat; Data used for backtest: Workspace= Symbols=TVIX EndDate=9/30/2013 StratName=VA Template= Intra/5|3 Months -OR- Intra/5|1/1/2013 - New Par File: ST_Par.txt in "C:/Database/PSS_VA/VA_Par.txt" used in: int CVAStrat::OnStratInit(float *pValBar) - New? ST_TRD.txt (M:\srcpss\Apps\StockData\TS\BTSeqMgr) - New Folder in BTSeqMgr (DCGo) - Adjust ST.cpp/h to new name - add Strat Inputs: FIXED STRATEGY PARAMETER - add Strat Values: LIVE BAR VALUES #define BAR_DCUP 0 // DC Upper band - add Strat calculated custom values: DEFINE CALCULATED SETUP VALUES #define STRAT_E_BAR 0 - add calculation if live values in CXXXStrat::CalcNewBar() - add strategy input assignments in CXXXStrat::OnStratSetInputs() - add Bar Calc Tracks in CXXXStrat::OnCalcTracks() - add Strategy Entry logic in CXXXStrat::OnCheckForNewSetup() - add Startegy Stage and entry logic in CXXXStrat::OnCalcSetup() - set Strategy Par Text file in CXXXoStrat::OnStratInit() - setup Strategy Par Text file M:\srcpss\Apps\StockData\TS\BTSeqMgr\DC_Par.txt\XXX_Par.txt let copy to C:\Database\HWLC - Define Parameter file in "m_txtFnGlobPar/m_arrGlobParTxt" - used in CBarCalcGlobalMgr::LoadGlobPar() define in CVAStrat::OnStratInit() via txtFnPar.Format("%s/VA_Par.txt",VA_BASE); GetBGM()->SetGlobParFn(txtFnPar); - set up trading ELD XX_TRD.txt - add new CXXXStrat in CBTSeqMgrDlg::ThreadHWSeq() - add CXXXStrat.h to StdAfx.h in BTSeqMgr - add switch (nStratNbr) in PSSTRD2() in PSS_TRD.cpp for DLL interface - add StratNbr and ColHdr in CXXXStrat::CXXXStrat() - set StratNumber also in ELD XXX_TRD.txt - arrPSSTRD1[5] = 101; - add any context variables to XX_XX.hts - Export test data - (nBGMode=2) into c:\Database\HWLC\TRD_Sym_Par.txt and TRD_Sym_Data.txt WATCH out for append trap - remove old data - Copy to - Run to Strat to check logic \SpeherLLC\PSS_TRD\StdAfx.hChange text pointer for log file and Diag files //#define DLL_LOG_NAME "PSS_TRD" //#define DLL_LOG_HOME "C:/Database/HWLC" #define DLL_LOG_NAME "ATR_TRD" #define DLL_LOG_HOME "C:/Database/ATR" Example to integrate into TS: http://www.profsoftware.com/download/el_20080430_G3/ http://www.profsoftware.com/download/el_20080515_G3B/ m:\srcpss\Apps\StockData\TS\EL_Consult\20080501_George3\G3_TRD\G3_TRD.cpp(149) int G3_TRD0(LPSTR *pSym,float *pValStratPar,float *pValBar,float *pValOut,CTxt &txtErr) //====== TS INTERFACE - COLLECT ARRAY VALUES AND PASS ON AS STANDARD FLT ARRAY === int __stdcall G3_TRD1(LPSTR *pSym,IEasyLanguageObject *pEL) BTMode(1) = Backtest Mode: 1=with detailed diagnostics(Setup_XX.txt, for development) 0=No diagnostics(for backtesting) George Pages: http://www.profsoftware.com/download/el_20080515_G3B/ http://www.profsoftware.com/download/el_20080430_G3/ http://www.profsoftware.com/download/el_20090430_G4/ |
XXX | Strategy Mnemonic (2 - 3 capital letters) |
DLL | a) New Win32 Dynamic-Link Library b) simple DLL Location: M:\srcpss\Apps\StockData\TS Project Name TRD_XXX c) Into VSS Location: M:\srcpss\Apps\StockData\TS Project: TRD_XXX |
stdafx.h | Sample main include Adjust: DLL_LOG_NAME, DLL_LOG_HOME,BCM_BASE |
XXX_TRD.def | Create Entry points |
XXX | Strategy Mnemonic (2 - 3 capital letters) |
stdafx.h | Sample main include Adjust: DLL_LOG_NAME, DLL_LOG_HOME,BCM_BASE |
XXX_TRD.def | Create Entry points |
Inherited | XXX_Strat.h/cpp: The new Strategy Class is
inherited from "CPTStrat": class
CXXXStrat : public CPTStrat Contains: a) Calculated Bar Values (BAR_XXX) b) Calculated Strategy Setup Values (STRAT_XXX) c) Added Custom Functions: int CheckCross(float fDelta,char cLS,CTxt &txtData,BOOL bInvert); d) Fixed Strategy Parameter: m_xxx - set in int CMSCStrat::OnStratSetInputs() e) Live Bar Values: m_fXXX |
Main Entry | int XXX_TRD0(LPSTR *pSym,float *pValStratPar,float *pValBar,float *pValOut,CTxt &txtErr) Called from Test NonDup and Chart function: int __stdcall MSC_TRD1(LPSTR *pSym,IEasyLanguageObject *pEL) |
Strat Entry Check | int CXXXStrat::OnCheckForNewSetup() xxx |
Debug | Project/Settings/Debug - Browse to: "M:\srcpss\Apps\NonDup\Debug\NonDup.exe" Working Directory: "C:\Database\MSC_TRD" Stack: CMSCStrat::OnCheckForNewSetup() line 199 CMSCStrat::OnProcessNewBar(float * 0x0018f5b8) line 63 + 13 bytes CPTStrat::OnProcessDataTracks(const char * 0x002ca938, float * 0x0018f734, float * 0x0018f658, float * 0x0018f5b8, int 95, int 40, CTxt & {...}) line 10279 + 43 bytes CPTStrat::Strat_ProcessBar(float * 0x0018f734, float * 0x0018f658, float * 0x0018f5b8, int 95, int 40, CTxt & {...}) line 2895 + 69 bytes MSC_TRD0(char * * 0x00254b40, float * 0x0018f734, float * 0x0018f658, float * 0x0018f5b8, CTxt & {...}) line 159 + 28 bytes Test_MSCTRD() line 3088 + 35 bytes |
Crash Debug | Many calls to set the BGM Progress State: GetBGM()->SetBGMProc(6020);
setting: CBarCalcGlobalMgr::m_nBGMProc Retrieve via : GetBGMProc() LOGTRACE("PSSTRD",1,"CRASH ERROR1 BGMState=%d",pBGM->GetBGMProc()); |
BackTest | //#define BGM_BT 1 // Activate BT Functions in BGM/BCM Modules |
Each Bar Proc | Each Bar is processed via the function: int CPTStrat::Strat_ProcessBar(float *pValStratPar,float *pValBar,float *pValOut,int nMaxVal1,int nMaxVal2,CTxt &txtErr) Which checks if start a new run: BOOL bNewRun = ((nBarNbr < m_nStratBarNbr1) || (m_nStratBarNbr1 == 0)); If bNewRun==TRUE: init new run: a) Reset All fixed Strategy parameter: ZAP0(m_fStratPar,sizeof(m_fStratPar)); - PSSTRD_MAXVAL1 b) Copy fixed startegy parameter: for (int iPar=0; iPar < m_nMaxPar; iPar++) m_fStratPar[iPar] = pValStratPar[iPar]; c) Load Global Parameter: m_pBGM->LoadGlobPar(pValStratPar,m_nMaxPar,TRUE); // force in case Strat Input changes into text array: m_arrGlobParTxt: Needs the XXX_PAR.txt file: 10/Source|1 11/MA1Length|3 12/MA2Length|10 ... 0/LastBarOnChart|0 1/MinMove|0.25 2/BigPointAmt|50 3/Comm|4 4/Slip|0 5/Strat|101 6/BGMode|0 7/MaxData|20 8/StockPosAmt|12000 9/nBTWFMgrExport|2 d) Load and process fixed Strategy parameter(see below) int CMSCStrat::OnStratSetInputs() e) Calculate the Tracks for all data tracks (m_nMaxData=1) int CPTStrat::OnProcessDataTracks(const char *pSym,float *pValStratPar,float *pValBar,float *pValOut,int nMaxVal1,int nMaxVal2,CTxt &txtErr) Get the data specific BCM: CBarCalcMgr *pBCM = GetStratBCM(nDataTrack-1); Extract the bar values: int nBarNbr = (int)pValBar[iVal+7]; ... float fO = pValBar[iVal+2]; Add new bar to BCM: iBar = pBCM->AddBar(&nDT,fO,fH,fL,fC,fV,nBarNbr,FALSE); pBar = pBCM->GetCalcBar(iBar); f) Calculate Tracks: (m_bIntraBarTick = FALSE) - int CMSCStrat::OnCalcTracks(int nDataTrack,CBarCalcData *pBar,BOOL bAdd) |
HWS | In the hws script we define the
backtesting ranges of each parameter within the BTSeqMgr fast
backtest framework - StratName=SNA - defines the Startegy Class CBTSeqMgrDlg::ThreadBTRun() if (StringCompare(pDlg->m_BTS.GetStratName(),"SNA",1) == 0) { CSNAStrat *pSNA = new CSNAStrat; pDlg->m_BTS.SetTopStrat(pSNA); pSNA->SetBTSes(&pDlg->m_BTS); } See BTSeqMgr backtest Framework: int CBTSession::RunScript(const char *pFn,CTxt &txtErr) Example: Workspace= Symbols=VXX EndDate=2/14/2014 StratName=SNA Template= Intra/1|9/1/2013 OptSet= 10/PivLeft|20,30 11/PivRight|2 12/EntryOffset|4 13/MaxEntryWait|15 14/TargetOffset|20 15/StopOffset|50 16/MinPriceChange|1.7,1.71 17/LSFilter|0 18/PivSeq|1 19/PosAge|20 9/nBTWFMgrExport|0 SymVXX= 1/MinMove/ParFlt|0.0100 2/BigPointAmt/ParFlt|1.0000 3/Comm/ParFlt|3.00 4/Slip/ParFlt|0 5/StratNbr|101 8/TrdCapital|10000 |
RunScript (HWS) | BTSeqMgr backtest Framework: int CBTSession::RunScript(const char *pFn,CTxt &txtErr) - "M:/srcpss/Apps/StockData/TS/BTSeqMgr/SNA_VXX1.hws" (m_bRunAsIndicator = TRUE for special mode: int CBTSession::PrepareForIndicatorRun(const char *pFnDef,CTxt &txtErr)) Create Session Folder: "C:/Database/BT/SNA_VXX1/SES_0009" - Debug - fixed: "C:/Database/BT/SNA_VXX1/SESSION" Copied backtesting script (0) M:/srcpss/Apps/StockData/TS/BTSeqMgr/SNA_VXX1.hws -> C:/Database/BT/SNA_VXX1/SESSION/SNA_VXX1.hws Execute Command: "OptSet;VXX;Intra/1|9/1/2013|02/14/2014;" int ret_ = RunBTCmd(pCmd,txtErr); Preload Data: PreloadBCM("VXX","Intra/1","9/1/2013|02/14/2014") ATTACHED STRAT TO BCM1: m_pBCM1->AddStrat(m_pStrat,m_pBCM1,fValBar[]); m_pStrat->SetBCM(m_pBCM1,m_pBGM); m_StratPar.m_pBTSes = this; m_ContextPar.m_pBTSes = this; EXTRACT SYMBOL SPECIFIC TRADING PARAMETER: SymVXX= 1/MinMove/ParFlt|0.0100 2/BigPointAmt/ParFlt|1.0000 3/Comm/ParFlt|3.00 4/Slip/ParFlt|0 Load Strategy Parameter (Permutations) and TRANSFER GLOBAL PARAMETER TO STRAT SET: int CBTStratParMgr::LoadStratPar(CTxtArray *pArr,CTxt &txtErr) FORCE FAST BGMMODE: Par6 (BCM_DIAG_COLID) = 0 m_pStrat->SetDiag(FALASE) nBTWFMgrExport = 2 (Equity) m_pBGM->m_nBGMMode = CBarCalcGlobalMgr::BGM_MODE_FAST; Init BTWF Hdr: ExportBTHdr(txtErr) PROCESS EACH PERMUTATION: for (m_iCurrPerm=0; m_iCurrPerm < m_nMaxPerm; m_iCurrPerm++) CBTStratParMgr::SetPerm(m_iCurrPerm) "NewRun 1 of 2: MinPriceChange=1.7" PROCESS EACH BAR: for (int iBar=0; iBar < nMaxBar; iBar++) CBarCalcData *pBar1 = m_pBCM1->GetCalcBar(iBar); ret = m_pStrat->Session_ProcessBar(&m_StratPar,bNewRun,txtErr,pBar1); Writing Trades: class CBTSession - CRamFile m_rfiEvt; int CBTSession::WriteEvt(BYTE *pEvtRam,int nBy) int CTrdSetup::WriteEvt(CBTSession *pBTSes) |
BTMode(1) | In the hws script is the line
defining the Backtest Mode: 0=No diagnostics(for backtesting) 1=with detailed diagnostics(for development) |
Loading Strat Par | int CMSCStrat::OnStratSetInputs() Initiate the startegy parameter:m_nMA1Length = GetStratParInt(11); using: GetStratParInt(11); GetStratParFlt(31); |
Calculate Tracks | Here we customize the bar calculations
for the strategy: int CMSCStrat::OnCalcTracks(int nDataTrack,CBarCalcData *pBar,BOOL bAdd) Init in: If (nMaxTrack < 1) Init Example: CBarCalcTrack::BarCalcValSrc nSrc = CBarCalcTrack::BARCALC_SRC_C; CBarCalcTrack *pTrack = GetBCM1()->AddCalcTrack(nBarCalcType,nSrc,fPar,txtErr); if (pTrack == NULL) return -1; AddCalcTrack(pTrack); Calc Example: pTrack->CalcTrackBar(pBar); in: int CBarCalcTrack::CalcTrackBar(CBarCalcData *pBar,float *pfSrc,CBarCalcData *pBar2) switch (m_nCalcType) { case BARCALC_TYP_PIVH: } if (m_bBarOutput == TRUE) Available Calculations defined in BarCalcMgr.h: enum BarCalcType { BARCALC_TYP_NONE, BARCALC_TYP_EXT, // External (Strategy) Fill BARCALC_TYP_MA, ... |
Data Dump | At the end of the Run the framework calls: FLOAT
XXX_TRD4(LPSTR *pSym,LPSTR *pCmd,LONG nDate,LONG nTime,INT
nBarNbr) typedef FLOAT (*PSSTRD5)(LPSTR,LPSTR,LONG,LONG,INT); float fVal = (*pPSSTRD5)((CHP)txtSym,"G/ExportCSV",0,0,0); which calls: return pBGM->ProcessDataRequest((CHP)pSym"@ES",(CHP)pCmd"G/ExportCSV",nDate,nTime,nBarNbr); which also exports the Startegy Setups and parameters used in the last run |
Tick by Tick | Can be switched on via: which accumulates each tick internally and then creates a new bar m_bTickByTick - in BillFarm set: pBSStrat->m_bTickByTick = TRUE; |