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

linking orders to indicators

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

    linking orders to indicators

    if you have three indicators in your strategy - how do you link a stop limit order to which ever one is set off first?

    also - what's the code for calculating the quantity of shares automatically? I'd like to set a % of my account value, then have the code determine how many shares need to be purchased. and as a subset, how do you get it to round down to the nearest 100 shares?

    Thanks!

    #2
    Hello Mr Roboto,

    Thank you for your post.
    how do you link a stop limit order to which ever one is set off first?
    Can you clarify what you mean by set off first? Are you setting a specific level they must cross?

    For the order size, you set the 'Set Order Quantity' option to 'by account size' which will allow you to set a virtual account value under 'Account size' that will be used to determine maximum order size based on the margin settings set for the instrument you are trading with the strategy. The margin settings are located under Tools > Instrument Manager > search for your instrument > select the instrument > select Edit > on the Definition tab you can set the 'Margin value'.

    For information on editing instruments please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

    Otherwise, you can develop your own internal logic in the strategy. You can base this off of your own variable for account size, using GetAccountValue() to pull Buying Power, Cash Value or even Realized Profit and Loss: http://www.ninjatrader.com/support/h...countvalue.htm

    You will need to ensure your brokerage connection provides the information you wish to pull at the following link: http://www.ninjatrader.com/support/h...counts_tab.htm

    To calculate the contract size you can use the following code:
    Code:
    			int percent = 25;
    			int size = (int)Math.Round((GetAccountValue(AccountItem.CashValue)*percent)/100, 0);

    Comment


      #3
      Hello Mr Roboto,

      The correct code is actually below, and this will round to the nearest 100:
      Code:
      				int percent = 25;
      			int size = (int)Math.Round(((GetAccountValue(AccountItem.CashValue)*percent)/100)/100)*100;

      Comment


        #4
        Thanks Pat - great stuff

        For the level that gets set off - let's use 9 different moving averages as an example. Let's say the stock moves above one moving average first, and you'd like to do a stop limit order. That order's stop would be the MA, the limit would be 69 ticks above the MA. How do you get the buy order to literally pick the first MA that gets pierced, and base the stop + limit price on that MA?

        For the order size, you set the 'Set Order Quantity' option to 'by account size' which will allow you to set a virtual account value under 'Account size' that will be used to determine maximum order size based on the margin settings set for the instrument you are trading with the strategy.
        I'm not following. Where's the "set order quantity" option? Are you talking about the quantity field in the syntax? I tried writing accountsize in the place of the bolded "quantity" below - & it didn't work.

        EnterLongStopLimit(int quantity, double limitPrice, double stopPrice)

        Comment


          #5
          Hello Mr Roboto,

          Thank you for your response.

          Create three conditions, one for each Moving Average Cross and set your EntriesPerDirection to 1.

          Both SetOrderQuantity and EntriesPerDirection are available through the UI when enabling your strategy on the Strategies tab of the Control Center or Strategies menu of the Chart.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ageeholdings, 05-01-2024, 05:22 AM
          6 responses
          42 views
          0 likes
          Last Post ageeholdings  
          Started by tony_28217, Today, 07:04 PM
          0 responses
          11 views
          0 likes
          Last Post tony_28217  
          Started by flybuzz, Today, 10:33 AM
          1 response
          9 views
          0 likes
          Last Post flybuzz
          by flybuzz
           
          Started by spencerp92, 10-10-2023, 09:56 AM
          4 responses
          309 views
          0 likes
          Last Post flybuzz
          by flybuzz
           
          Started by samish18, Yesterday, 10:13 AM
          1 response
          26 views
          0 likes
          Last Post NinjaTrader_Eduardo  
          Working...
          X