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

Strategy Position Flat

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

    Strategy Position Flat

    I have been running a live strategy for week or so and I think I noticed a bug I have been having. I run the same strategy on 3-5 different instruments. In my main "order entry" code, I only want to submit an order if the market position == flat for the instrument that I am running the strategy on. I dont mind having multiple positions on, just not multiple positions in the same instrument. Currently I have been using the code

    PHP Code:
        if( Position.MarketPosition != MarketPosition.Flat)
        return; 
    But this code, I think has been stopping me from submitting orders when I have a position in another instrument, which is not what I want. . Is there a way I can determine if there is a position on in the strategy on each different instrument or do I have to make a bool somewhere in my code to keep track of this stuff

    Thanks

    #2
    Hello eurostoxx trader,

    Market position only applies to the strategy instance that accesses it. Also, this property makes no distinction between a historical(virtual) strategy position and a real time strategy position.

    You can print it to verify its value: Print(Position.MarketPosition.ToString());


    I don't see any advantages to the snippet you posted. If you return out of OnBarUpdate anytime you're in a position, then you've effectively prevented any exit management by the strategy.
    Last edited by NinjaTrader_RyanM1; 12-01-2011, 11:26 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the information. Perhaps I have a bug somewhere else in the code.

      I only return out of the script if I am in a position in my "Order Entry" method.. not always.

      I will use the print to see where things arent working. Perhaps I had a virtual position, because a few times when I initially connected to my data provider, I had some wierd orders go through that didnt meet any of my entry criteria.

      Comment


        #4
        OK, it makes more sense if it's limited only to your entry section. Thanks for the reply. The strategy should not be getting position information from any other strategy instances and this would indeed be a bug. I would hint at virtual position being the most likely, but please let us know if you're not able to track it down. While this does concern multiple strategy instances, it's always best if you can evaluate a strategy one instance at a time to confirm behavior.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by alifarahani, Today, 09:40 AM
        6 responses
        25 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Waxavi, Today, 02:00 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by gentlebenthebear, Today, 01:30 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X