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

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);
    					}
    				}
    			}
    Paul H.NinjaTrader Customer Service

    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 andrewtrades, Today, 04:57 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X