Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order always entered when strategy is Enabled

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

    Order always entered when strategy is Enabled

    I'm loading a strategy into the Strategies tab and it always enters an order immediately upon Enabling it when I'm connected to IB. I'm assuming it is acting on historical data, but I can't figure out why this is happening. I've included an outline of my strategy below. Can someone tell me what I'm doing wrong?

    p.s. no problems when connected to market replay.
    p.p.s. an order is entered if I enable this before or after 6:45am.

    Code:
    namespace NinjaTrader.Strategy
    {
        public class mystrat : Strategy
        {
            bool tradingTimeAccepted = false;
    
            protected override void Initialize()
            {
                Add("ZF 09-15",PeriodType.Tick, 1);
                Add("ZB 09-15",PeriodType.Minute, 1);
                Add("ZN 09-15",PeriodType.Minute, 1); 
                Add("ZF 09-15",PeriodType.Minute, 1);
                CalculateOnBarClose     = true;
                Unmanaged                 = true;
            }
            
            protected override void OnBarUpdate()
            {
                if (Historical)  return;
                TimeManagement();
                
                if (tradingTimeAccepted)
                {
                    if (certain conditions exist)
                        EnterOrder();
                }
    
                CalculatePNL();
            }
    
            private void TimeManagement()
            {
                tradingTimeAccepted = false; 
                
                if (ToTime(Time[0]) > 64500 && ToTime(Time[0]) < 120000)
                    tradingTimeAccepted = true;
                
                if (ToTime(Time[0]) == 125500) 
                {
                    // exit trade
                }
                
                if (ToTime(Time[0]) == 120000) 
                {
                    // manage trade
                }
            }
        }
    }

    #2
    Hello lookOutBelow,

    Thank you for writing in. Based on what you have said, it sounds like your strategy is trying to sync to your IB account position on starting. Could you please confirm if you are syncing your account position in the strategy? Please see this help guide document for more information: http://ninjatrader.com/support/helpG...sync%2Baccount

    Thank you in advance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      I'm not completely clear on the differences between those settings. However, I have tried both with the same result. I've also tried "sync account position" in both true and false states. All combinations of these settings produce the same results.

      Comment


        #4
        Okay. Unless I'm going completely insane (could be the case!), if (historical) is being ignored. Can someone confirm for me? I've included a test strategy that has the same problem.

        The following strategy should report "false" until it gets to live data. My ouput window is showing true on dates preceding live data.

        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("Enter the description of your strategy here")]
            public class historicTimeTesting : Strategy
            {
               
                bool tradingTimeAccepted = false;
                
        
                protected override void Initialize()
                {
                    Add("ZF 09-15",PeriodType.Tick, 1);
                    Add("ZB 09-15",PeriodType.Minute, 1);
                    Add("ZN 09-15",PeriodType.Minute, 1); 
                    Add("ZF 09-15",PeriodType.Minute, 1);
                    CalculateOnBarClose     = true;
                    Unmanaged                 = true;
                }
        
                
                protected override void OnBarUpdate()
                {
                    if (Historical)  return;
                    TimeManagement();
                    PrintWithTimeStamp("tradingTimeAccepted: " + tradingTimeAccepted);
                }
                
                
                private void TimeManagement()
                {
                    tradingTimeAccepted = false; 
                    
                    if (ToTime(Time[0]) > 64500 && ToTime(Time[0]) < 120000)
                         tradingTimeAccepted = true;
                }
            }
        }
        p.s. Please note that the image shows the account as "Sim101". I actually have this set to an IB account. I just didn't want that posted here.
        Attached Files
        Last edited by lookOutBelow; 08-03-2015, 10:25 AM.

        Comment


          #5
          Hello lookOutBelow,

          The strategy code you provided should not report anything until it reaches realtime data. So we should not ever see false unless, in realtime, the current bar time is before 6:45am or after 12:00pm. I am unable to replicate this issue on my end. If you adjust the OnBarUpdate code like this you should have a better idea of what bars are actually being called and their relation to the chart:
          Code:
          PrintWithTimeStamp("tradingTimeAccepted(" + CurrentBar.ToString() + "): " + tradingTimeAccepted);
          DrawText("barNumber" + CurrentBar.ToString(), CurrentBar.ToString(), 0, High[0] + TickSize, Color.Red);
          Please send me your log and trace files for today so that I may investigate further.
          You can do this by going to the Control Center-> Help-> Mail to Platform Support.
          Please reference the following ticket number in the body of the email: #1362749

          Thank you in advance.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #6
            Just so I know we are on the same page. Are you launching this from the Strategies tab and using a 1 tick input?

            Cause if I launch this from a chart, or the Strategy tab using 1min, I get different results.

            Comment


              #7
              Hello lookOutBelow,

              Thank you for clarifying. I am not experiencing these issues when launching the test strategy from the strategies tab with 1 tick. Everything is outputting as expected, there are no rogue bars getting called. Here is an excerpt:
              Code:
              **NT** Enabling NinjaScript strategy 'historicTimeTesting/b9f4526e29c3411292f811bdc521210f' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
              8/3/2015 12:13:55 PM tradingTimeAccepted(743346): False
              8/3/2015 12:13:56 PM tradingTimeAccepted(743347): False
              8/3/2015 12:13:57 PM tradingTimeAccepted(743348): False
              8/3/2015 12:13:57 PM tradingTimeAccepted(743349): False
              8/3/2015 12:13:58 PM tradingTimeAccepted(743350): False
              This lets us know that your code up to that point is not the issue and that the issue is likely something else (settings or account connection). At this point, it may be more efficient to resolve this via remote support. If you would like to set up a remote support session, please launch the remote support application (or Team Viewer): http://www.ninjatrader.com/remotesupport
              Then email platformsupport[AT]ninjatrader[DOT]com with the userID and password provided by the remote support application as well as this ticket number: #1362749

              Please let me know if you have any questions at all.
              Michael M.NinjaTrader Quality Assurance

              Comment


                #8
                Thanks for looking into this. I'm going to try a few things. If I can't resolve it, I will do the remote session thing.

                Thanks

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                606 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                353 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
                560 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                561 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X