• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.

                    https://ninjatrader.com/support/help...t_overview.htm

                    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 Brillo, Today, 12:40 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post Brillo
                    by Brillo
                     
                    Started by authenticx, 05-29-2020, 03:51 PM
                    3 responses
                    59 views
                    0 likes
                    Last Post NinjaTrader_ChrisL  
                    Started by nikolaalx, Today, 07:31 AM
                    10 responses
                    36 views
                    0 likes
                    Last Post bltdavid  
                    Started by HiddenPhilosopher, Today, 09:28 AM
                    0 responses
                    11 views
                    0 likes
                    Last Post HiddenPhilosopher  
                    Started by tipslark, Today, 07:23 AM
                    0 responses
                    23 views
                    0 likes
                    Last Post tipslark  
                    Working...
                    X