Diamond Backtesting with Walk Forward Manager
(BTWFMgr)
Strategy Code Preparation
(Professional Software Solutions)
BTWFMgr allows you to easily add a small backtesting data
collection section to your
strategy EasyLanguage®
code
using the C:/BTWFMgr/BTPrep.exe
Strategy preparation Module.
See the Code example below - BTWFMgr can work with
many different data sources,
because
BTWFMgr uses a modular appraoch, which translates the various data sources into a standard btwf1/2 format:
Open Editor with your Strategy Code
|
||||||||||
Open the Diamond BTWFMgr Start/Programs/Diamond Backtesting with Walk Forward Manager (BTWFMgr)/Backtesting with Walk Forward Manager (BTWFMgr) Click on the "Strategy Preparation" button (or File/Strategy Preparation) |
||||||||||
or Open the Strategy Preparation Module Start the Strategy Preparation Module (C:/BTWFMgr/BTPrep.exe) directly: |
||||||||||
Loading Strategy EasyLanguage Code The easiest is to use the "Load from Clipboard" button a) Open your Strategy EasyLanguage Code in the TradeStation Editor - or Multicharts formla editor b) Select the entire Strategy test (Edit/Select All or Ctrl+A) c) Copy the entire Strategy Code to the Clipboard (Edit/Copy or Ctrl+C) d) Click on the "Load from Clipboard" button e) Confirm the modification - click on YES g) Click on the "Modify Strategy" buitton the Enter the strategy name into the "Strategy Name" box h) The newly modified Strategy Code will appear in NOTEPAD i) Select the entire text again (Edit/Select All or Ctrl+A) j) Copy the new code (Edit/Copy or Ctrl+C) k) Paste the new text to the EasyLangugae Window (Edit/Paste or Ctrl+V) |
||||||||||
Adjust Strategy Inputs for the backtest Optimization The Strategy Input parameter will appear in a list modify any setting in the Strategy Input parameter list (see point 5 below) All numeric variables - which can be used in backtesting optimizations - are pre-selected with an X in the "Optimize" column To select/de-select a variable double click on that line - and the X will appear/disappear To save overhead - select only those Strategy variables you will actually use in the backtest optimizations: |
||||||||||
MultiChart Checkbox If you use MultiCharts Strategy EasyLanguage Code - enable the "Multichart64" checkbox: |
||||||||||
Modify Strategy Finally click on the "Modify" button This will automatically popup the Notepad Text with the modified Strategy Code. It will add a small section at the end of your strategy code |
||||||||||
nBTWFMgrExport Strategy input A new Strategy input parameter has been added: nBTWFMgrExport The following modes are available:
|
||||||||||
When you initially develop your strategy you usually want
to research the effect of additional context input values. With BTWFMgr you can check now if certain ranges or values will improve the overall strategy result and then filter bad entries out! We have added - as an example automatically - the TimeOfDay context value, so you can see of certain times yield better results. This function allows you to add also these context input values to the BTWFMgr data capturing:
|
Example BTWFMgr added data
collection
segment:
//====== WALK-FORMWARD-OPTIMIZATION DATA COLLECTION SECTION ======
external: "C:\BTWFMgr\PSS_BT.DLL", int, "PSS_BT", LPSTR,LPSTR,LPSTR,IEasyLanguageObject;
DefineDLLFunc: "C:\BTWFMgr\PSS_BT.DLL", int, "PSS_BTSetExit", FLOAT;
Vars: nRetWFO(0),MinDistance(15),WalkForwardVar(""),WeekDay(1),nMinMove(MinMove/pricescale);
Array: arrPSSBTInp[100](0), arrPSSBTVal[30](0);
if nBTWFMgrExport > 0 then begin
PSS_BTSetExit(Open);
if nBTWFMgrExport = 3 AND Marketposition = 0 then
Buy("L") 1818 shares next bar at market;
WeekDay = DayOfWeek(Date);
if WeekDay = 0 THEN
WeekDay = 7; //Sunday
if GetAppInfo(aiOptimizing) = 1 then begin
//------ Setup Input Name List
if WalkForwardVar = "" then begin
WalkForwardVar = "RSILength";
WalkForwardVar = WalkForwardVar + "/OverSold";
WalkForwardVar = WalkForwardVar + "/OverBought";
WalkForwardVar = WalkForwardVar + "/EMALength";
WalkForwardVar = WalkForwardVar + "/LossAmt";
WalkForwardVar = WalkForwardVar + "/GainAmt";
if nBTWFMgrExport = 1 OR nBTWFMgrExport = 3 then begin
WalkForwardVar = WalkForwardVar + "/*TimeOfDay/WeekDay";
// WalkForwardVar = WalkForwardVar + "/YourContextVariables";
end;
end;
//------ Transfer current Strategy Input Values
arrPSSBTInp[0] = RSILength; // Strategy Input#01
arrPSSBTInp[1] = OverSold; // Strategy Input#02
arrPSSBTInp[2] = OverBought; // Strategy Input#03
arrPSSBTInp[3] = EMALength; // Strategy Input#04
arrPSSBTInp[4] = LossAmt; // Strategy Input#05
arrPSSBTInp[5] = GainAmt; // Strategy Input#06
arrPSSBTInp[6] = Time; // Context Input#01
arrPSSBTInp[7] = WeekDay; // Context Input#02
//------ Transfer Position Details
arrPSSBTVal[0] = 6; // Number of tracked Strategy Inputs
if nBTWFMgrExport = 1 OR (nBTWFMgrExport = 3 AND CurrentShares = 1818) then
arrPSSBTVal[0] = 8; // add Number of Context Variables
arrPSSBTVal[1] = (MarketPosition(0)*MaxShares(0));
arrPSSBTVal[2] = (MarketPosition(1)*MaxShares(1));
arrPSSBTVal[3] = EntryPrice(0);
arrPSSBTVal[4] = EntryPrice(1);
arrPSSBTVal[5] = ExitPrice(0);
arrPSSBTVal[6] = ExitPrice(1);
arrPSSBTVal[7] = PositionProfit(1);
arrPSSBTVal[8] = Commission + Slippage;
arrPSSBTVal[9] = nMinMove;
arrPSSBTVal[10]= BigPointValue;
if LastBarOnChart then
arrPSSBTVal[11] = 1 // Last Bar reached
else
arrPSSBTVal[11] = 0;
arrPSSBTVal[12] = BarNumber;
arrPSSBTVal[13] = BarType;
arrPSSBTVal[14] = BarInterval;
arrPSSBTVal[15] = nBTWFMgrExport;
arrPSSBTVal[16] = Date;
arrPSSBTVal[17] = Time;
arrPSSBTVal[18] = Open;
arrPSSBTVal[19] = High;
arrPSSBTVal[20] = Low;
arrPSSBTVal[21] = Close;
arrPSSBTVal[22] = Volume;
arrPSSBTVal[23] = BarsSinceExit(1);
arrPSSBTVal[24] = BarsSinceEntry(1);
arrPSSBTVal[25] = MarketPosition*CurrentShares;
arrPSSBTVal[26] = ExitPrice(2);
//------ Call Diamond Backtesting Data Collection Interface
nRetWFO = PSS_BT(Symbol,"PSS_RSISample"{Strategy},WalkForwardVar{InputNames},self);
end;
//------ Close new Positions in Potential Mode after MinDistance Bars
If nBTWFMgrExport = 1 then begin
If marketposition = 1 AND BarsSinceEntry >= MinDistance then
Sell ("LPot") next bar Market;
If marketposition = -1 AND BarsSinceEntry >= MinDistance then
Buy to Cover ("Spot") next bar Market;
end;
end; // End of Data Collection Insert
MultiCharts Example BTWFMgr added data
collection segment
The MultiCharts code is identical to the TradeSTation code
- except the DLL function declaration:
//====== WALK-FORMWARD-OPTIMIZATION DATA COLLECTION SECTION ======
external: "C:\BTWFMgr\PSS_BT64.DLL", int, "PSS_BTMC", LPSTR,LPSTR,LPSTR,IEasyLanguageObject,
LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,
LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,
LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT,LPFLOAT;
DefineDLLFunc: "C:\BTWFMgr\PSS_BT64.DLL", int, "PSS_BTSetExit", FLOAT;
and the he DLL function call:
//------ Call Diamond Backtesting Data Collection Interface
nRetWFO = PSS_BTMC(Symbol,"PSS_RSISample"{Strategy},WalkForwardVar{InputNames},self,
&arrPSSBTVal[ 0],&arrPSSBTVal[ 1],&arrPSSBTVal[ 2],&arrPSSBTVal[ 3],&arrPSSBTVal[ 4],
&arrPSSBTVal[ 5],&arrPSSBTVal[ 6],&arrPSSBTVal[ 7],&arrPSSBTVal[ 8],&arrPSSBTVal[ 9],
&arrPSSBTVal[10],&arrPSSBTVal[11],&arrPSSBTVal[12],&arrPSSBTVal[13],&arrPSSBTVal[14],
&arrPSSBTVal[15],&arrPSSBTVal[16],&arrPSSBTVal[17],&arrPSSBTVal[18],&arrPSSBTVal[19],
&arrPSSBTVal[20],&arrPSSBTVal[21],&arrPSSBTVal[22],&arrPSSBTVal[23],&arrPSSBTVal[24],
&arrPSSBTVal[25],&arrPSSBTVal[26]);
© Copyright 1998-2016, Burkhard Eichberger, Professional Software Solutions
All Rights Reserved Worldwide.