Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X