PureBytes Links
Trading Reference Links
|
Herman asked me to write a script that would do what the subject
line states.Here it is for those interested:<FONT
face="Courier New" size=1>'**************************************'Purpose:
Run A Procedure in
Amibroker' that will load a
database,' load a settings
file, Load a' formula, Set
the Apply To and' Range
settings, run a backtest'
and export the tradelist to'
a csv file''Operation: Name this file whatever
you' wish but give it an
extension' of .vbs. Place it
in your' Amibroker folder
and run it' by double
clicking on the file'
name.' ' Make sure
that you change those' lines
under the !!!!!!! lines' to
match your system.''
Make sure that you have the'
correct format file in the'
format folder.''The Code: Is written in VB Script
and' runs within "Windows
Scripting' Host (WSH)". I
have included' many
commented out MsgBox lines'
that you can uncomment if
you're' having problems.
That way you' have a way to
monitor the progress' of the
script as it executes.''vbScript Help: The following links
will' provide information on
VBScript:' (Be careful of
folded lines)'' <A
href=""><FONT
face="Courier New"
size=1>http://msdn.microsoft.com/library/default.asp?url=""><FONT
face="Courier New" size=1>'' <A
href=""><FONT
face="Courier New"
size=1>http://msdn.microsoft.com/library/default.asp?url=""><FONT
face="Courier New" size=1>'' <A
href=""><FONT
face="Courier New"
size=1>http://www.microsoft.com/technet/community/scriptcenter/default.mspx<FONT
face="Courier New" size=1>'' <A
href=""><FONT
face="Courier New"
size=1>http://groups.msn.com/windowsscript/_homepage.msnw?pgmarket=en-us<FONT
face="Courier New" size=1>''Created By:
dingo'**************************************Dim oABDim
oAADim result_Ok dim Data_Base_Folderdim
BackTest_Frmla_Pathdim Xport_CSV_FlePathdim Settngs_FilePathdim
iError'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
change the following paths to suit your
configuration'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Data_Base_Folder
= "C:\Program Files\Amibroker\Your Database Dir"BackTest_Frmla_Path =
"C:\Program Files\Amibroker\Afl\Your Formula Here.Afl"Xport_CSV_FlePath =
"C:\Program Files\Amibroker\Output\TradeList.CSV"Settngs_FilePath =
"C:\Program Files\Amibroker\Settings Files\Your Settings File.ABS"'
declare object for Amibroker and the file system objectset oAB =
CreateObject("Broker.Application")Set oAA =
oAB.Analysis'------------------------------------------' Load the
Settings File, Set from and to' dates, and the
watchlist'------------------------------------------with
oAA
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' change the following settings to suit your configuration
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If Not .LoadSettings(cstr(Settngs_FilePath))
Then MsgBox "Can't Load Settings
File" iError =
true
Else .RangeMode
= 3 .RangeFromDate =
"01/01/2001" .RangeToDate =
"12/31/2002"
.ClearFilters .ApplyTo =
2 .Filter(0, "watchlist") =
29 End IfEnd WithIf Not iError
then
'------------------------------------------ ' The
following is the "main" code for the ' exporting and
importing of the data
'------------------------------------------ ' Load EOD
Data Base
'------------------------------------------ 'wscript.echo
"Loading EOD Database: " + Data_Base_Folder If
oAB.LoadDatabase(cstr(Data_Base_Folder))
Then
'------------------------------------------
' Load the AFL for Building the CSV
File
'------------------------------------------
'wscript.echo "Loading AFL: " +
BackTest_Frmla_Path If
oAA.LoadFormula(cstr(BackTest_Frmla_Path))
Then
'------------------------------------------
' Run The
Scan
'------------------------------------------
'wscript.echo "Running
Backtest"
oAA.Backtest
'------------------------------------------
' now export the
tradelist
'------------------------------------------
result_Ok =
oAA.Export(Xport_CSV_FlePath)
If Not result_Ok
Then
'wscript.echo "result_Ok: " +
cstr(result_Ok)
MsgBox "Error Exporting
Tradelist"
else
MsgBox
"Finished"
End If
Else
MsgBox "Can't Load Backtest
Formula" End
If
Else MsgBox "Cant Load
Database" End IfEnd
If'------------------------------------------' destroy all
objects'------------------------------------------Set oAA =
Nothingset oAB = Nothing
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
'**************************************
'Purpose: Run A Procedure in Amibroker
' that will load a database,
' load a settings file, Load a
' formula, Set the Apply To and
' Range settings, run a backtest
' and export the tradelist to
' a csv file
'
'Operation: Name this file whatever you
' wish but give it an extension
' of .vbs. Place it in your
' Amibroker folder and run it
' by double clicking on the file
' name.
'
' Make sure that you change those
' lines under the !!!!!!! lines
' to match your system.
'
' Make sure that you have the
' correct format file in the
' format folder.
'
'The Code: Is written in VB Script and
' runs within "Windows Scripting
' Host (WSH)". I have included
' many commented out MsgBox lines
' that you can uncomment if you're
' having problems. That way you
' have a way to monitor the progress
' of the script as it executes.
'
'vbScript Help: The following links will
' provide information on VBScript:
' (Be careful of folded lines)
'
' http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28001169
'
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbscripttoc.asp
'
' http://www.microsoft.com/technet/community/scriptcenter/default.mspx
'
' http://groups.msn.com/windowsscript/_homepage.msnw?pgmarket=en-us
'
'Created By: dingo
'**************************************
Dim oAB
Dim oAA
Dim result_Ok
dim Data_Base_Folder
dim BackTest_Frmla_Path
dim Xport_CSV_FlePath
dim Settngs_FilePath
dim iError
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' change the following paths to suit your configuration
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Data_Base_Folder = "C:\Program Files\Amibroker\Your Database Dir"
BackTest_Frmla_Path = "C:\Program Files\Amibroker\Afl\Your Formula Here.Afl"
Xport_CSV_FlePath = "C:\Program Files\Amibroker\Output\TradeList.CSV"
Settngs_FilePath = "C:\Program Files\Amibroker\Settings Files\Your Settings File.ABS"
' declare object for Amibroker and the file system object
set oAB = CreateObject("Broker.Application")
Set oAA = oAB.Analysis
'------------------------------------------
' Load the Settings File, Set from and to
' dates, and the watchlist
'------------------------------------------
with oAA
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' change the following settings to suit your configuration
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If Not .LoadSettings(cstr(Settngs_FilePath)) Then
MsgBox "Can't Load Settings File"
iError = true
Else
.RangeMode = 3
.RangeFromDate = "01/01/2001"
.RangeToDate = "12/31/2002"
.ClearFilters
.ApplyTo = 2
.Filter(0, "watchlist") = 29
End If
End With
If Not iError then
'------------------------------------------
' The following is the "main" code for the
' exporting and importing of the data
'------------------------------------------
' Load EOD Data Base
'------------------------------------------
'wscript.echo "Loading EOD Database: " + Data_Base_Folder
If oAB.LoadDatabase(cstr(Data_Base_Folder)) Then
'------------------------------------------
' Load the AFL for Building the CSV File
'------------------------------------------
'wscript.echo "Loading AFL: " + BackTest_Frmla_Path
If oAA.LoadFormula(cstr(BackTest_Frmla_Path)) Then
'------------------------------------------
' Run The Scan
'------------------------------------------
'wscript.echo "Running Backtest"
oAA.Backtest
'------------------------------------------
' now export the tradelist
'------------------------------------------
result_Ok = oAA.Export(Xport_CSV_FlePath)
If Not result_Ok Then
'wscript.echo "result_Ok: " + cstr(result_Ok)
MsgBox "Error Exporting Tradelist"
else
MsgBox "Finished"
End If
Else
MsgBox "Can't Load Backtest Formula"
End If
Else
MsgBox "Cant Load Database"
End If
End If
'------------------------------------------
' destroy all objects
'------------------------------------------
Set oAA = Nothing
set oAB = Nothing
|