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

Official support for Order.IsLong and Order.IsShort?

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

    Official support for Order.IsLong and Order.IsShort?

    Hey there,

    When using the NinjaTrader 8 Editor or Visual Studio, if I create an instance of the Order object, intellisense shows me two bool values IsLong and IsShort. They seem fairly obvious what they mean, but I wanted to be thorough and make sure I understood the detailed purpose of these bools for some smaller cases that aren't so obvious. I'll explain some scenarios below, but the reason why I'm creating this ticket is that after checking the NinjaTrader 8 Help Guide, specifically here: https://ninjatrader.com/support/help...nt8/?order.htm I do not see any mention of these two bool Properties in the Order object. I even searched for IsLong and IsShort in the Guide and found 0 matches.

    The cases that seem obvious for these values are when I have a reference to an Order object that I set from OnOrderUpdate for an order that I placed. If I had placed Buy order with an EnterLong method call and have a reference to a class variable for that order, it would seem that once it is filled, IsLong should be true and IsShort should be false. However, there are several cases that are not so obvious to me. Please see the following examples:

    What about when I call EnterLongLimit and the order is in the Working state, just waiting for price to come down and reach it? Would this Order object have IsLong and IsShort both set to false, or would IsLong be True knowing we could check the OrderState to know if it is filled or not?

    What would these values be for a Stop order or Profit Target order? Would these orders for a long position have IsShort == true because they are set to Sell in order to exit?

    Before using these variables in my code, I just wanted to make sure I fully understood the intention of them. Mostly I wonder if they are intended only for an Entry Order object that is Filled and not Stop or Target orders (or Entry Orders that are limit or stop orders not yet filled) If it's possible to update the Guide with these Properties and descriptions clarifying these things I would hope it could help others with this question as well.

    Thank you!
    Paul

    #2
    Hello Paul,

    <Order>.IsLong and .IsShort is not documented or officially supported by NinjaTrader Support to use. Use at your own risk, and we will not be able to assist with these unsupported properties.


    The <Order>.OrderAction and <Order>.OrderType would be the supported way of knowing the direction of an order.


    Order variables must be assigned from the order object in OnOrderUpdate().


    A buy limit in a working state would be below the market price and fills at the specified price or better, a sell limit would be above the market price.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Very helpful Chelsea, thank you! I do understand Limit orders but was asking about those since IsLong and IsShort didn't seem to apply to them, so I was wondering what they would be. Knowing these bools are not supported makes that a moot point though.

      Can you please confirm my understanding of the OrderAction values?
      - Buy always means Buy to Enter a Long position
      - Sell always means Sell to Exit a Long position
      - SellShort always means Sell to Enter a Short position
      - BuyToCover always means Buy to Exit a Short position

      On that same line of thinking, I want to be sure the following is the safest way to know if my Strategy currently is flat and has a Working Buy Limit order in the market as entered by EnterLongLimit. Please assume entryOrder is an Order object that is set within OnOrderUpdate:

      if (Position.Quantity == 0 && entryOrder != null && entryOrder.OrderAction == OrderAction.Buy)

      Thanks for your time and help, I don't want to use unsupported properties so I really appreciate you clarifying that!

      Comment


        #4
        Hello pdennis,

        Ideally an OrderAction.Buy would always be a buy entry and OrderAction.BuyToCover would be a buy exit, while Sell would be a sell exit and SellShort would be a sell entry. (Programmers don't always use the correct OrderAction in the unmanaged approach)

        The position is updated from OnPositionUpdate. This means that the position may not have yet changed when an order is being processed in OnOrderUpdate(). But in general if OnPositionUpdate has updated then the position would be Position.MarketPosition == MarketPosition.Flat.

        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        6 views
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        8 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        98 views
        1 like
        Last Post caryc123  
        Working...
        X