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

what variables to determine if my account has open position?

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

    what variables to determine if my account has open position?

    Hi There,
    I am working on a custom indicator using the sendmail functionality and I am trying to have ninjatrader automatically e-mail out the details of a trade on order execution. So for example when I enter a trade it will e-mail out a message saying " long 100 shares xyz at $50 ". Now i have this part working fine with no problems.

    But what I want to have happen is once I have a position, say a long position, and I go to sell that position, instead of the e-mail sending out "short 100 shares of xyz at 50" i want it to say "closing position: sold long at 50". So in other words I need to implement logic for it to check whether or not I have a current position. I have tried a handful of different things, currently the code is as follows, but doesn't assign correctly. Any thoughts on what variables (account/position/etc) I should use to implement this logic?

    Thanks!

    foreach (Account acct in Cbi.Globals.Accounts)
    {
    if (acct.Positions[0].MarketPosition != MarketPosition.Flat)
    {
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    if (e.Execution.MarketPosition == MarketPosition.Long)
    action = "NEW POSITION: Long";
    else action = "NEW POSITION: Sold Short";
    }
    }
    else
    {
    if (e.Execution.MarketPosition == MarketPosition.Long)
    action = "POSITION CLOSED: Covered Short";
    else action = "POSITION CLOSED: Sold Long";
    }
    }

    #2
    Hello,

    Thanks for the post. Unfortunately the code you have provided is not supported or documented, and as a result we cannot gurantee the function of these methods. While it is technically possible to obtain the account position information through the ninjatrader core as other users have demonstrated, we will not be able to comment on how to use these functions.

    We will leave this thread open for other users who have experience in this area to assist. Best of luck in your project development.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by slocumtrader View Post
      Hi There,
      I am working on a custom indicator using the sendmail functionality and I am trying to have ninjatrader automatically e-mail out the details of a trade on order execution. So for example when I enter a trade it will e-mail out a message saying " long 100 shares xyz at $50 ". Now i have this part working fine with no problems.

      But what I want to have happen is once I have a position, say a long position, and I go to sell that position, instead of the e-mail sending out "short 100 shares of xyz at 50" i want it to say "closing position: sold long at 50". So in other words I need to implement logic for it to check whether or not I have a current position. I have tried a handful of different things, currently the code is as follows, but doesn't assign correctly. Any thoughts on what variables (account/position/etc) I should use to implement this logic?

      Thanks!

      foreach (Account acct in Cbi.Globals.Accounts)
      {
      if (acct.Positions[0].MarketPosition != MarketPosition.Flat)
      {
      PositionCollection positions = acct.Positions;
      foreach (Position pos in positions)
      {
      if (e.Execution.MarketPosition == MarketPosition.Long)
      action = "NEW POSITION: Long";
      else action = "NEW POSITION: Sold Short";
      }
      }
      else
      {
      if (e.Execution.MarketPosition == MarketPosition.Long)
      action = "POSITION CLOSED: Covered Short";
      else action = "POSITION CLOSED: Sold Long";
      }
      }
      I am not sure why you are using such a complex method to query what is already provided. Just use the OrderAction to tell you what action was taken, and use the OnPositionUpdate() event handler to tell you the remaining position.

      ref: http://www.ninjatrader.com/support/f...ad.php?t=60274

      Comment


        #4
        koganam suggestion would be correct. A much simpler approach would be to watch the strategy position in OnPositionUpdate. As long as your account is not in other positions on the same instrument, the supported methods should help accomplish what you're looking for.
        MatthewNinjaTrader Product Management

        Comment


          #5
          I should have been more clear, there isn't a strategy running, this is for discretionary trading where I am trying to use this indicator overlayed on my charts. Do i still have access to those account/position variables even though there is no strategy at work?

          Comment


            #6
            There is not a supported method for obtaining this information for manual trades.
            MatthewNinjaTrader Product Management

            Comment


              #7
              koganam any thoughts on accomplishing this without a strategy, this is purely an indicator designed for discretionary fashion. Thanks!

              Comment


                #8
                Originally posted by slocumtrader View Post
                koganam any thoughts on accomplishing this without a strategy, this is purely an indicator designed for discretionary fashion. Thanks!
                Most of the properties and methods that your code is trying to access are not even available in the Indicator class. It may be possible to cobble something together, but it will take a pretty deep hack into the NinjaTrader code base. It is, unfortunately, something that I would not try to undertake.
                Last edited by koganam; 08-13-2013, 07:21 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Barry Milan, Yesterday, 10:35 PM
                5 responses
                16 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Started by DJ888, 04-16-2024, 06:09 PM
                4 responses
                13 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by terofs, Today, 04:18 PM
                0 responses
                12 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by nandhumca, Today, 03:41 PM
                0 responses
                8 views
                0 likes
                Last Post nandhumca  
                Working...
                X