Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using tick resolution in backtesting 3350 Volume chart

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

    Using tick resolution in backtesting 3350 Volume chart

    Hi, I have a simple strategy that I have programmed to enter simply on a specific date/time on a SP emini 3350 volume chart. Basically,when I arrive at my specific bar on the 3350, I then want to enter a long limit order on a 1-tick resolution timeframe (I have this already set up in my strategy), one tick less than the close of the 3350 volume "5/27/2009 1:01:54 PM" bar.

    For example:

    datetimeinfo = Time[0].ToString();
    if datetimeinfo == "5/27/2009 1:01:54PM"
    {
    if (myEntryOrder == null)
    {
    myEntryOrder = EnterLongLimit(1, true,1, Close[0] - (1 * Ticksize), "Long Entry");
    barNumberofOrder = CurrentBar;
    }
    }


    The problem is (looking at the completed trades of the backtest), it is entering my long trade DURING the ""5/27/2009 1:01:54PM" bar on the 3350. This is not what I want - I need to obtain the close value of the "5/27/2009 1:01:54PM" 3350 bar, and *then* enter my long limit order based on that, on the next 3350 bar. I assumed that it would first wait until the "5/27/2009 1:01:54PM" bar on the 3350 was closed, and then issue the long limit order at the beginning of the very next bar.

    Any thoughts?

    Thanks
    Shawn

    #2
    Shawn, I'm not sure how you determine that this specific 3350 volume bar is the bar for your entry trigger, but you have to consider NinjaTrader uses the end of bar time to stamp it, so this could be the reason you identify the incorrect bar for your trade to be placed.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Well, I just specify "ES 06-09" Volume 3350 under "Data Series"in the "BackTest" settings screen within the Strategy
      Analyzer. isn't that all I need to do? Is there something else I need to specifically set within my strategy.

      Also, aside from my first query, there is one other thing that's not working correctly within my strategy: When I
      issue a EnterLongLimit or EnterShortLimit order, I wish to have the order remain in force for a specified number
      of bars which the user inputs as a parameter ("Numwaitbars"). Then after that number of bars is reached, the order is cancelled
      if not yet filled. My logic doesn't seem to work .. it seems like it completely ignores my bar limit specified. I've
      included my complete strategy below.. could you have a look at it please? Thanks.




      #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 TWOUP trades in direction of trend. Q bar must engulf prior 3 bars. Trade on 3350 chart.
      /// </summary>
      [Description("Enter the description of your strategy here")]
      public class MyTest : Strategy
      {
      #region Variables
      // Wizard generated variables
      // User defined variables (add any user defined variables below)
      private IOrder myEntryOrder = null;
      private int barNumberOfOrder = 0;
      private int myStop = 4;
      private int myTgt = 4;
      private int numofticks = 0;
      private int numwaitbars = 0;
      private string datetimeinfo = string.Empty;
      #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()
      {
      /* Add a secondary bar series */
      Add(PeriodType.Tick, 1);
      SetProfitTarget("Long Entry", CalculationMode.Ticks, MyTgt);
      SetStopLoss("Long Entry", CalculationMode.Ticks, MyStop, false);
      SetProfitTarget("Short Entry", CalculationMode.Ticks, MyTgt);
      SetStopLoss("Short Entry", CalculationMode.Ticks, MyStop, false);
      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {

      /* When the OnBarUpdate() is called from the primary bar series (5min series in this example), do the following */

      if (BarsInProgress == 0)
      {


      if (Position.MarketPosition == MarketPosition.Flat)
      {
      myEntryOrder = null;
      barNumberOfOrder = 0;
      }


      datetimeinfo = Time[0].ToString();

      if (datetimeinfo == "4/9/2009 11:46:41 AM" || datetimeinfo == "4/9/2009 12:29:56 PM"
      || datetimeinfo == "4/9/2009 1:19:48 PM" || datetimeinfo == "4/13/2009 11:29:56 AM"
      || datetimeinfo == "4/14/2009 11:06:53 AM" || datetimeinfo == "4/14/2009 1:42:40 PM"
      || datetimeinfo == "4/14/2009 2:38:45 PM" || datetimeinfo == "4/14/2009 3:08:48 PM"
      || datetimeinfo == "4/14/2009 4:52:59 PM" || datetimeinfo == "4/15/2009 3:14:22 PM"
      || datetimeinfo == "4/15/2009 3:41:18 PM" || datetimeinfo == "4/15/2009 3:57:23 PM"
      || datetimeinfo == "5/29/2009 12:29:59 AM" || datetimeinfo == "5/29/2009 12:57:29 PM")
      {
      if (myEntryOrder == null)
      {
      myEntryOrder = EnterShortLimit(1, true, 1, Close[0] + (Numofticks * TickSize), "Short Entry");
      barNumberOfOrder = CurrentBar;
      }
      }

      if (datetimeinfo == "4/9/2009 10:47:05 AM" || datetimeinfo == "4/9/2009 11:30:24 AM"
      || datetimeinfo == "4/9/2009 2:49:09 PM" || datetimeinfo == "4/9/2009 3:28:04 PM"
      || datetimeinfo == "4/9/2009 4:37:59 PM" || datetimeinfo == "4/9/2009 4:50:34 PM"
      || datetimeinfo == "4/13/2009 3:25:34 PM" || datetimeinfo == "4/13/2009 3:55:33 PM"
      || datetimeinfo == "5/28/2009 2:37:17 PM" || datetimeinfo == "5/29/2009 10:38:02 AM"
      || datetimeinfo == "5/29/2009 2:05:02 PM" || datetimeinfo == "5/29/2009 5:04:37 PM")
      {
      if (myEntryOrder == null)
      {
      myEntryOrder = EnterLongLimit(1, true, 1, Close[0] - (Numofticks * TickSize), "Long Entry");
      barNumberOfOrder = CurrentBar;
      }
      }

      if (Position.MarketPosition == MarketPosition.Flat && CurrentBar > barNumberOfOrder + NumWaitbars && myEntryOrder != null)
      CancelOrder(myEntryOrder);

      }
      // When the OnBarUpdate() is called from the secondary bar series, do nothing.
      else
      {
      return;
      }

      } /* END OnBarUpdate */


      #region Properties
      [Description("Stop Loss Amount")]
      [Category("Parameters")]
      public int MyStop
      {
      get { return myStop; }
      set { myStop = Math.Max(1, value); }
      }
      [Description("Profit Target Amount")]
      [Category("Parameters")]
      public int MyTgt
      {
      get { return myTgt; }
      set { myTgt = Math.Max(1, value); }
      }
      [Description("Number of ticks for limit order")]
      [Category("Parameters")]
      public int Numofticks
      {
      get { return numofticks; }
      set { numofticks = Math.Max(0, value); }
      }
      [Description("Number of bars to wait to get filled before cancelling")]
      [Category("Parameters")]
      public int NumWaitbars
      {
      get { return numwaitbars; }
      set { numwaitbars = Math.Max(0, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        shawn, for backtesting it's unlikely the timestamp exactly matches the times you have specified, as you check those on the 3350 volume chart.

        For the order submission issues, I would suggest working with TraceOrders to check - http://www.ninjatrader-support.com/H...aceOrders.html

        Should your 'number of bars to keep the order alive' be counting for the 3350 or the finer tick chart you have added?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          > shawn, for backtesting it's unlikely the timestamp exactly matches the times > you have specified, as you check those on the 3350 volume chart.


          The timestamp matches *exactly* - I have made very sure of this. This is not the problem.


          > For the order submission issues, I would suggest working with TraceOrders >to check - http://www.ninjatrader-support.com/H...aceOrders.html


          OK, I will have a look at this... I have never used that before. So you don't see anything wrong logically with my code?


          > Should your 'number of bars to keep the order alive' be counting for the >3350 or the finer tick chart you have added?


          It should be counting for the 3350 chart. All analysis and decision-making is done on the 3350 chart. I only want the tick chart for entries and exits.

          Thanks
          Shawn

          Comment


            #6
            Shawn, the best would be you work with Print statements at critical code sections to check you get the values you expect to work with (such as your barcount or the close price as reference for order placing) - http://www.ninjatrader-support2.com/...ead.php?t=3418
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Well, I don't mean to be unappreciative of your assistance - but you are really not giving me much help here. I'm a newbie at NinjaScript programming and I would really like a bit of advice as to whether the code of my script will do what I want it to do, or whether there are glaring errors. It's not a very long strategy - I figured you could just take a quick look at it and discern what my mistakes were.

              :-(

              Comment


                #8
                shawn, unfortunately we don't offer strategy coding or debugging services. Your strategy has no 'glaring' coding errors standing out since you do not get an exception thrown in the log tab of the Control Center as you run it.

                But to make sure it's getting your ideas across exactly as you had them in mind can sometimes be tougher than you initially think, so without making any assumptions, it would be best to proceed with Print statements and trace orders in realtime to check where it needs to be improved to match your original ideas.

                If you need professional custom programming, I can suggest to check those NinjaScript consultants out - http://www.ninjatrader.com/webnew/pa...injaScript.htm
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,610 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                9 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                19 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                6 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                16 views
                0 likes
                Last Post Javierw.ok  
                Working...
                X