Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does Position.MarketPosition called in one strategy affect another?

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

    Does Position.MarketPosition called in one strategy affect another?

    For example, if I'm trying to limit the number of trades for a strategy to less than 5. If I have another strategy running simultaneously, will any trades triggered in the other strategy affect the calculation for MarketPosition or my variable for EntriesToday in THIS strategy? I have multiple strategies running and this particular one keeps missing trades, yet every time I backtest it the behavior is as expected.

    int EntriesToday = 0;

    protected override void OnPositionUpdate(IPosition position)
    {
    if(position.MarketPosition != MarketPosition.Flat)
    EntriesToday++;
    }


    protected override void OnBarUpdate()
    {

    if (FirstTickOfBar)
    {
    if (Bars.BarsSinceSession == 0)
    {
    Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out SessionStartTime, out SessionEndTime);

    if(Position.MarketPosition == MarketPosition.Flat || BarsSinceEntry() > 0)
    EntriesToday = 0;

    }

    if (Position.MarketPosition == MarketPosition.Flat && EntCondL && (EntriesToday < 5 || EndofSess))
    EnterLongMarket(NShares);
    }

    #2
    Hi nmk85roll, thanks for posting. The Position object represents the Strategy position, not the Account position. When the Strategy position and Account position are the same, the strategy is said to be "in sync" with the account. You can see columns for Strategy position, Account position, and Sync in the Strategies tab of the Control Center. Referencing Position.MarketPosition references the Strategy position, not the Account position.

    A better way to count entries is to either increment the counter right after you call the entry order, or read the Position.Quantity value. As with most debugging, use the Print(); method to print out data from the script to make sure it's doing what you expect.

    Kind regards,
    -ChrisL

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hi nmk85roll, thanks for posting. The Position object represents the Strategy position, not the Account position. When the Strategy position and Account position are the same, the strategy is said to be "in sync" with the account. You can see columns for Strategy position, Account position, and Sync in the Strategies tab of the Control Center. Referencing Position.MarketPosition references the Strategy position, not the Account position.

      A better way to count entries is to either increment the counter right after you call the entry order, or read the Position.Quantity value. As with most debugging, use the Print(); method to print out data from the script to make sure it's doing what you expect.

      Kind regards,
      -ChrisL
      Thanks Chris, that's what I was afraid of. The hard part about debugging this is it backtests and performs properly on market replay and I only see the issue in live testing every so often. Happened once this week and once last week, both times the trade executed 3 times just fine and then the 4th time it didn't trigger for some reason. Can we move to email and I can send you code as the issue may not be with the MarketPosition then.

      Comment


        #4
        Hi nmk85roll, What connection technology are you using on the live account? If its Rithmic or Interactive Brokers, the updating events (OnPositionUpdate, OnExecutionUpdate) do not come in a guaranteed order, so one must take special care in their strategy to work with this caveate. Please let me know

        -ChrisL

        Comment


          #5
          Originally posted by NinjaTrader_ChrisL View Post
          Hi nmk85roll, What connection technology are you using on the live account? If its Rithmic or Interactive Brokers, the updating events (OnPositionUpdate, OnExecutionUpdate) do not come in a guaranteed order, so one must take special care in their strategy to work with this caveate. Please let me know

          -ChrisL
          It's Ninjatrader Brokerage with Continuum.

          Comment


            #6
            Hi, We can continue through email. Please send an email with details to scriptingsupport at ninjatrader.com and reference "Attn ChrisL 3617707" in the body or subject.

            Kind regards,
            -ChrisL

            Comment

            Latest Posts

            Collapse

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