Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

All Open Positions

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

    All Open Positions

    Hi there, I am trying to find out if there is a way to find all OPEN POSITIONS across all strategies and accounts.
    I am trying to use the following code and it doesnot work .
    Thanks
    BJ

    int buy_counter = 0;
    int sell_counter = 0;
    for (int i=0; Account.Positions.Count;i++)
    {
    if(Account.Positions[i].MarketPosition != MarketPosition.Flat)
    {
    if(Account.Positions[i].MarketPosition == MarketPositon.Long)
    buy_counter++;
    if(Account.Positions[i].MarketPosition == MarketPositon.Short)
    sell_counter++;
    }
    }
    Print("Total Open Long :" + buy_counter + "\n");
    Print("Total Open Short :" + sell_counter + "\n");

    #2
    Hello Braji,

    Thank you for your post and welcome to the forums!

    I would not expect to get the other accounts information this way.

    You would need to query all the accounts in the database that you are connected to in order to get any information for them. This is unsupported programming with NinjaTrader but here is a link to get you started on something -
    http://www.ninjatrader.com/support/f...ad.php?t=55718

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks @NinjaTrader_Cal

      That worked...
      Awesome.

      Comment


        #4
        Originally posted by braji View Post
        Thanks @NinjaTrader_Cal

        That worked...
        Awesome.
        @braji,

        Would you mind to share the final solution?
        Future viewers/readers would thank you too.
        Last edited by Mr.Trader; 04-02-2015, 02:41 PM. Reason: add info

        Comment


          #5
          Unrealized P&L

          Hi Cal,

          In addition to what you've indicated about getting information on all open positions (even on different accounts) by the referenced code, one other thing which I'm trying to do is the collected Unrealized P&L from all open positions.
          It is pretty much straightforward to accomplish such things when your own strategy is running and collecting its own data. It's quite different though when you try to calculate P&L from open positions which are running under different instruments on separate charts.

          The following code attempts to achieve such task, nevertheless with no success.
          It could be that GetProfiLoss() method does not work for SIM101 or there's something else I'm missing. The fact is that I can't get the P&L data for each open position.
          Any help or recommendations will be greatly appreciated.

          foreach (Account acct in Cbi.Globals.Accounts)
          {
          //Realized
          Print (
          "Account => " + acct.Name +
          " Realized Profit Loss: " + GetAccountValue(AccountItem.RealizedProfitLoss) +
          " CashValue: " + GetAccountValue(AccountItem.CashValue) +
          " Used Margin: " + GetAccountValue(AccountItem.InitialMargin)
          );
          RealizedPNL = GetAccountValue(AccountItem.CashValue) +
          GetAccountValue(AccountItem.InitialMargin) +
          GetAccountValue(AccountItem.RealizedProfitLoss);
          Print("Current Equity = " + RealizedPNL.ToString());

          // Unrealized
          if (acct.Positions != null)
          {
          UnRealizedPNL = 0;
          PositionCollection positions = acct.Positions;
          foreach (Position pos in positions)
          {
          UnRealizedPNL = UnRealizedPNL + pos.GetProfitLoss(pos.AvgPrice, PerformanceUnit.Currency);
          Print (
          pos.GetProfitLoss(pos.AvgPrice, PerformanceUnit.Currency).ToString() +
          " " +
          pos.Account.Name +
          " " +
          pos.Instrument +
          " " +
          acct.Strategies.Count.ToString() +
          " " +
          pos.MarketPosition.GetTypeCode() +
          " " +
          pos.Quantity.ToString() +
          " " +
          pos.AvgPrice.ToString()
          );
          }
          Print ("Total Unrealized PNL = " + UnRealizedPNL.ToString());
          }
          }


          Thanks,

          Comment


            #6
            herval,

            GetProfitLoss() needs to have a double for the price that you want to compare the Entry price to. If you tell it to compare it against the AvgPrice there may not be much of a difference if any.

            Try using Close[0] instead.

            GetProfitLoss(Close[0], PerformanceUnit.Currency);

            http://www.ninjatrader.com/support/h...profitloss.htm
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Thanks !!!

              Thanks for your help Cal !!!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              40 views
              0 likes
              Last Post jeronymite  
              Started by bill2023, Today, 08:51 AM
              2 responses
              16 views
              0 likes
              Last Post bill2023  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              167 responses
              2,260 views
              0 likes
              Last Post jeronymite  
              Started by warreng86, 11-10-2020, 02:04 PM
              7 responses
              1,362 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by Perr0Grande, Today, 08:16 PM
              0 responses
              5 views
              0 likes
              Last Post Perr0Grande  
              Working...
              X