Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What are the problems with backtesting?

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

    #31
    How many days were you testing? Did you perhaps run again into the 'out of memory' situation you experienced in former tests?

    If not, please post more complete code so we can check into.

    Thanks

    Comment


      #32
      I am running it on 1 day. I do not see that exception being thrown

      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Strategy;
      #endregion
      
      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
          /// <summary>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class ScalperTakeTwo : Strategy
          {
              #region Variables
              // Wizard generated variables
             
              
              // User defined variables (add any user defined variables below)
              #endregion
      
              /// <summary>
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              /// </summary>
              protected override void Initialize()
              {
                  SetStopLoss("", CalculationMode.Ticks, 11, false);
                  
                  Add(PeriodType.Tick,3500);
                  CalculateOnBarClose = true;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  if(BarsInProgress == 1)
                  {
                      Print("3500 bar");
                      // Condition set 1
                      if (Slope(Median, 7, 0) > 0
                          && Position.MarketPosition == MarketPosition.Flat)
                      {
                          SetProfitTarget("", CalculationMode.Ticks, 2);
                          EnterLongLimit(DefaultQuantity, Close[0], "");
                      }
          
                      // Condition set 2
                      if (Slope(Median, 7, 0) < 0
                          && Position.MarketPosition == MarketPosition.Flat)
                      {
                          SetProfitTarget("", CalculationMode.Ticks, 2);
                          EnterShortLimit(DefaultQuantity, Close[0], "");
                      }
                  }
              }
      
              #region Properties
              
      
            
              #endregion
          }
      }

      Comment


        #33
        Ok, which min bars required setting and which market? It could be you not get enough bar with the 3500 tick chart to trigger it's OnBarUpdate using the default min bars of 20 setting.

        Comment


          #34
          ES, and I am doing 28000 min bars. I am assuming this refers to the data series, which means I don't want to start running until 2800 ticks pass. Does that min bars setting refer to the 3500 tick bar or the 1 tick bar?

          Comment


            #35
            So when I run it with 2 min bars it seems to see the other bar. I guess min bars refers to the 3500 tick not the data series.

            But now it is impossible to see the trades in the chart.

            Is it possible to use a profit target and stop loss and tell it to not exit the trade until the next bar? Thus I won't run into the same bar issue?

            Thanks
            -Jeff

            Comment


              #36
              There is actually still the same problem.....It enters and exits on the same tick....

              Check this out:

              Comment


                #37
                You would need to use for example a BarsSinceEntry() qualifier for it to submit the Stops and Target for example on bar 1 after entry...

                Comment


                  #38
                  So in backtesting I cannot use SetProfitTarget and SetStopLoss because there is no way to delay their exits to the next bar?

                  And that still doesnt explain why it is getting impossible prices?

                  Comment


                    #39
                    Jeff, sure please add for example the check I mentioned to submit those one bar after try...those are attached to the entry fill executions as real orders thus they can trigger intrabar. Please clarify which 'impossible fills' are you referring to?

                    Per default there are 2 fill algorithms used in backtesting, 'liberal' and 'default', you could code your own if you like to -

                    Comment


                      #40
                      In this image: http://www.postimage.org/image.php?v=gxmOqWA

                      There is never a tick at my cover price, but it says my profit target was hit.

                      I am using default fill so it is worst case scenario. I want to use this filling type.

                      How can I submit a setProfitTarget or setStopLoss using those barsAfterEntry conditions since those are global settings that I could set in initialize? How do I turn them off and turn them back on?

                      Comment


                        #41
                        Jeff, it might hard to judge to see one tick on this chart, I would suggest use the databox on a regular chart to confirm this.

                        The BarsSinceEntry would be a hard coded in solution, there's unfortunately no GUI setting for this behaviour.

                        Comment


                          #42
                          Think about this though.....The chart clearly shows that it is exiting without a tick at the exit price. There is no way in ES that the price would get penetrated and fill me on a default fill. Let alone get through another price in 1 tick.

                          For example, say I buy 1000 with a profit target of 1000.50. I would need to have 1000.25 and 1000.50 be penetrated to get filled. We would clearly see this on a 1 tick chart.

                          I understand it is a hard coded solution. But if I set SetProfitTarget and SetStopLoss in initialize, then how do I shut them off when I enter a trade and turn them back on for the next bar. They are not exit orders but exit conditions.....

                          Comment


                            #43
                            You cannot turn off Set() methods. They are always used. If you want control you should be using ExitLongLimit() and ExitLongStop()s instead.

                            When using default fill type you will be filled at your limit prices. This is the most conservative approach possible and it will be taken. If you want different fill types you can try the liberal which will fill it on the bar at the high/low if the price was outside of the limit price. Otherwise, you will need to custom program your own fill type.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #44
                              Check out this pic: http://www.postimage.org/image.php?v=Pq7I6aA

                              Both of the prices obtained were impossible prices. This has to be some sort of bug?

                              This is using Zen data

                              Also, is there a way that I can send a limit order and it will give me the best price possible even if I am asking for a lower one? For instance, I want to send a limit order for 2 ticks, but if the price is already in my favor 5 ticks, I want to get more than 2 ticks. However if the prices is less than 2 ticks in my favor, I want to just have a limit order sitting at 2 ticks profit.
                              Last edited by jeffbg123; 03-04-2010, 01:53 PM.

                              Comment


                                #45
                                This is expected. As mentioned earlier, when you use limit orders with the Default fill type you will get filled at the limit price, never better. This is the most conservative approach to never overstate account performance. If you want different behavior you need to use the Liberal fill type or custom program your own.
                                Josh P.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by CarlTrading, Yesterday, 09:41 PM
                                1 response
                                19 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by CarlTrading, Today, 02:41 AM
                                0 responses
                                6 views
                                0 likes
                                Last Post CarlTrading  
                                Started by CaptainJack, Yesterday, 11:44 PM
                                0 responses
                                17 views
                                0 likes
                                Last Post CaptainJack  
                                Started by CarlTrading, 03-30-2026, 11:51 AM
                                0 responses
                                33 views
                                0 likes
                                Last Post CarlTrading  
                                Started by CarlTrading, 03-30-2026, 11:48 AM
                                0 responses
                                32 views
                                0 likes
                                Last Post CarlTrading  
                                Working...
                                X