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

Order Management

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

    Order Management

    When I have a strategy running on a pair that has an open position, how do I:

    1. Get information about the open position:
    - Open price, lots, type (buy or sell), limit, stop

    2. Update the stop and limit

    3. Close part of the position

    Thanks in advance!!

    #2
    Hello RiversideDude,

    The position information is in the Position object.
    http://ninjatrader.com/support/helpG...7/position.htm

    For example the entry price is Position.AvgPrice, the market position is Position.MarketPosition, etc.

    The position will not be an order but will be a position.

    You can track the entry order with an IOrder object.
    http://ninjatrader.com/support/helpG...nt7/iorder.htm

    This provides the OrderAction, and OrderType.

    You can update any order that is in a working state by calling it again with the same signalName. This includes SetStopLoss and SetProfitTarget.

    SetStopLoss("longEntry", CalculationMode.Price, 1000, false);
    SetStopLoss("longEntry", CalculationMode.Price, 1000.25, false);

    This would move the stop for longEntry from 1000 to 1000.25.

    To scale out of a position. Exit the amount you want to scale out with an exit order.
    I recommend that if you plan to scale out, use separate orders to enter specific quantities and exit the same quantities. This will make everything much simpler.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Is it really that easy? Do I have to instantiate the object or is it automatically created? How to check if one or more positions are opened for that currency?

      Thanks!!

      Comment


        #4
        Hello RiversideDude,

        Which ever account you are connected to can only have one Position per instrument.

        If your position is long 1 and you place a buy order with a quantity of 2, your position becomes long 3. If you place a sell order for 1 the position becomes long 2.

        You will not be able to have multiple positions for the same instrument on the same account. You would need different instruments or different accounts.

        IOrder objects are created when you call the method to place the order. (The method will return the IOrder object which you can save to your variable)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          When is the position object created?

          Thanks!!

          Comment


            #6
            Hello RiversideDude,

            The Position object is created when the script is initialized and will always exist.

            The Position.Market position will always be MarketPosition.Long, MarketPosition.Short, or MarketPosition.Flat.


            If you would like to take on learning NinjaScript, we have a fully documented help guide which will help you get started with Ninja Script. You will find language references to all of the methods and functions you will be using. You will also see a tutorial section which will help you create your first indicator and get you started with some of these concepts.
            A link to our Help Guide with tutorials can be found below:


            The entire Alphabetical Reference can be found with the following link:


            The best way to begin learning NinjaScript is to use the Strategy Wizard. With the Strategy Wizard you can setup conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

            I'm also proving a link to a pre-recorded set of videos 'Strategy Wizard 301' and 'NinjaScript Editor 401' for you to view at your own convenience.
            Strategy Wizard 301 - https://www.youtube.com/watch?v=FmBi...56536A44DD7105
            NinjaScript Editor 401 - https://www.youtube.com/watch?v=K8v_...56536A44DD7105

            If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:


            I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript: http://www.ninjatrader.com/support/h..._resources.htm

            You will find Reference Samples online as well as some Tips and Tricks for both indicators and strategies:
            Click here to see our NinjaScript Reference Samples: http://www.ninjatrader.com/support/f...splay.php?f=30
            Click here to see our NinjaScript Tips: http://www.ninjatrader.com/support/f...ead.php?t=3229

            These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.

            There is a also a growing library of user submitted custom indicators (100+) that can be downloaded from our support form. Please look in the NinjaScript File Sharing section of our support forum as you may find what you are looking for there: http://www.ninjatrader.com/support/f...splay.php?f=37
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Brevo, Today, 01:45 AM
            0 responses
            6 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            3 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            242 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            384 views
            1 like
            Last Post Gavini
            by Gavini
             
            Started by oviejo, Today, 12:28 AM
            0 responses
            6 views
            0 likes
            Last Post oviejo
            by oviejo
             
            Working...
            X