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

Looping through strategy Open Orders (not realtime open orders)

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

    Looping through strategy Open Orders (not realtime open orders)

    For reasons that are not relevant to the example, my account will enter orders with a label (Name) as such:

    B-1 | 0.12
    B-2 | 0.33
    B-2 | 0.10
    B-1 | 0.03
    B-1 | 0.22
    B-1 | 0.15

    If a certain condition is met, for example Close[0] > EMA(9)[0] I want to ExitLong on all the B-1**** for example.

    I got as far as this code:

    OnBarUpdate() ....
    if (condition) {
    foreach (Order order in Account.Orders){

    Print("\n\nORDER NAME: " + order.Name);
    if (order.Name.Contains("B-1") ) {
    ExitLong(order.Name);
    }
    }
    .......

    I only get over and over:
    ORDER NAME: B-1 | 0.12

    Just as I finished typing this I had a hunch and went to look into my accounts tab and I see that there is a rejected order in there called B-1 | 0.12! So obviously this is what I am looping through but for backtesting purposes, I'd need to be able to get the "open orders on each bar update rather than realtime" hope this is making sense.

    So, the question is with the Lifetime license: How can I program my strategy to ExitLong("B-1*") on each tick or bar update but leave open all B-2*, B-3*, A^, etc, etc ...if you know what I mean? I need to access the strategy order list and NOT the "current" orders.

    Any help on this would be extremely appreciated and if you could provide a complete working example I'd be forever grateful!
    Last edited by focus333; 12-03-2020, 12:36 AM.

    #2
    Hello focus333,

    Thank you for the post.

    If you are referring to an order which was submitted in historical processing the strategy will only be aware of the order by the order events from OnOrderUpdate or OnExecutionUpdate. If the order was submitted in realtime while the strategy is running it will see the order in the Account.Orders collection as well because that is now a real order. The Orders collection will otherwise not contain historical orders that were submitted in the strategies backtest, those are not part of the Account.



    So, the question is with the Lifetime license: How can I program my strategy to ExitLong("B-1*") on each tick or bar update but leave open all B-2*, B-3*, A^, etc, etc ...if you know what I mean? I need to access the strategy order list and NOT the "current" orders.
    The ExitLong command will exit whatever FromEntrySignal name you pass it. if B-1 was the signal name for the entry then this exit would exit that part of the position. This would be how you scale in or out using the managed appraoch, you can use multiple signal names to create multiple parts to an overall position.



    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    6 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    9 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    20 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X