How do I set backtesting for specific periods in the past e.g from 1st of August 2011 to 30th September 2011. Is it a user setting before you generate a back testing report or does it have to be written in to the EFS study itself?
Announcement
Collapse
No announcement yet.
Back testing specific periods
Collapse
X
-
Re: Back testing specific periods
EFSlearners
You would need to code the required logic in the script. If you search through this forum you should find examples of how to do it as the topic has been discussed before
Alex
Originally posted by EFSlearners
How do I set backtesting for specific periods in the past e.g from 1st of August 2011 to 30th September 2011. Is it a user setting before you generate a back testing report or does it have to be written in to the EFS study itself?
-
Re: Re: Back testing specific periods
Originally posted by Alexis C. Montenegro
EFSlearners
You would need to code the required logic in the script. If you search through this forum you should find examples of how to do it as the topic has been discussed before
Alex
I looked at some code you have posted earlier as per your suggestion. Could you help me with where I should turn the switch 'On' or 'Off' and where to enter the dates.......again, I am so new to EFS that I could be asking a very basic question. Your code below..
/************************************************** *******
Alexis C. Montenegro © May 2004
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
************************************************** ********/
function preMain(){
setStudyTitle("Trade Permissioning");
setPriceStudy(true);
setShowCursorLabel(false);
var fp1 = new FunctionParameter("Switch", FunctionParameter.STRING);
fp1.addOption("Off");
fp1.addOption("On");
fp1.setDefault("Off");
var fp2 = new FunctionParameter("Start", FunctionParameter.NUMBER);
fp2.setName("Start (yyyymmdd)");
fp2.setDefault("");
var fp3 = new FunctionParameter("End", FunctionParameter.NUMBER);
fp3.setName("End (yyyymmdd)");
fp3.setDefault("");
var fp4 = new FunctionParameter("Background", FunctionParameter.STRING);
fp4.addOption("Off");
fp4.addOption("On");
fp4.setDefault("On");
}
function main(Switch,Start,End,Background){
var vTrade = 1;
var vYear,vMonth,vDay;
vYear=getYear(0,-1)+"";
vMonth=getMonth()+"";
if(vMonth<10)
vMonth = 0+vMonth;
vDay = getDay()+"";
if(vDay<10)
vDay = 0+vDay;
if(Switch=="On"){
if(Start!=null&&End==null) End=vYear+vMonth+vDay;
if((vYear+vMonth+vDay)<Start || (vYear+vMonth+vDay)>End){
vTrade = 0;
}
}
//insert indicator logic here
//end indicator logic here
if(vTrade==1){
//insert trading logic here
//end trading logic here
}
//logic to close all trades if Switch is On
if(vTrade==0){
if(Strategy.isLong()==true){
Strategy.doSell("Closeout Long(s)",Strategy.STOP,Strategy.THISBAR,Strategy.A LL,close(-1));
}
if(Strategy.isShort()==true){
Strategy.doCover("Closeout Short(s)",Strategy.STOP,Strategy.THISBAR,Strategy. ALL,close(-1));
}
}
//logic to visually check if in trade
if(Strategy.isInTrade()==true&&Background=="On")
setBarBgColor(Color.yellow);
//replace with your return
return;
}Last edited by SNR2012; 01-31-2012, 01:29 AM.
Comment
-
Re: Re: Re: Back testing specific periods
EFSlearners
As I explain in the post where you found the script you set those parameters through Edit Studies [called Edit Chart in version 11]
Alex
Originally posted by EFSlearners
Alex
I looked at some code you have posted earlier as per your suggestion. Could you help me with where I should turn the switch 'On' or 'Off' and where to enter the dates.......again, I am so new to EFS that I could be asking a very basic question. Your code below..
/************************************************** *******
Alexis C. Montenegro © May 2004
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
************************************************** ********/
function preMain(){
setStudyTitle("Trade Permissioning");
setPriceStudy(true);
setShowCursorLabel(false);
var fp1 = new FunctionParameter("Switch", FunctionParameter.STRING);
fp1.addOption("Off");
fp1.addOption("On");
fp1.setDefault("Off");
var fp2 = new FunctionParameter("Start", FunctionParameter.NUMBER);
fp2.setName("Start (yyyymmdd)");
fp2.setDefault("");
var fp3 = new FunctionParameter("End", FunctionParameter.NUMBER);
fp3.setName("End (yyyymmdd)");
fp3.setDefault("");
var fp4 = new FunctionParameter("Background", FunctionParameter.STRING);
fp4.addOption("Off");
fp4.addOption("On");
fp4.setDefault("On");
}
function main(Switch,Start,End,Background){
var vTrade = 1;
var vYear,vMonth,vDay;
vYear=getYear(0,-1)+"";
vMonth=getMonth()+"";
if(vMonth<10)
vMonth = 0+vMonth;
vDay = getDay()+"";
if(vDay<10)
vDay = 0+vDay;
if(Switch=="On"){
if(Start!=null&&End==null) End=vYear+vMonth+vDay;
if((vYear+vMonth+vDay)<Start || (vYear+vMonth+vDay)>End){
vTrade = 0;
}
}
//insert indicator logic here
//end indicator logic here
if(vTrade==1){
//insert trading logic here
//end trading logic here
}
//logic to close all trades if Switch is On
if(vTrade==0){
if(Strategy.isLong()==true){
Strategy.doSell("Closeout Long(s)",Strategy.STOP,Strategy.THISBAR,Strategy.A LL,close(-1));
}
if(Strategy.isShort()==true){
Strategy.doCover("Closeout Short(s)",Strategy.STOP,Strategy.THISBAR,Strategy. ALL,close(-1));
}
}
//logic to visually check if in trade
if(Strategy.isInTrade()==true&&Background=="On")
setBarBgColor(Color.yellow);
//replace with your return
return;
}
Comment
Comment