• 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

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 asmmbillah, Today, 02:23 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by steveg, Today, 02:44 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Heath  
            Started by BatBart, Today, 01:24 PM
            1 response
            12 views
            0 likes
            Last Post Jonsey529  
            Started by lightsun47, Today, 12:33 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by Woomera, Today, 12:21 PM
            2 responses
            9 views
            0 likes
            Last Post Woomera
            by Woomera
             
            Working...
            X