• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position object scope

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

    Position object scope

    When OnBarUpdate fires, what is the scope of the Position object? Can I reference it in custom created procedures? Can you show me how to solve this using Ninjatrader.CBI?

    How would I do this so that my procedure AdjustStopLimit would know the value of that property?

    // Long position
    if (Position.MarketPosition == MarketPosition.Long)
    {
    AdjustStopLimit(Position.MarketPosition);
    }

    // Short position
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    AdjustStopLimit(Position.MarketPosition);
    }

    protected void AdjustStopLimit( ????????? )

    Thanks in advance!
    Last edited by GibbsB613; 03-13-2017, 10:48 PM.

    #2
    Hello GibbsB613, and thank you for your questions.

    Before I get into any specifics, I would like to mention that NinjaTrader.CBI is used much less frequently in NinjaTrader 8 than it has been in NinjaTrader 7. Many methods that were previously only available through this object, including NinjaTrader.CBI.Globals objects, have now been promoted to fully documented and supported methods. As such, rather than demonstrating using NinjaTrader.CBI, I will instead be speaking from the help guide documentation.

    When OnBarUpdate fires, what is the scope of the Position object? Can I reference it in custom created procedures?
    The help guide documentation is now organized into a tree. All objects commonly available to any kind of NinjaScript are in a "Common" section. Position, as shown in the attached image, is a property of Strategy. From its documentation,

    Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/position.htm
    Represents position related information that pertains to an instance of a strategy.

    We see that this is a non-static member of the current strategy. Your strategy instance can use its own Position member however you see fit, and can pass it to other methods. As far as whether this is public, if we attempt to use IntelliSense as shown in the second image, we find that this is a public member of a strategy instance, which can be accessed outside a strategy instance.


    How would I do this so that my procedure AdjustStopLimit would know the value of that property?
    Your method signature would look like this :


    Code:
    
    protected void AdjustStopLimit(Position myPosition)
    Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by frankduc, Today, 08:12 AM
    0 responses
    0 views
    0 likes
    Last Post frankduc  
    Started by jertrade, Today, 08:10 AM
    1 response
    2 views
    0 likes
    Last Post jertrade  
    Started by iq200, Today, 08:05 AM
    0 responses
    1 view
    0 likes
    Last Post iq200
    by iq200
     
    Started by frantic, Today, 06:37 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by bouncetherubble, Yesterday, 06:56 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_ChristopherS  
    Working...
    X