Hi,
I am trying to add the ability to automatically Backtest a Strategy with one or more variable parameters. I have been able to do this in realtime by using reloadEFS(). (See the attached code sample). Unfortunately this approach requires 1 or more new bars to test each new parameter setting. While this is usable on a short interval (e.g. 1 minute), it is impractical on a 15 minute or longer chart. Does anyone have any ideas on how to achieve the same thing without waiting for one or more new bars to form.
I also find it curious that the two debugPrintln() statements after reloadEFS() are executing. Not really important as the code works, but not what I expected based on what I have read in other posts on reloadEFS().
Thanks,
Greg Schroeder
I am trying to add the ability to automatically Backtest a Strategy with one or more variable parameters. I have been able to do this in realtime by using reloadEFS(). (See the attached code sample). Unfortunately this approach requires 1 or more new bars to test each new parameter setting. While this is usable on a short interval (e.g. 1 minute), it is impractical on a 15 minute or longer chart. Does anyone have any ideas on how to achieve the same thing without waiting for one or more new bars to form.
I also find it curious that the two debugPrintln() statements after reloadEFS() are executing. Not really important as the code works, but not what I expected based on what I have read in other posts on reloadEFS().
Thanks,
Greg Schroeder
PHP Code:
debugClear();
// Global Vars
var gbInit = 0;
var giBacktestParam = 1;
var giBarCounter = 0;
//**************************
// preMain Function Executes Once When Study is Loaded
//**************************
function preMain()
{
setPriceStudy(true);
setShowCursorLabel(false);
setShowTitleParameters(false);
setComputeOnClose();//Delete to have study execute on every tick
}
//***************************
// main Function Executes on Each New Tick (or New Bar if setComputeOnClose() is in preMain)
//***************************
function main()
{
// One Time Initialization
if (!gbInit)
{
// Code to be run once per reload
debugPrintln("In Initialization..... giBacktestParam="+giBacktestParam);
gbInit = true;
} // end Initialization
if (isLastBarOnChart())
{
debugPrintln("Entered if ..... giBacktestParam="+giBacktestParam+", giBarCounter="+giBarCounter);
if (getBarState() == BARSTATE_NEWBAR)
{
if (giBacktestParam >= 10)
{
debugPrintln("Backtest run finished. giBacktestParam="+giBacktestParam+", giBarCounter="+giBarCounter);
return;
}
else if (giBarCounter == 2)
{
// Increment Backtest Parameter
giBacktestParam = giBacktestParam + 2;
//Restart Study with new Parameter
debugPrintln("In reloadEFS ..... giBacktestParam="+giBacktestParam+", giBarCounter="+giBarCounter);
debugPrintln();
debugPrintln("Backtest Parameter="+giBacktestParam);
debugPrintln();
giBarCounter = 0;
gbInit = 0;
reloadEFS();
debugPrintln("After reloadEFS()");
debugPrintln();
}
giBarCounter++;
debugPrintln("Leaving if ..... giBacktestParam="+giBacktestParam+", giBarCounter="+giBarCounter);
}
}
//-----------------------------------
// Strategy code for Backtesting here
//-----------------------------------
// Write trade results to file
return;
}
Comment