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

Exit Condition based on Position.Average Price and Close Price isn't working

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

    Exit Condition based on Position.Average Price and Close Price isn't working

    Hi all, can someone please help with probably a very simple question below?

    I am creating a very simple condition in Strategy Builder to exit my Short position:

    Default input[0]>(Position.AveragePrice*StopLossFactor); where StopLossFactor is a User Input and I have it set at 1.01

    Despite this condition, my strategy exits at some random number. I tried to troubleshoot by isolating a period of time in question. I then made the strategy put Fixed String on the chart to see if any of the variables mismatch.

    When Set 1 (entry into position) executes, I get the following string printed on the screen: "121.52-123.9504-130.25" that can be read as "Average Posiition Price = 121.52, Average Position Price * StopLossFactor = 123.95; Close Price = 130.25". The latter doesn't make sense since Price close on that bar is way below 122.00.

    I also make sure that when I have a position, Set 1 doen'st get executed again by using a Boolean on position open and position close.

    Thanks a bunch!

    #2
    Hello Serge A,

    Thanks for your post and welcome to the NinjaTrader forums!

    Can you provide a screenshot of the set with the exit order and one of the entry order set?

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for your response. Here they are.
      Attached Files

      Comment


        #4
        And here is the StopLoss group
        Attached Files

        Comment


          #5
          Hello Serge A,

          Thanks for your posts.

          The observations are that you are using market order to exit so "my strategy exits at some random number." would be a possible cause/contributor of this.

          In the entry conditions your code is placing the order and then immediately printing Position.AveragePrice which may not be valid because it takes more time to fill (a live or replay) order than is does for your code to execute. I recommend that you create another set where if the MarketPosition is short to then print out the position.AveragePrice and your calculations based on that.

          Here is a link to a short video that shows how to construct a "Print" statement to print out bar by bar the value of your variables, bools, and Position.AveragePrice. (and anything else you wish). The output goes to New>Ninjascript output window. https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thank you so much for your ideas! I will test them out and get back to you if I have a follow-up concern.

            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