Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Odd behaviour

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

    Odd behaviour

    I have an indicator that calls the method OnPositionUpdate but it reports some data but not other items.
    It reports the Direction ie the MarketPosition but does NOT report the tradeSize or the price?
    I have also tried this using OnExecutionUpdate and get the same behaviour.
    Can support help me here as I am completely lost.
    I should also add that when I designed the indicator using simulated data it worked just fine - turned it off and on - and it no longer works , so I am baffled.

    Code:
        private void OnPositionUpdate(object sender, PositionEventArgs e)
        {
           if(ShowPrints)
            NinjaTrader.Code.Output.Process(string.Format(" OnPosition1 - Instrument: {0} MarketPosition: {1} AveragePrice: {2} Quantity: {3}",
                  e.Position.Instrument.FullName, e.MarketPosition, e.AveragePrice, e.Quantity), PrintTo.OutputTab2);
       
           if(e.MarketPosition == MarketPosition.Flat)
           {
               Direction = 0;
               inTradeSize = 0;
              MyEP1 = 0;
           }
                  if(e.MarketPosition != MarketPosition.Flat)
               {
               inTradeSize = e.Quantity;
               MyEP1 = Instrument.MasterInstrument.RoundToTickSize(e.AveragePrice);
        }
        }​

    #2
    Hello Mindset,

    Try printing the e.Position.Quantity and e.Position.MarketPosition as well as the e.Quantity and e.MarketPosition to see which of these you are wanting to use.

    As an example, when exiting a position:
    e.MarketPosition / e.Quantity is the current position - shows flat with a quantity of 0
    e.Position.MarketPosition / e.Position.Quantity is the updating position - shows long or short with a quantity of 1 with a remove operation


    "I should also add that when I designed the indicator using simulated data it worked just fine - turned it off and on - and it no longer works , so I am baffled."

    Are you assigning handler methods to the <Account>.PositionUpdate and <Account>.ExecutionUpdate events in State.DataLoaded?
    Are you removing handler methods to the <Account>.PositionUpdate and <Account>.ExecutionUpdate events in State.Terminated?

    Are you using Account.All.ToList() when fetching an account?
    Is this Account null?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi
      I get no output at all Printing e.Position.Quantity when I am in a position?
      Yes I have the handlers

      myAccount.AccountItemUpdate += OnAccountItemUpdate;
      myAccount.ExecutionUpdate += OnExecutionUpdate;
      myAccount.PositionUpdate += OnPositionUpdate;​
      and they are terminated correctly
      Last edited by Mindset; 04-03-2025, 08:23 AM.

      Comment


        #4
        LOL It's just told me I am suspected Spam :-)

        Comment


          #5
          Hello Mindset,

          Attached is a modified version of the ProfitCaseStopTrailIndicatorExample found here that prints the position information as well as the output text file produced.
          ProfitChaseStopTrailIndicatorExampleModified_NT8.zip
          NinjaScript Output 4_3_2025 7_24 AM.txt

          I am not able to reproduce.

          The position not being able to exit may indicate a script has caused an issue that has frozen the account thread.
          Close all open workspaces, save a new blank workspace, restart NinjaTrader, then reset the Sim101 account.
          Next, try the attached example script.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks Chelsea - yours works obviously, so let me digest it and adapt to my circumstance. :-)

            Comment


              #7
              QuickQuestion about the naming of the Order having to be "Entry" - why should the order Name make any difference?

              Comment


                #8
                Hello Mindset,

                You can choose any signal name you would like as long as you are not using Atm Strategies.

                The name 'Entry' only has to be used with Atm Strategies.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                558 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                324 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
                545 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