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 FrazMann, Today, 11:21 AM
    0 responses
    1 view
    0 likes
    Last Post FrazMann  
    Started by geddyisodin, Yesterday, 05:20 AM
    8 responses
    51 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    10 responses
    36 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by DayTradingDEMON, Today, 09:28 AM
    4 responses
    24 views
    0 likes
    Last Post DayTradingDEMON  
    Started by George21, Today, 10:07 AM
    1 response
    18 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Working...
    X