Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy not running in NT7

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

    Strategy not running in NT7

    Because of the shortcomings of NT6.5 and backtesting a tick based strategy, I have tried running my strategy with market replay and backtest in NT7, It does not appear to run at all.

    Here is a small code snippet to demonstrate the wall I have encountered.

    Code:
            protected override void Initialize()
            {
    			Print("*");
    			CalculateOnBarClose = false;
    			TimeInForce = Cbi.TimeInForce.Gtc;
    			SeekType = null;
    			Indication = null;
    			OrderPending = null;
    			EntriesPerDirection = 2;
    			EntryHandling = EntryHandling.AllEntries;
       			TraceOrders = true;
    			EntryPriceLong = 0;
    			EntryPriceShort = 0;
            }
    
            protected override void OnBarUpdate()
            {
    			Print("0");
    			//if (Historical)return;
    			if (CurrentBar < 1)return;
    			//if (FirstTickOfBar)return;
    			if (Bars.FirstBarOfSession)
    The * Prints, the 0 does not...

    Help please?

    #2
    Are there any error messages in your Control Center Log tab?
    RayNinjaTrader Customer Service

    Comment


      #3
      Simple answer is no, but I had to add some characters to make it long enough.

      Comment


        #4
        Try this and see if it works.

        Print("*");
        // CalculateOnBarClose = false;
        // TimeInForce = Cbi.TimeInForce.Gtc;
        // SeekType = null;
        // Indication = null;
        // OrderPending = null;
        // EntriesPerDirection = 2;
        // EntryHandling = EntryHandling.AllEntries;
        // TraceOrders = true;
        // EntryPriceLong = 0;
        // EntryPriceShort = 0;
        RayNinjaTrader Customer Service

        Comment


          #5
          Still no joy... I am just flabbergasted, took me all night to get to the point of putting a print statement in Initialize block... Hang on, getting rest of top portion of code...

          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
          
          namespace NinjaTrader.Strategy
          {
              [Description("Enters trades @ peaks following trend.")]
              public class TrendTrack : Strategy
              {
                  #region Variables
          			private int bank = 2; // Default setting for Bank
          			private int hide = 2; // Default setting for Hide
          			private int entry = 2; // Default setting for Entry
          			private int span = 3; // Default setting for Span
          			private bool orderSet = false;//Flag for quantity increment
          			private bool BlackFlag = false;//Flag for "losing day"
          			private int orderQuantity = 1; // Default setting for Bank Quantity
          			private bool? SeekType; //Longs or Shorts
          			private bool? Indication; //Order Trigger
          			private bool? OrderPending;
          			private bool? Status;//Flag for MACD above, below or within Bollinger
          			private bool Confirm;//Flag for MACD above Lower Bollinger or Below Upper Bollinger
          			private double Cancel;//Cancel order before fill price.
          			private double Avg;
          			private double trend;
          			private double flag = 100;
          			private double StopLong;//Long Stop Loss
          			private double StopShort;//Short Stop Loss
          			private double EntryTrigger;//Order Entry Trigger
          			private double EntryPriceLong = 0;//Order EntryPrice
          			private double EntryPriceShort = 0;//Order EntryPrice
          			private double Upper;
          			private double Lower;
          			private IOrder LongRunner = null;
          			private IOrder LongBank = null;
          			private IOrder ShortRunner = null;
          			private IOrder ShortBank = null;
          			private string Market;
          			public int Fast;//Fast for MACDBBLines
          			public int Slow;//Slow for MACDBBLines
          			public int Smooth;//Smooth for MACDBBLines
          			public int numStdDev;//Number of Standard Deviations for MACDBBLines
          			public int period;//SMA period for MACDBBLines
          			private bool? NewHighLow;//Flag for new PeakHigh or PeakLow
                  #endregion
          Did I see something about this:

          [Description("Enters trades @ peaks following trend.")]

          In code breaking changes?
          Last edited by Sleeping Troll; 05-21-2010, 10:28 AM.

          Comment


            #6
            I think you will have to debug a little deeper unfortuantely. I would review the code breaking changes again although, if an exception is caught, it should generate a log entry. Comment out more code until you find what exactly the code is getting hung up on.
            RayNinjaTrader Customer Service

            Comment


              #7
              OK, I created a new strategy "TrendTrack7" and and copied the contents of "TrendTrack" Class into new strategy, same results.

              Comment


                #8
                I would expect the same results. You really will have to start stripping things down until you get something that works so you can isolate where in your code the source of the problem is. We can then take a look if this is something on your end or an issue on our end.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Good advice, however...

                  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
                  
                  namespace NinjaTrader.Strategy
                  {
                      [Description("Enters trades @ peaks following trend.")]
                      public class TrendTrack : Strategy
                      {
                          #region Variables
                  //			private int bank = 2; // Default setting for Bank
                  //			private int hide = 2; // Default setting for Hide
                  //			private int entry = 2; // Default setting for Entry
                  //			private int span = 3; // Default setting for Span
                  //			private bool orderSet = false;//Flag for quantity increment
                  //			private bool BlackFlag = false;//Flag for "losing day"
                  //			private int orderQuantity = 1; // Default setting for Bank Quantity
                  //			private bool? SeekType; //Longs or Shorts
                  //			private bool? Indication; //Order Trigger
                  //			private bool? OrderPending;
                  //			private bool? Status;//Flag for MACD above, below or within Bollinger
                  //			private bool Confirm;//Flag for MACD above Lower Bollinger or Below Upper Bollinger
                  //			private double Cancel;//Cancel order before fill price.
                  //			private double Avg;
                  //			private double trend;
                  //			private double flag = 100;
                  //			private double StopLong;//Long Stop Loss
                  //			private double StopShort;//Short Stop Loss
                  //			private double EntryTrigger;//Order Entry Trigger
                  //			private double EntryPriceLong = 0;//Order EntryPrice
                  //			private double EntryPriceShort = 0;//Order EntryPrice
                  //			private double Upper;
                  //			private double Lower;
                  //			private IOrder LongRunner = null;
                  //			private IOrder LongBank = null;
                  //			private IOrder ShortRunner = null;
                  //			private IOrder ShortBank = null;
                  //			private string Market;
                  //			public int Fast;//Fast for MACDBBLines
                  //			public int Slow;//Slow for MACDBBLines
                  //			public int Smooth;//Smooth for MACDBBLines
                  //			public int numStdDev;//Number of Standard Deviations for MACDBBLines
                  //			public int period;//SMA period for MACDBBLines
                  //			private bool? NewHighLow;//Flag for new PeakHigh or PeakLow
                          #endregion
                  
                          protected override void Initialize()
                          {
                  //			CalculateOnBarClose = false;
                  //			TimeInForce = Cbi.TimeInForce.Gtc;
                  //			SeekType = null;
                  //			Indication = null;
                  //			OrderPending = null;
                  //			EntriesPerDirection = 2;
                  //			EntryHandling = EntryHandling.AllEntries;
                  //			TraceOrders = true;
                  //			EntryPriceLong = 0;
                  //			EntryPriceShort = 0;
                  			Print("*");
                          }
                  
                          protected override void OnBarUpdate()
                          {
                  			Print("0");
                  //			//if (Historical)return;
                  //			if (CurrentBar < 1)return;
                  //			//if (FirstTickOfBar)return;
                  //			if (Bars.FirstBarOfSession)
                  //			{
                  
                  ...
                  ...
                  ...
                  
                  
                  //						Cancel = Lower + (Hide * TickSize);
                  //					}
                  //					
                  //					SetStopLoss(CalculationMode.Price,StopShort);
                  //					SetProfitTarget("ShortBank",CalculationMode.Price,EntryPriceShort - (Bank * TickSize));
                  //					ShortBank = EnterShortLimit(0,true,1 + orderQuantity,EntryPriceShort,"ShortBank");
                  //					ShortRunner = EnterShortLimit(0,true,orderQuantity,EntryPriceShort,"ShortRunner");
                  //					OrderPending = false;
                  //				}
                  //								
                  //			#endregion
                  //			#region Order Maintenance
                  //			Print("6");
                  //				if (Position.MarketPosition == MarketPosition.Flat && LongRunner != null && Input[0] >= Cancel)
                  //				{
                  //					CancelOrder(LongRunner);
                  //					Print ("Long Cancel due to new fib approached");
                  //					if (LongBank != null)
                  //					{
                  //						CancelOrder(LongBank);
                  //					}
                  //					OrderPending = null;
                  //				}
                  //				if (Position.MarketPosition == MarketPosition.Flat && ShortRunner != null && Input[0] <= Cancel)
                  //				{
                  //					CancelOrder(ShortRunner);
                  //					Print ("Short Cancel due to new fib approached");
                  //					if (ShortBank != null)
                  //					{
                  //						CancelOrder(ShortBank);
                  //					}
                  //					OrderPending = null;
                  //				}
                  //				if (Position.MarketPosition == MarketPosition.Flat && LongRunner != null && Status == false)
                  //				{
                  //					CancelOrder(LongRunner);
                  //					if (LongBank != null)
                  //					{
                  //						CancelOrder(LongBank);
                  //					}
                  //					OrderPending = null;
                  //				}
                  //				if (Position.MarketPosition == MarketPosition.Flat && ShortRunner != null && Status == true)
                  //				{
                  //					CancelOrder(ShortRunner);
                  //					if (ShortBank != null)
                  //					{
                  //						CancelOrder(ShortBank);
                  //					}
                  //					OrderPending = null;
                  //				}
                  //				if(Position.MarketPosition == MarketPosition.Long && StopLong < Lower - (Hide * TickSize))
                  //				{
                  //					StopLong = Lower - (Hide * TickSize);
                  //					SetStopLoss(CalculationMode.Price,StopLong);
                  //				}
                  //				if(Market == "Fat" && Input[0] > EntryPriceLong + (Hide * 2 * TickSize) && Position.MarketPosition == MarketPosition.Long)
                  //				{
                  //					StopLong = Lower + (Hide * TickSize) + ((Upper - Lower)/2);
                  //					SetStopLoss(CalculationMode.Price,StopLong);
                  //					EntryPriceLong = EntryPriceLong + (Hide * TickSize);
                  //				}
                  //				if(Position.MarketPosition == MarketPosition.Short && StopShort >= Upper + (Hide * TickSize))
                  //				{
                  //					StopShort = Upper + (Hide * TickSize);
                  //					SetStopLoss(CalculationMode.Price,StopShort);
                  //				}
                  //				if(Market == "Fat" && Input[0] < EntryPriceShort - (Hide * 2 * TickSize) && Position.MarketPosition == MarketPosition.Short)
                  //				{
                  //					StopShort = EntryPriceShort - (Hide * TickSize) - ((Upper - Lower)/2);
                  //					SetStopLoss(CalculationMode.Price,StopShort);
                  //					EntryPriceShort = EntryPriceShort - (Hide * TickSize);
                  //				}
                  //				if (BlackFlag == false && Position.MarketPosition == MarketPosition.Flat && Performance.AllTrades.Count > 0 && Performance.AllTrades[Performance.AllTrades.Count - 1].ProfitPoints > 0 && orderSet != true)
                  //				{
                  //					orderQuantity++;
                  //					orderSet = true;
                  //				}
                  //				if (BlackFlag == false && Position.MarketPosition == MarketPosition.Flat && Performance.AllTrades.Count > 1 && Performance.AllTrades[Performance.AllTrades.Count - 1].ProfitPoints <= 0)
                  //				{
                  //					orderQuantity = 1;
                  //					orderSet = false;
                  //				}
                  //				
                  //			#endregion
                  		}
                  //		protected override void OnOrderUpdate(IOrder order) 
                  //		{ 
                  //			if (LongRunner != null && LongRunner.Token == order.Token) 
                  //			{ 
                  //				if (LongRunner.OrderState == OrderState.Filled)
                  //				{
                  //					OrderPending = null;
                  //					orderSet = false;
                  //				}
                  //			} 
                  //			if (ShortRunner != null && ShortRunner.Token == order.Token) 
                  //			{ 
                  //				if (ShortRunner.OrderState == OrderState.Filled)
                  //				{
                  //					OrderPending = null;
                  //					orderSet = false;
                  //				}
                  //			}
                  //		}
                  //         
                  //		#region Properties
                  //        [Description("Target Ticks for Bank orders")]
                  //        [Category("Parameters")]
                  //        public int Bank
                  //        {
                  //            get { return bank; }
                  //            set { bank = Math.Max(1, value); }
                  //        }
                  //
                  //        [Description("Tick offset for StopLoss Hide")]
                  //        [Category("Parameters")]
                  //        public int Hide
                  //        {
                  //            get { return hide; }
                  //            set { hide = Math.Max(1, value); }
                  //        }
                  //
                  //        [Description("Tick offset for Entry price")]
                  //        [Category("Parameters")]
                  //        public int Entry
                  //        {
                  //            get { return entry; }
                  //            set { entry = Math.Max(0, value); }
                  //        }
                  //		
                  //		
                  //		[Description("$ Loss 'BlackFlag'")]
                  //        [Category("Parameters")]
                  //        public double Flag
                  //        {
                  //            get { return flag; }
                  //            set { flag = Math.Max(0, value); }
                  //        }
                  //
                  //        [Description("Minimum Span between Fibs for 'Normal' trade range")]
                  //        [Category("Parameters")]
                  //        public int Span
                  //        {
                  //            get { return span; }
                  //            set { span = Math.Max(1, value); }
                  //        }
                  //         #endregion
                     }
                  }
                  Everything but the Print statement is commented...
                  Does not work, I am at a Total loss! other strategies run...

                  Comment


                    #10
                    Hello,

                    Just wanted to let you know we received your note and you should have a response shortly.

                    Thank you for your patience.
                    BrettNinjaTrader Product Management

                    Comment


                      #11
                      Transferred script back to 6.5, and it runs fine... re exported to 7 and same results. Would you like me to email the zip?

                      Comment


                        #12
                        Sleeping,



                        I copied the code you provided with the comments and was able to get it to run and print to the output window. This means you have something else that is not commented or something that is not setup correctly in the NinjaScript file. What I would try next is creating a new Strategy file(Control Center->Tools->Strategy) and then copy the Initialize section(between the brackets { }) and compile, run the code and make sure it prints the * once or possible 3 times in the output window. Then copy the OnBarUpdate() and compile, then check to see it the 0 prints to the output window. Continue this until everything is copies over, if it works then start uncommenting items.


                        Let me know how this goes.
                        BrettNinjaTrader Product Management

                        Comment


                          #13
                          Did it print "0" or just "*"?

                          Comment


                            #14
                            Once you get OnBarUpdate and Initilized copied so that both Print statements are there you will see the following in the output window

                            *
                            *
                            *
                            *
                            *
                            *
                            **NT** Enabling NinjaScript strategy 'test4/ac08f0be7ae5417b91b3c7e18799849f' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=False MaxRestarts=4 in 5 minutes
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            0
                            BrettNinjaTrader Product Management

                            Comment


                              #15
                              aha, I am not getting:

                              **NT** Enabling NinjaScript strategy 'test4/ac08f0be7ae5417b91b3c7e18799849f' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=False MaxRestarts=4 in 5 minutes

                              Wow, not even getting that in log! any suggestions?


                              Thx!
                              Last edited by Sleeping Troll; 05-21-2010, 12:46 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              628 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              359 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              562 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X