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 FrancisMorro, Today, 03:24 AM
      0 responses
      1 view
      0 likes
      Last Post FrancisMorro  
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,769 views
      0 likes
      Last Post Leafcutter  
      Started by Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      30 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      943 views
      0 likes
      Last Post spwizard  
      Started by Max238, Today, 01:28 AM
      0 responses
      10 views
      0 likes
      Last Post Max238
      by Max238
       
      Working...
      X