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

Order entry time / multiple strategies

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

    Order entry time / multiple strategies

    I am attempting to run multiple strategies at once, and my desire is that only one of them can be active at one time. I've tried something like this:

    Code:
    foreach (var order in Account.Orders)
    
    {[INDENT]if (order.OrderState == OrderState.Working && !order.GetOwnerStrategy().Equals(this))
    
    {[/INDENT][INDENT=2]sb.Append("Other orders are in, doing nothing. ");
    
    return;[/INDENT][INDENT]
    }[/INDENT]
     
    }
    This works most of the time; however, I've encountered a race condition where two strategies put in orders at the same time and I end up with a double position. This happens when two charts finish a bar simultaneously. I tried locking on the account:

    Code:
    lock (Account) { // strategy logic }
    ...but this doesn't seem to do anything. My conclusion is that it takes a significant amount of time for the order to reach the server and be confirmed in the account; within that timeframe the second strategy has already placed a duplicate order.

    Is my assumption correct? Does it make sense to investigate a more complicated locking approach? Thanks!

    P.S. Typing this out prompted me to look at the possible values of OrderState... maybe checking for Submitted will be enough??

    #2
    Hello aworldnervelink,

    You most likely have the correct understanding.

    It does take time for orders to go from Initialized, to Submitted, to Accepted, to Working.


    You may try looking for all of these states instead of just Working.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by serman, Yesterday, 09:47 AM
    4 responses
    20 views
    0 likes
    Last Post serman
    by serman
     
    Started by DayTradingDEMON, 07-11-2024, 08:54 AM
    21 responses
    68 views
    0 likes
    Last Post DayTradingDEMON  
    Started by Clevchin, Today, 12:57 PM
    3 responses
    9 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by samish18, Today, 03:48 AM
    9 responses
    17 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by rtwave, 06-13-2024, 12:10 AM
    9 responses
    94 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X