Announcement

Collapse
No announcement yet.

Backtesting Formulas

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Backtesting Formulas

    Can someone tell me how I set the backtesting tool to place the trade at the closing price of the period instead of the opening price.

  • #2
    Re: Reply to post 'Backtesting Formulas'

    czumwalt
    Use Strategy.CLOSE and Strategy.THISBAR
    Alex
    Last edited by ACM; 03-19-2003, 02:31 PM.

    Comment


    • #3
      Is it possible to tell the formula to not enter the trade until market opens and to exit trade at market close. The problem I am having is when backtesting MA crossovers the formula is in a trade at market close however afterhours trading really scews the results because the formula doesn't exit until the next bar in my time template which is at market open. By that time the price may be well past the MA crossover causing huge losses.

      Comment


      • #4
        here is what I do

        var StartTradingTime = 83000; //i.e. 09:00:00 A.M.
        var NoNewTradeTime = 155900; //i.e. 15:30:00 P.M.
        var EndTradingTime = 155900; //i.e. 15:45:00 P.M.

        BarHr = getHour();
        BarMin = getMinute();
        BarSec = getSecond();

        cBarTimeInt =BarHr*10000+BarMin*100+BarSec*1;

        if(cBarTimeInt >= StartTradingTime
        && cBarTimeInt<NoNewTradeTime){
        vTIMEofDAY = "ok2trade";
        }

        if(cBarTimeInt >= NoNewTradeTime
        && cBarTimeInt <= EndTradingTime){
        vTIMEofDAY = "NoNewTrades"
        }

        if(cBarTimeInt < StartTradingTime
        || cBarTimeInt >= EndTradingTime){
        vTIMEofDAY = "closed"
        dots5.call("CancelAllFor",sym, fut, exp, ri, 0, xchg, cur);
        dots5.call("ClosePositionFor", sym, fut, exp, ri, 0, xchg, cur);
        }

        then I use the value of vTIMEofDAY to test and see what to do next.

        Comment


        • #5
          can you elaborate a little on where I should insert each of these lines in my formula. ie. above function premain below function main etc...

          Comment


          • #6
            Here's a snippet that is sensitive to the time template you are using.

            var vThisDay = getDay();
            var vNextDay = getDay(1);
            var vNextNextDay = getDay(2);
            var bCanTrade = true;


            if(vThisDay != null && vNextDay != null && vNextNextDay != null) {
            if(vNextDay != vNextNextDay) {
            bCanTrade = false;
            }

            if(vThisDay != vNextDay) {
            bCanTrade = false;
            }

            if(!bCanTrade) {
            bNewDay = true;

            ************************
            *** If in a position, Close your Trade
            ************************
            return;
            }
            }
            Matt Gundersen

            Comment

            Working...
            X