Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest Problems

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

    Backtest Problems

    Hello Ninja Trader Support Team,

    I have a very big problem with the backtesting tool.
    I have developed a strategy which is basically doing this:

    only buy long if sma1 > sma2
    only buy short if sma1 < sma2

    Code:
    if (SMA(25)[0] > SMA(50)[0]
         && Stochastics(3, 5, 2).D[0] < 55
         && Stochastics(3, 5, 2).K[1] < 30 || Stochastics(3, 5, 2).K[2] < 30)
                {
                    EnterLong; 
                }

    but the strategy is still doing short orders when the short sma (turquoise) is on top of the longer sma (orange).

    please see attached screenshot.

    on this screenshot you will notice the second problem I have - see that long entry at 9550 at 19:39 in the middle of the screen? price has not touched this entry but the entry marker is there. Include commission is set to false.

    I am using latest ninja trader Version (6.5.1000.12)
    Attached Files

    #2
    Hi Phaseshifter, the code you posted only deals with the long entries. What are you using for short entries?

    Regarding your second problem, have you read the page describing the differences of backtesting?
    AustinNinjaTrader Customer Service

    Comment


      #3
      hi austin!
      thanks for your fast response.

      here ist the short entry:

      Code:
                  // Condition set 2
                  if (SMA(25)[0] < SMA(50)[0]
                      && Stochastics(3, 5, 2).D[0] > 45
                      && Stochastics(3, 5, 2).K[1] > 70  || Stochastics(3, 5, 2).K[2] > 70
      )
                  {
                      EnterShort; 
                  }
      for me it looks like that if there are more condition sets NT sometimes "forgets" about one or more conditions. is this somehow possible??

      how can I avoid this behaviour and make sure only short trades are entered during a downtrend defined by the moving averages?


      Concerning the second question I still can't answer why the order gets filled outside the bar's (high or low). For my understanding the bar should always reach the trade's price, or am I wrong here??

      Taken from your link - "During a backtest assumptions are made on the fill price of an order is based on the OHLC of a bar and the price of the order itself."

      Comment


        #4
        Originally posted by Phaseshifter View Post
        Code:
                    // Condition set 2
                    if (SMA(25)[0] < SMA(50)[0]
                        && Stochastics(3, 5, 2).D[0] > 45
                        && Stochastics(3, 5, 2).K[1] > 70  || Stochastics(3, 5, 2).K[2] > 70
        )
                    {
                        EnterShort; 
                    }
        for me it looks like that if there are more condition sets NT sometimes "forgets" about one or more conditions. is this somehow possible??
        NT doesn't forget about conditions. It is possible for the conditions to not be nested right, so it appears NT forgets. Please try the following code for a method to work out when code triggers:
        Code:
        // first check SMA stuff
        if (SMA(25)[0] < SMA(50)[0])
        {
            Print("SMA 25 < SMA 50");
            
            // then check current Stoch stuff
            if (Stochastics(3, 5, 2).D[0] > 45)
            {
                Print("Stoch.D[0] > 45");
        
                // lastly, check past stoch stuff
                if (Stochastics(3, 5, 2).K[1] > 70  || Stochastics(3, 5, 2).K[2] > 70)
                {
                    Print("past stoch stuff checks out, enter short");
                    EnterShort();
                }
            }
        }
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X