Announcement

Collapse
No announcement yet.

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?

    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

          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 NullPointStrategies, Today, 05:17 AM
            0 responses
            43 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            65 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X