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 Uregon, Today, 03:44 AM
      0 responses
      2 views
      0 likes
      Last Post Uregon
      by Uregon
       
      Started by CyberNate, 11-17-2020, 08:15 PM
      2 responses
      426 views
      0 likes
      Last Post nurpalgo  
      Started by sdauteuil, 09-23-2021, 10:16 AM
      7 responses
      1,247 views
      0 likes
      Last Post marcus2300  
      Started by sofortune, 05-18-2024, 11:48 AM
      2 responses
      34 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by Zach55, 02-19-2024, 07:22 PM
      2 responses
      67 views
      0 likes
      Last Post lbadisa1  
      Working...
      X