Announcement

Collapse
No announcement yet.

New to Backtesting.. Need help.

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

  • New to Backtesting.. Need help.

    I am trying to do some simple backtest code using the E-Mini. What I want to do is something like this:
    if (bar(-3)=downbar & bar(-2)=upbar & bar(-1)=upbar and bar(-1).high>bar(-2).high) then go long on current bar with a stoplimit of bar(-2).high
    if ordernot filled on current bar, cancel.
    then, if order filled. Set exit limit @ enter price + 1.00 and set stop-limit at enter - 2.5..

    This is what I have done so far, but it does not record any trades in the strategy analyzer...

    if(close(-4)>close(-3) && (close(-3)<close(-2)) && close(-2)<close(-3) && Strategy.isInTrade()==false && close(-1)<close(-2)
    && high(-2)<high(-1))
    {
    var longenter = high(-1);
    Strategy.doLong("Forward Momentum",Strategy.LIMIT, Strategy.THISBAR, null, longenter);
    }
    if(Strategy.isInTrade()==true && Strategy.isLong() == true)
    {
    Strategy.setStop(longenter-2.5);
    Strategy.doSell("Getting out at profit", Strategy.LIMIT,Strategy.THISBAR, null, (longenter+1.00));
    }

    Any help would be great...
    --------------------
    http://groupshares.com

  • #2
    Some fixes made

    Didn't have lots of time to check all my solution and your logic, but you had some mutually exclusive code which would never execute:
    (close(-3)<close(-2)) && close(-2)<close(-3)

    I think I dropped the close( 1 vs 2)
    check the null in doSell line

    This will at least get you going, 2 links for coding samples





    Believe me, code structure is important as logic can get contorted quickly as more ideas are added. Adding a varying trailing stop is something to look into.
    Attached Files

    Comment

    Working...
    X