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

OnPositionUpdate - MarketPosition.Flat works only on SIM

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

    OnPositionUpdate - MarketPosition.Flat works only on SIM

    I use the following logic to determine if I'm flat on a specific instrument:

    protected void OnPositionUpdate(object sender, PositionEventArgs e)
    {
    if (e.Position.Instrument == this.Instrument)
    {
    if (e.MarketPosition == MarketPosition.Flat)
    {
    // Do stuff
    }
    }
    }

    This method works on SIM but not on a live trade. And this appears to be caused by live trades not returning a flat status, but instead a direction long or short only. Example of execution difference:

    Live trade:
    BUY: MarketPosition: Long AveragePrice: 1183.3 Quantity: 1
    STOP: MarketPosition: Short AveragePrice: 0 Quantity: 0

    SIM trade:
    BUY: MarketPosition: Long AveragePrice: 1179.7 Quantity: 1
    STOP: MarketPosition: Flat AveragePrice: 0 Quantity: 0

    So my question is, how can I check if the account is flat on a specific instrument in OnPositionUpdate()?
    Last edited by martyn73; 04-08-2020, 08:16 PM.

    #2
    Hello martyn73

    This could relate to the broker being used, what broker are you currently using for the live test?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I use NinjaTrader Continuum.

      Comment


        #4
        Hello martyn73,

        Thank you for the reply.

        I will need to test this on my end to see if I get the same result. I just wanted to confirm, how are you submitting the order? Could you provide a simple example of what you used so that I can test the same situation?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Sure, I used a simple ATM Strategy with one limit target order, and one stop market order. Entered each trade on the M2K using a limit order. And both were exited through the stop order.

          If you need the Atm Strategy file, or anything from the execution log, just let me know.

          Comment


            #6
            Hello martyn73,

            Thank you for the reply.

            I wanted to clarify, are you using an Addon or watching an account directly by using the addon Account object and its events?

            ATM orders would not be use this override. The strategy overrides and properties are intended for the Managed or Unmanaged approach only. To get an ATM position you would need to use GetAtmStrategyMarketPosition().

            If you are instead using the addon framework here I would likely need an exported sample that we can test with which shows the specific code you used. Otherwise I would not expect this to work when using the override based on the new information.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              I see the notes now in the NT help guide that ATM Strategies do not report position updates through OnPositionUpdate(). My bad for missing that. And in further testing it does report using the SIM101 account but not on live trades. This is what caused the confusion. Any particular reason why it does work for SIM101?

              My question remains the same, I'm running a customer indicator, and in that indicator I want to check when I go flat for the current primary instrument that is loaded on the chart. GetAtmStrategyMarketPosition() alone will not do that because it only reports if a specific Atm Strategy is flat. But if I'm running more than one Atm Strategy I might still have an open position. So I would need to loop through each running Atm Strategy to check. Is that the best option? GetAtmStrategyMarketPosition() is also not event based. Is there an event based method I can use when an Atm Strategy goes flat?

              Thanks.

              Comment


                #8
                Hello martyn73,

                For the sim101 account I am not certain why that would be reporting, if you are subscribed directly to the account that could be why.

                If you are using the addon framework to create the atm, you would generally need to store an instance to the ATMStraetgy object rather than waiting for events. This is demonstrated with the buttons in the addon sample: https://ninjatrader.com/support/help...t_overview.htm
                This works very similar to the NinjaScript strategy approach which observes the external ATM strategy rather than being event driven like the managed or unmanaged approach. An addon works much in the same way and would not be event driven for an ATM, you would need to check the status yourself while it is active. Once the ATM is no longer active it would just report flat.

                If you need to drive logic based on events such as position updates or orders events it is generally suggested to use standard orders or in a strategy the managed/unmanaged approach. ATM's have a separate system to observe their data because it is an external strategy in all use cases.


                I look forward to being of further assistance.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  So I'm simply monitoring Atm Strategies from an indicator. Not using the Add On framework. Is there anything wrong with continuing to use OnPositionUpdate() and just change my check from: if (e.MarketPosition == MarketPosition.Flat) to if (e.MarketPosition == MarketPosition.Flat || e.Quantity == 0) ?

                  Comment


                    #10
                    Hello martyn73,

                    If you are using an Indicator you would need to use the Addon framework methods to execute an ATM from that context. Using OnPositionUpdate is not what is suggested to monitor ATM's, you can see the Addon sample for a full sample of how to use the ATM strategy object outside of a strategy. You would need to hold on to the ATMStrategy objects you create so that you can reference the values later.



                    You can see how the variable is stored:
                    selectedAtmStrategy = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(atmStrategySelector.SelectedAtmStrategy, entryOrder);

                    And then you can look at any of the methods which use the variable selectedAtmStrategy such as GetAtmStrategyMarketPosition()

                    The ATM is not intended to be event driven, you will need to poll for changes in the ATM. If you want an event driven order entry you should avoid using ATM's and submit orders using Submit(), that will be like a standard manual order and will use the standard account overrides/update events.


                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jclose, Today, 09:37 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post jclose
                    by jclose
                     
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    10 responses
                    1,414 views
                    0 likes
                    Last Post Traderontheroad  
                    Started by firefoxforum12, Today, 08:53 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post firefoxforum12  
                    Started by stafe, Today, 08:34 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post stafe
                    by stafe
                     
                    Started by sastrades, 01-31-2024, 10:19 PM
                    11 responses
                    169 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X