Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check for open trades

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

    Check for open trades

    I'm trying to find a function for checking if there is a trade open already using a strategy. I would like my strategy to check if there is an open trade before execution, anyone know where I can find this?
    Thanks

    #2
    Hello matt_,

    Thank you for your post.

    You would need to check the position of the account. While this is unsupported in NinjaTrader 7 you can use the following code to check the positions on the account:
    Code:
    foreach (Account acct in Cbi.Globals.Accounts)
    {
    if (acct.Positions != null)
    {
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
    }
    }

    Comment


      #3
      Thank you Patrick

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      60 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      35 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      106 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      185 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      171 views
      0 likes
      Last Post CarlTrading  
      Working...
      X