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
A. Open TradeStation
Start/Programs/TradeStation 9.X
B. Open the strategy EasyLanguage Editor:
Click on the EasyLanguage Button - or File/Editor
C. Select "Strategy" in the Select Analysis type pull down list (at the top)
then click on your Strategy and click on the Open button (you might need to enter a password)
D. When the Strategy EasyLanguage window has opened continue to Step2 below

 

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:
0 Disable BTWFMgr data capture
1 Enable BTWFMgr data capture - in initial strategy potential research mode
When you are researching the basic strategy potential and the effect of additional context input values
2 (Default) Enable BTWFMgr data capture - in regular backtesting mode
When you are finalizing strategy development and want to collect data for the Walk Forward backtesting
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:
A. Add one line for each context variable before the line:
// WalkForwardVar = WalkForwardVar + "/YourContextVariables";
Here is one example - adding two angles:
   WalkForwardVar = WalkForwardVar + "/Angle1";
   WalkForwardVar = WalkForwardVar + "/Angle2";
B. Increment the specified input counter (X) by the number of added context values (X+added)::
     arrPSSBTVal[0] = 7; // add Number of Context Variables
Here is one example - if you had an input counter of 7 - adding two variables - will change it to -9:
     arrPSSBTVal[0] = 9; // add Number of Context Variables
C. Add the actual values to the BTWFMgr data capture function argument list, after the line:
     arrPSSBTInp[6] = Time; // Context Input#01
Here is one example - adding two angles (array is zero based):
       arrPSSBTInp[7] = Angle1; // Context Input#02
       arrPSSBTInp[8] = Angle2; // Context Input#03
D. Verify the EasyLanguage code and run your optimizations
E. When the BTWFMgr is showing the result - you will see your context variables in the "Context Variables" section
(red squares) in the BTWFMgr treeview on the left 

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.

 

DbTkXml,DbXml,Database,DBF,XML,Export,Import,SQL,MDB,XML,DTD,HTML,CSV,Access,Toolkit,
Table,Column,Field,Record,Index,Query,External Data,Save As,merge,synchronize,explorer,
Db2XML,Db2CSV,Db2Txt,Db2Html,DbLoad,DbExplorer,DbSql,DbQuery,DbScript,
Conversion,Automate,API,Windows,Microsoft,utilities,file,management,administration,
command,line,batch scipts, shareware