Announcement

Collapse
No announcement yet.

backtesting day trading only

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • backtesting day trading only

    I would like to set up backtesting to only evaluate studies for pure intra-daytrading. By this I mean that all positions are closed at the end of the day, no positions are carried over night, and new positions (if any) are established beginning from zero open interest each day, added to, subtracted from, etc., but all closed out to zero at the end of ech day. I would still like to be able to vary time intervals, such as minutes and hours, or to vary time templates, as to the days back for which data is retrieved. But, here's the problem: If I have a 5 minute chart with a 10 period moving average, it takes 10 periods from the beginning of the day to get that moving average fully initialized. So, from the Open, my MA is not at true value for 50 minutes, that is if I set time template to 1 day. I only know how to solve this by setting time template to go back 2 days, in order to get my MA up and running at full 10 period value in Day One in time for the opening of Day Two, of a 2 Day time template. But, my problem is that now when I try that my backtesting also goes back and starts in the second previous day. I need the be able to limit somehow the day that backtesting starts to the Open of the Second Day or the day following the one in which the studies initialize, and thereafter close all positions every day, re-open new positions the every day, and close all the final day of the time template period. A pure intra-daytrading, time template for backtesting, which gives me some control over the starting date for the studies, separated from the starting date for the backtesting, for the date range I select with Time Template. Can you help me with some pre-main settings or other time de-limiters, in EFS.
    thanks,
    tilmon

  • #2
    tilmon
    To close all trades at the end of the day all you need to do is add the following to your strategy.
    PHP Code:
    if(getDay(0) != getDay(1)){
        if(
    Strategy.isLong()){
            
    Strategy.doSell("EOD close Long",Strategy.CLOSE,Strategy.THISBAR,Strategy.ALL);
        }
        if(
    Strategy.isShort()){
            
    Strategy.doCover("EOD close Short",Strategy.CLOSE,Strategy.THISBAR,Strategy.ALL);
        }

    Note that this portion of code can be used only in back testing because the back tester can verify "tomorrow's date" [ie getDay(1)] which cannot happen instead in real time.

    As to permitting trades to occurr only from the second day - thereby allowing the studies time to prime themselves - that can be done with a simple counter that starts at 1 and increases its value once a day. Then all you need to do is verify that the counter is at least equal to 2 for any trading strategy to be evaluated and/or executed.
    The enclosed sample of the required logic will allow tradng only from the second day onwards and it will color the background of the first bar of that day in yellow. If you want to start from the third day replace 2 in if(Counter >= 2) with 3, etc. You can also make that a user defined variable if you wish (but that is beyond the scope of this example)
    Alex


    PHP Code:
    var Counter 1;

    function 
    main(){

    if(
    getDay(0) != getDay(-1) && getBarState() == BARSTATE_NEWBAR){
        
    Counter++;
    }

    if(
    Counter>=2){//begin condition that allows trading
        
    if(Counter == && getDay(0) != getDay(-1)) setBarBgColor(Color.yellow);
        
        
    //insert all your trading strategy code here    
        
    }//end of condition that allows trading
        
    return;


    Originally posted by tilmon
    I would like to set up backtesting to only evaluate studies for pure intra-daytrading. By this I mean that all positions are closed at the end of the day, no positions are carried over night, and new positions (if any) are established beginning from zero open interest each day, added to, subtracted from, etc., but all closed out to zero at the end of ech day. I would still like to be able to vary time intervals, such as minutes and hours, or to vary time templates, as to the days back for which data is retrieved. But, here's the problem: If I have a 5 minute chart with a 10 period moving average, it takes 10 periods from the beginning of the day to get that moving average fully initialized. So, from the Open, my MA is not at true value for 50 minutes, that is if I set time template to 1 day. I only know how to solve this by setting time template to go back 2 days, in order to get my MA up and running at full 10 period value in Day One in time for the opening of Day Two, of a 2 Day time template. But, my problem is that now when I try that my backtesting also goes back and starts in the second previous day. I need the be able to limit somehow the day that backtesting starts to the Open of the Second Day or the day following the one in which the studies initialize, and thereafter close all positions every day, re-open new positions the every day, and close all the final day of the time template period. A pure intra-daytrading, time template for backtesting, which gives me some control over the starting date for the studies, separated from the starting date for the backtesting, for the date range I select with Time Template. Can you help me with some pre-main settings or other time de-limiters, in EFS.
    thanks,
    tilmon

    Comment

    Working...
    X