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

ATM unmanaged strategy status sequence for MarketPosition Flat to Long or Short?

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

    ATM unmanaged strategy status sequence for MarketPosition Flat to Long or Short?

    When using ATM and GetAtmStrategyEntryOrderStatus(OrderId) waiting for the status to be "Filled" the OrderId is set to string.empty and the order status[2] == "Filled" occurs, when is Position.MarketPosition == MarketPosition changed?

    Is it within the current OnBarUpdate() with the sequence of conditions that the Strategy has implement?

    If the Strategy is using Calculate == Calculate.OnBarClose does it to check for both ATM OrderId is "Filled" and MarketPosition is not "Flat"?


    #2
    Hello Tonofit,

    Thanks for your post.

    Once an entry order is filled, Position.MarketPosition will reflect your current market position. For example, if a long entry order is filled, Position.MarketPosition will be MarketPosition.Long. If a short entry order is filled, Position.MarketPosition will be MarketPosition.Short.

    When using Calculate.OnBarClose, the strategy OnBarUpdate() method will only run when a bar has closed.

    See this help guide page for more information about Calculate: https://ninjatrader.com/support/help.../calculate.htm

    This means that all of the strategy's OnBarUpdate() logic will process once at the close of each bar.

    A strategy uses GetATMStrategyEntryOrderStatus() and Calculate.OnBarClose will get the current state of the specified entry order at the close of each bar. You could print out the current state to see the state of the entry order status.

    See this help guide page for more information and sample code: https://ninjatrader.com/support/help...rderstatus.htm

    A strategy that uses Calculate.OnBarClose and contains a condition to check if Position.MarketPosition == MarketPosition Flat, this condition will process once at the close of each bar. You could test this by printing out Position.MarketPosition in your script to see the market position of your strategy.

    See this help guide page for more information about Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm

    Let me know if I may assist further.
    Last edited by NinjaTrader_BrandonH; 09-09-2022, 11:50 AM.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      For Calculate.OnBarClose using unamanged ATM and the strategy comes from builder but is unlocked code, so that ATM code can be used.

      If I have a short position and get stopped out, and then want to re-enter a new position (short or long) should it be done by checking the strategy id like this and resetting my logic state user variables GO_LONG = false; GO_SHORT = false

      // If the strategy has terminated reset the strategy id.
      if (shortAtmId.Length > 0 && GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat)
      {
      GO_LONG = false;
      GO_SHORT = false;
      }

      Or should I use (Position.MarketPosition == MarketPosition.Flat) where it won't take place until the bar following the current bar from what I'm understanding.

      if (Position.MarketPosition == MarketPosition.Flat)
      {
      GO_LONG = false;
      GO_SHORT = false;
      }

      Comment


        #4
        Hello Tonofit,

        Thanks for your note.

        If you would like to place a long or short order when you are in a flat position, you could create a condition that checks if Position.MarketPosition == MarketPosition.Flat and set your bools within that condition.

        Then, you could create a condition that checks if the bools are true or false and call your order entry method accordingly to place the long/short order.

        Let me know if I may assist further.

        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by FishTrade, Yesterday, 11:11 PM
        3 responses
        11 views
        0 likes
        Last Post FishTrade  
        Started by Graci117, Today, 09:02 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ETFVoyageur, Today, 07:55 PM
        0 responses
        9 views
        0 likes
        Last Post ETFVoyageur  
        Started by janio973, Today, 07:24 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by aligator, 01-06-2022, 12:14 PM
        4 responses
        250 views
        0 likes
        Last Post john_44573  
        Working...
        X