Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop losses for multiple entries

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

    Stop losses for multiple entries

    Hi all,

    First post here, and just want to say a big thank you to the dev team for NinjaTrader. Now onto my question. Right now I have a strategy whereby upto 3 positions can be opened at once.

    I've set it up to open positions and it working fine. The problem area is to do with the stop losses based on the ATR. So far I have this, one setup for each long position entered, (I've named EnterLong, Enterlong2...).

    if (Close[0] < (Position.AvgPrice - (2*ATR(...)))
    && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong("", "EnterLong");
    }

    if (Close[0] < (Position.AvgPrice - (2*ATR(...)))
    && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong("", "EnterLong2");
    }

    etc.

    The problem I have is with the Position.AvgPrice part. If I have one position open this is ok, as the average price will obviously be the opening price. However if I open the three positions then the stop is going to be based on the average price, rather than the price of the last / highest priced order entry, which is what I want. So ideally what I would like is something like:

    if (Close[0] < (EnterLong2 Entry Price - (2*ATR(...)))
    && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong("", "EnterLong2");
    }

    Any ideas?

    EDIT: Sorry, another bit to add. Having thought about it would also be handy if I was able to take the ATR value of the first trade and lock that value in using a variable. Thanks.
    Last edited by milzay; 12-08-2009, 02:34 PM.

    #2
    milzay,

    If you need per trade information you would be better served using IOrder objects to get the information out in relation to each individual order placed.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi again, I've looked into the IOrder function and tbh I'm pretty confused by it. I'm confused how to use it, I'm confused how to change my script so each order can pass on its 'enter price'? Well, as you can see, I'm just confused. I know the admins only have time to give guidelines, so can probably not expand any further, however if there are any helpful members out there, any help would be greatly appreciated. Thanks.

      Comment


        #4
        The idea is you have 3 entry orders so you create yourself 3 IOrders.

        Code:
        private IOrder entry1 = null;
        private IOrder entry2 = null;
        private IOrder entry3 = null;
        Then you can make your entry orders like this for example:

        Code:
        entry1 = EnterLong();
        entry2 = EnterLong();
        entry3 = EnterLong();
        Then when you want to get the entry price for entry1 you can do this:

        Code:
        if (entry1 != null)
            entry1Price = entry1.AvgFillPrice;
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hey Josh,

          Thanks for the advice worked a treat, should have perservered was pretty much there, I guess that's the way of coding.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          656 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          371 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          579 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X