Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Chris L.NinjaTrader Customer Service

    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
        Chris L.NinjaTrader Customer Service

        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
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,221 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            437 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            9 views
            0 likes
            Last Post FAQtrader  
            Working...
            X