Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade existance

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

    Trade existance

    Hi, I have an indicator that collects volume data, but I only want to collect this data when in a trade. Is there a way to detect the existence of a trade from within an indicator? thanks

    #2
    Hello FCatan,

    Thanks for your post.

    While this is unsupported code you could accomplish your goal with modifying this code snippet:

    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);
    					}
    				}
    			}

    Comment


      #3
      Originally posted by FCatan View Post
      Hi, I have an indicator that collects volume data, but I only want to collect this data when in a trade. Is there a way to detect the existence of a trade from within an indicator? thanks
      Code:
      if (Position.MarketPosition != MarketPosition.Flat) 
      {
      //you are in a trade. Do as thou wilt.
      }

      Comment


        #4
        Thank you Koganam, but when I run this code I get this message:

        An object reference is required for the non-static field, method, or property 'NinjaTrader.Cbi.Position.MarketPosition.get'

        Comment


          #5
          Originally posted by FCatan View Post
          Thank you Koganam, but when I run this code I get this message:

          An object reference is required for the non-static field, method, or property 'NinjaTrader.Cbi.Position.MarketPosition.get'
          My mistake. You said Indicator. You were talking about being in a position, so my brain pooped and assumed that you were in Strategy land. Indicators cannot natively determine if you are in a position, so the point is moot.

          One can certainly create code so that a specific Strategy works in tandem with a specific Indicator to pass along that information, but that is a rather limiting option..

          There are other deeper approaches to allow an indicator to read a Strategy position. Indeed the code from, NinjaTrader_Paul, in this thread, suitably filtered, could probably get that information.

          There is also an indicator, shared in the Forum, that can read Strategy positions, by querying the Strategy event handlers. You may care to search for it.

          Addendum: This is the indicator of which I spoke. Whereas it was designed to email executions in an account, It does show you how to access Strategy information from an indicator. http://www.ninjatrader.com/support/f...catid=6&id=533
          Last edited by koganam; 09-14-2015, 05:21 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CaptainJack, 05-29-2026, 05:09 AM
          0 responses
          172 views
          0 likes
          Last Post CaptainJack  
          Started by CaptainJack, 05-29-2026, 12:02 AM
          0 responses
          88 views
          0 likes
          Last Post CaptainJack  
          Started by charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          129 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          208 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          185 views
          0 likes
          Last Post CarlTrading  
          Working...
          X