Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

now NT runs a WRONG strategy

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

    now NT runs a WRONG strategy

    I try to backtest my strategy: I compiled it, selected an instrument, right-click ->"backtest", selected my strategy from the list - it executes backtest of a different strategy! (one of the sample strategies). What's going on with NT??

    #2
    I restarted NT, now it runs my strategy (when I select it). However, when in strategy analyzer, I select another strategy and backtest it and then select my strategy - it backtests the PREVIOUS strategy and I can't get it to run my strategy!

    Comment


      #3
      Mark, when you check the Control Center > Log tab, any errors noted there then as you attempt to run your custom script?

      Thanks,
      BertrandNinjaTrader Customer Service

      Comment


        #4
        when I select strategies to run, in log "1/22/2013 12:20:07 PM,Strategy,Failed to call method 'Initialize' for strategy 'Strategy001/0b831389c6174f01aa8e73130ff14b4f': Object reference not set to an instance of an object.,
        1/22/2013 12:16:44 PM,Strategy,Failed to call method 'Initialize' for strategy 'Strategy001/20b31bc63ee74e7c89deb707af190e79': Object reference not set to an instance of an object.,
        "
        Other then this there are no log messages during compile or run of strategy. Also, I notice that when I select my test strategy, "label" below and "parameters" above do not change from the previously selected strategy...i.e. it does not really "select it". then it runs NOT my strategy, but previously selected

        Comment


          #5
          Mark, if you don't mind please post your Initialize() so we could work removing that error message with you.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Here is the whole strategy:

            #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>
            /// simple gap
            /// </summary>
            [Description("simple gap")]
            public class Strategy001 : Strategy
            {
            #region Variables
            // Wizard generated variables
            private int profit = 20; // Default setting for Profit
            private int loss = 8; // Default setting for Loss
            // User defined variables (add any user defined variables below)
            private bool isLowerOpen = false;
            private bool isHigherOpen = false;
            private double refPrice = 0.0;
            private bool tradedToday = false;
            #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()
            {
            SetProfitTarget("Stg001", CalculationMode.Ticks, Profit);
            SetTrailStop("Stg001", CalculationMode.Ticks, Loss, false);
            CalculateOnBarClose = true;

            tradedToday = false;
            isLowerOpen = CurrentDayOHL().CurrentOpen[0] < Bars.GetDayBar(1).Low;
            isHigherOpen = CurrentDayOHL().CurrentOpen[0] > Bars.GetDayBar(1).High;
            if (isLowerOpen)
            refPrice = Bars.GetDayBar(1).Low;
            else if (isHigherOpen)
            refPrice = Bars.GetDayBar(1).High;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            if (tradedToday)
            return;
            if (isLowerOpen && Close[0] > refPrice) {
            EnterLong(DefaultQuantity, "Stg001");
            tradedToday = true;
            }
            else if (isHigherOpen && Close[0] < refPrice) {
            EnterShort(DefaultQuantity, "Stg001");
            tradedToday = true;
            }
            }

            #region Properties
            [Description("Profit")]
            [GridCategory("Parameters")]
            public int Profit
            {
            get { return profit; }
            set { profit = Math.Max(1, value); }
            }

            [Description("Loss")]
            [GridCategory("Parameters")]
            public int Loss
            {
            get { return loss; }
            set { loss = Math.Max(1, value); }
            }
            #endregion
            }
            }

            Comment


              #7
              Mark, please move this logic here to the OnBarUpdate() instead - Initialize() could be called multiple times and bars data would not be guaranteed to be available, so for those custom calcs not an ideal processing place.

              isLowerOpen = CurrentDayOHL().CurrentOpen[0] < Bars.GetDayBar(1).Low;
              isHigherOpen = CurrentDayOHL().CurrentOpen[0] > Bars.GetDayBar(1).High;
              if (isLowerOpen)
              refPrice = Bars.GetDayBar(1).Low;
              else if (isHigherOpen)
              refPrice = Bars.GetDayBar(1).High;
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Ok, how do I insure that I calculate isLowerOpen and isHigherOpen only 1 time per day?
                These simply compare today's open price with yesterday's low/high:
                isLowerOpen = CurrentDayOHL().CurrentOpen[0] < Bars.GetDayBar(1).Low;
                isHigherOpen = CurrentDayOHL().CurrentOpen[0] > Bars.GetDayBar(1).High;

                Comment


                  #9
                  You could for example calculate that only on the first bar of session :

                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Is session only one per day, or could there be several sessions in a trading day? If yes, then how to deal with init correctly?

                    Comment


                      #11
                      That would depend on which session template you have underlying for the instrument. If you're concerned with that you could check this and demand the Time[0].Date being different than the previous one for example.

                      BertrandNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

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