Autohotkey script for backtesting

 

This is a first pass at a script to run an optimization for every week between two dates. This particular script has the window name for IBFX - change to use it for other banks. Of course, I'm giving no claims, warranties, promises, or debugging help, but this seems to be working - it's run thousands of tests since last night; an optimization of 450 runs for every week from January - May, and it's still running. AutoHotKey is a scripting language with what seems to be a pretty broad user base, and the price is right: free. Just download it from the web. So if you want to play with it, this will giive you a starting off point...

For those who get into it: I couldn't get the ControlClick command to work reliably with the Start/Stop button (Button10), so I used ControlGetPos and a calculation, but if anybody does, let me know the syntax - it would make it a little cleaner.

#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Recommended for catching common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2

;-------------------------------------------------------------------------------------------------
; IBFX script
;-------------------------------------------------------------------------------------------------
^!i:: ; Open IBFX
IfWinExist Interbank FX Trader 4
{
WinActivate
}
else
{
MsgBox, Please Open IBFX
return
}

;-------------------------------------------------------------------------------------------------
; Get start date from user
;-------------------------------------------------------------------------------------------------
InputBox, RunDate, Start Date, Enter Start Date as YYYYMMDD (blank to cancel)
if StrLen(RunDate) = 0
{
Winclose, A
return
}
FormatTime, DateString, %RunDate%, dddd
while ( DateString "Sunday" )
{
RunDate += 1, Days
FormatTime, DateString, %RunDate%, dddd
}

;-------------------------------------------------------------------------------------------------
; Get end date from user
;-------------------------------------------------------------------------------------------------
InputBox, EndDate, End Date, Enter End Date as YYYYMMDD (blank to cancel)
EndDate = %EndDate%000000

;-------------------------------------------------------------------------------------------------
; Write to log file
;-------------------------------------------------------------------------------------------------
FormatTime DateString, A_Now, yyyyMMdd
FormatTime TimeString, A_Now, hhmmss
StartTime := A_TickCount

while RunDate < EndDate
{
; get location of dates control
ControlGetPos, StartX, StartY, StartW, StartH, SysDateTimePick321, Interbank FX Trader 4
Dates := StartY + ( StartH / 2 )

; send start year
FormatTime, DateString, %RunDate%, yyyy
Click, 265,%Dates%
Sleep, 100
Send, %DateString%

; send start month
FormatTime, DateString, %RunDate%, MM
Click, 290,%Dates%
Sleep, 100
Send, %DateString%

; send start day
FormatTime, DateString, %RunDate%, dd
Click, 305,%Dates%
Sleep, 100
Send, %DateString%

RunDate += 6, Days

; send end year
FormatTime, DateString, %RunDate%, yyyy
Click, 450,%Dates%
Sleep, 100
Send %DateString%

; send end month
FormatTime, DateString, %RunDate%, MM
Click, 475,%Dates%
Sleep, 100
Send %DateString%

; send end Day
FormatTime, DateString, %RunDate%, dd
Click, 490,%Dates%
Sleep, 100
Send %DateString%

ControlGetPos, StartX, StartY, StartW, StartH, Button10, Interbank FX Trader 4
StartX := StartX + ( StartW / 2 )
StartY := StartY + ( StartH / 2 )
Click, %StartX%, %StartY%
Sleep 1000
ControlGetText, ButtonText, Button10, Interbank FX Trader 4
While ButtonText "Start"
{
Sleep 1000
ControlGetText, ButtonText, Button10, Interbank FX Trader 4
}

; advance run date to the next week
RunDate += 1, Days

}

FormatTime, TimeString, A_Now, dddd MMMM d, yyyy hh:mm:ss tt
Elapsed := round((A_TickCount - StartTime)/1000,0)
MsgBox, 4096, , Reports finished`nTime: %elapsed% seconds
return

 

Thanks Bill to share this "Autohotkey script for backtesting". I will use it.

Reason: