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

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:
    [FONT=Courier New]
    protected void AdjustStopLimit(Position myPosition)[/FONT]
    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 junkone, Today, 11:37 AM
    0 responses
    2 views
    0 likes
    Last Post junkone
    by junkone
     
    Started by quantismo, 04-17-2024, 05:13 PM
    5 responses
    34 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by proptrade13, Today, 11:06 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    34 views
    0 likes
    Last Post love2code2trade  
    Started by cls71, Today, 04:45 AM
    2 responses
    10 views
    0 likes
    Last Post eDanny
    by eDanny
     
    Working...
    X