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

Multiple Entry orders with separate takeprofit and stoploss for each entry

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

    Multiple Entry orders with separate takeprofit and stoploss for each entry

    Hi All,

    Im sure this has been done many times as fairly standard approach, but i cant seem to find the logic to create multiple orders dynamically depending on "EntriesPerDirection" value, then assign this variable order to pair with a new stoploss and take profit order?

    The forum alludes to using an array or list to create the orders but the trail ends there with no examples on how to implement this.

    How would one start to implement this using managed orders? Any examples or deeper explanation on how to apply lists and retrieve these listed orders to create the separate TP and SL would be much appreciated.

    Thankyou

    #2
    Hello mr_trade,

    Just as a suggestion for custom logic you could create, you could use a for loop that adds the index to the signal name string.

    Something like:

    for (int index = 0; index < EntriesPerDirection; index++)
    {
    EnterLong("enterorder"+index);
    }

    Below are publicly available links to a 3rd party educational site on using for loops and using lists and arrays.
    http://www.dotnetperls.com/for
    Create a new List, add elements to it, and loop over its elements with for and foreach.

    http://www.dotnetperls.com/array

    And a few forum posts you may find helpful.
    Hello. I want to check on the strategy start are there any working orders placed on the instrument and are any other strategies running on the instrument. How to do it in a thread safe way? Can I just do it like this: #region check is no working orders on instrument List&lt;Order&gt;

    Last edited by NinjaTrader_ChelseaB; 11-15-2020, 08:08 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the pointer Chelsea.

      This is similar approach I was taking so good to know. I can create the entries and have a TP, SL attached, so far so good. However I have noticed after the 2nd order is filled the position average price is corrected and averaged up/down as I would expect, but after the second position is closed (assuming it’s the second position) the cost averaging of the position is not updated and remains in the same position on the chart and in execution the order remains the same average price, is there additional steps to correct this? Or maybe my SL or TP isn’t properly paired to the first/second entry using the approach above so is not closing the correct entry?

      Thankyou

      Comment


        #4
        Hello mr_trade,

        When you mention:
        " the cost averaging of the position is not updated "

        Are you stating that the Position.AveragePrice does not change after the Position.Quantity changes?
        (I'm testing this but so far not able to reproduce. If the position size changes, the unrealized average price changes.)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi chelesa,

          Sorry for the delay, yes the position.averageprice does not change correctly. i can only gather that its because of the FIFO issue.
          If i enter position A @ 100 and then an additional position B @ 110. the average is 105. But when position B is closed, the average price does not update back to 100. and remains hanging, this is through unmanaged. When trying the standard managed approach, the chart trader doesnt update to the correct average price, however under the strategy performance trades i can see the pairs have closed off correctly. Is there a disconnect with the strategy logic and the chart trader position averaging? So they are basically totally different when dealing with scaling in and scaling out?
          How would you suggest to handle this correctly so if had 5 random positions and position 3 is closed first (out of sequence) how does NT cope with this?

          Thankyou

          Comment


            #6
            Hello mr_trade,

            The position of the strategy, updated in OnPositionUpdate, is separate from the account position. Chart Trader will be reflecting the Account position, not the strategy position.

            To confirm, you are using prints in the script in OnPositionUpdate, and the Position.AveragePrice is not changing when the quantity is changing, is this correct? (I would not focus on anything visual and focus on what the strategy is seeing)


            Regarding scaling in and out, below is a simple example made with the strategy builder.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jclose, Today, 09:37 PM
            0 responses
            4 views
            0 likes
            Last Post jclose
            by jclose
             
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            10 responses
            1,413 views
            0 likes
            Last Post Traderontheroad  
            Started by firefoxforum12, Today, 08:53 PM
            0 responses
            10 views
            0 likes
            Last Post firefoxforum12  
            Started by stafe, Today, 08:34 PM
            0 responses
            10 views
            0 likes
            Last Post stafe
            by stafe
             
            Started by sastrades, 01-31-2024, 10:19 PM
            11 responses
            169 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X