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

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 Skifree, Yesterday, 01:33 PM
      6 responses
      50 views
      0 likes
      Last Post Skifree
      by Skifree
       
      Started by MJ123, Today, 04:06 PM
      2 responses
      15 views
      0 likes
      Last Post MJ123
      by MJ123
       
      Started by dgutz15, 12-12-2022, 11:50 PM
      4 responses
      63 views
      0 likes
      Last Post drsclaud23  
      Started by xtremel, Today, 08:48 PM
      0 responses
      14 views
      0 likes
      Last Post xtremel
      by xtremel
       
      Started by SilverSurfer1, Today, 08:27 PM
      0 responses
      5 views
      0 likes
      Last Post SilverSurfer1  
      Working...
      X