Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How tor ead the account position from strategy

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

    How tor ead the account position from strategy

    Hi:

    My scenario is:
    have 2 strategies (called ST_A and ST_B working simultaneously on the same instrument).

    For timimg reason, ST_A is excuted first and probably I have a position in the market when ST_B wants to fire another order. I don't want 2 positions at the market, just want the second strategy to avoid entering the market again

    Briefly, I just need to read from ST_B if the account position is NOT flat to avoid the EnterLong()
    Something like
    if (Account_is_flat())
    {
    EnterLong();
    }

    Will (Position.MarketPosition == MarketPosition.Flat) do the trick? As far as I tested it, it seems to be startegy position, not account position.

    Thanks!

    #2
    Originally posted by pakricard View Post
    Hi:

    My scenario is:
    have 2 strategies (called ST_A and ST_B working simultaneously on the same instrument).

    For timimg reason, ST_A is excuted first and probably I have a position in the market when ST_B wants to fire another order. I don't want 2 positions at the market, just want the second strategy to avoid entering the market again

    Briefly, I just need to read from ST_B if the account position is NOT flat to avoid the EnterLong()
    Something like
    if (Account_is_flat())
    {
    EnterLong();
    }

    Will (Position.MarketPosition == MarketPosition.Flat) do the trick? As far as I tested it, it seems to be startegy position, not account position.

    Thanks!
    Here is some generic code to query all account positions. It should give you some ideas on how to go about getting or querying data about any and/or all account positions.
    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); //example code. Here is where you will grab what info you want. 
    }
    }
    There are probably other examples if you search the fora.

    Comment


      #3
      Hello pakricard,

      With koganam example you should be able to get any open positions for your account but this method is just not supported since NinjaTrader was designed that each Strategy has its own virtual Position so it is independent of the Account.

      Let us know if you have any further questions.
      JCNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      69 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      42 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      24 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      27 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      54 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X