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

How to space multiple entrees from each other?

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

    How to space multiple entrees from each other?

    I wonder if you can give me some code example on how to space multiple entrees from each other by a set number of ticks. For example if I am scaling in to a position with extra entrees I don't want the next entree to be made too close to my last one.

    #2
    Hello relogical,

    You may use the "TickSize" object to be able to set the number of ticks away from a price so that you may space out some of your scale in orders.

    For example:
    Code:
    protected override void Initialize()
    {
    	EntryHandling = EntryHandling.UniqueEntries;
    }
    
    protected override void OnBarUpdate()
    {
        //...Entry condition code.
    
        if ( /* Scale in Condition */ )
        {
              // Sets a Long limit order 5 Ticks above the average position price.
    	EnterLongLimit(Position.AvgPrice+5*TickSize,"EnterLong2"); // Set order name unqiuely to scale in
        }
    
       // Rest of code.
    }
    JCNinjaTrader Customer Service

    Comment


      #3
      Thank you for the suggestion but this will only use Avg.Price as the reference point. This will not work for me. I need to use the last entree as the reference point.

      Comment


        #4
        Hello relogical,

        That was just an example. If you would like to if you would like to store the the price of the last executed order then you may want to get the information from the OnExecution() method.

        Code:
        double lastTradedPrice;
        
        protected override void OnExecution(IExecution execution)
        {
                  // Condition to check to see if OnExecution is being called for your entry order and not an exit
                  // Note you will want to change this to your own logic as this is an example
                  if (entryOrder != null && entryOrder == execution.Order)
        	   {
                             lastTradedPrice = execution.Price;
                             // Now you can use the lastTradedPrice variable for your scale in orders
                    }
        }
        JCNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NM_eFe, Today, 10:13 AM
        0 responses
        1 view
        0 likes
        Last Post NM_eFe
        by NM_eFe
         
        Started by hdge4u, Yesterday, 12:23 PM
        1 response
        10 views
        0 likes
        Last Post hdge4u
        by hdge4u
         
        Started by 1001111, Today, 09:45 AM
        0 responses
        4 views
        0 likes
        Last Post 1001111
        by 1001111
         
        Started by DTSSTS, 01-28-2024, 12:07 PM
        11 responses
        557 views
        0 likes
        Last Post bmo111
        by bmo111
         
        Started by Torontobluejays, Today, 08:43 AM
        0 responses
        1 view
        0 likes
        Last Post Torontobluejays  
        Working...
        X