Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Manually syncing a strategy to account via parameters

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

    Manually syncing a strategy to account via parameters

    I'm trying to manually synchronize my strategy to my account's current positions, and not in the way that NT7 allows, where it will flatten if the strategy isn't in a position as of the latest bar. For some reason, the strategy will do this:

    11/5/2010 8:21:00 AM Entered internal PlaceOrder() method at 11/5/2010 8:21:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    However, it won't actually take a historical position. Why is that?

    Code:

    Code:
     public class NinjaTerminalInternal : Strategy
        {
    		
    		public double DailyDifference;
    		private bool _InShort = false;
    		private bool _InLong = false;
    		private int _InQuantity = 0;
    		private bool Traded = false;
    		
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
    			Days2Load = 5;
    			MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    			TraceOrders = true; 
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if (Historical && !Traded)
    			{
    				if (InLong)
    				{
    					EnterLong(InQuantity);
    					Print("Entering Long");
    				}
    				if (InShort)
    				{
    					EnterShort(InQuantity);
    				}
    				Traded = !Traded;
    			}
    			
    			double diff = (-(CurrentDayOHL().CurrentOpen[0] - Close[0]) / Close[0]) * 100;
    			DailyDifference = Math.Round(diff,2,MidpointRounding.AwayFromZero);
            }
    
    
            [GridCategory("Parameters")]
    		public int InQuantity
            {
                get { return _InQuantity; }
                set { _InQuantity = Math.Max(0, value); }
            }
    		
            [GridCategory("Parameters")]
    		public bool InShort
            {
                get { return _InShort; }
                set { _InShort = value; }
            }
    		
            [GridCategory("Parameters")]
    		public bool InLong
            {
                get { return _InLong; }
                set { _InLong = value; }
            }
    		
        }

    #2
    Hello Zwentz,

    What happens when you Print(Position.MarketPosition);

    Is ExitOnClose set to true? This will close positions at end of session.

    Since your bools initiate as false, there may be a timing issue. By the time you set the bool to true, Historical property will start returning false. The strategy has processed all historical bars and will start on real time. Print all these variables to confirm.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hey, thanks! Completely overlooked ExitOnClose.

      For future people with the same question my initialize now looks like this:

      Code:
      protected override void Initialize()
      {
              CalculateOnBarClose = false;
      	Days2Load = 5;
      	MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      	ExitOnClose = false;
              StrategySync = StrategySync.SubmitImmediately;
      }
      You can change to StrategySync to StrategySync.WaitUntilFlat (which is the default) and the strategy won't do anything until you've exited out of your manual position. I just didn't want this functionality for my purposes.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X