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

Stop price of previous trade is being used despite being reset when flat

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

    Stop price of previous trade is being used despite being reset when flat

    It is suggested to call this method from within the strategy OnStateChange() method if your stop loss price/offset is static

    •You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position

    •Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position
    Because my stop size is dynamic I need to reset my stop price to zero when flat.

    Despite resetting it to zero it's still using the stop price of the previous trade when testing in market replay.

    I even print out the value that SetStopLoss() is using on the line immediately prior to the line SetStopLoss() is and the value that is being printed is correct, while the value that shows up in the error message and in the log shows that the value is from the previous trade.

    I'm not sure what to do here does anyone have any pointers??

    Edit:
    This is a crazy update. I'm currently looking at a session that I actually traded live using a previous version of this strategy. Live it handled it no problem. In market replay I went back and replayed it with both the current version and the version I used to trade it live and both times I got this situation I described in this post. Weird that it would happen in market replay but not in real life.
    Last edited by WalterSkinner; 01-23-2022, 03:37 PM.

    #2
    Hello WalterSkinner,

    Set methods cannot be unset. This means call Set methods with CalculationMode.Ticks when flat, and before calling a new entry.

    Below is a working example you can use to model your code after.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you so much for this.

      I'm going to have to do some serious re-adjusting it looks like this is the first time I've heard of this.

      I'm surprised it's this complex to get something as simple as a stop to function normally.

      Am I making this way more complex than it needs to be or is that just the nature of the platform?

      Comment


        #4
        Hello WalterSkinner,

        It depends on what you are trying to use the tools for.

        With set methods, the Strategy Builder sets these once in State.Configure and never sets them again. Its somewhat of a set it and forget it model. So easy use but comes with limitations in that you cannot adjust the set or set this to price information from the data.

        The more complex the action, the more complex the code.

        The examples I have provided come in many forms so you can find what is suitable for you and your needs.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello WalterSkinner,

          It depends on what you are trying to use the tools for.

          With set methods, the Strategy Builder sets these once in State.Configure and never sets them again. Its somewhat of a set it and forget it model. So easy use but comes with limitations in that you cannot adjust the set or set this to price information from the data.

          The more complex the action, the more complex the code.

          The examples I have provided come in many forms so you can find what is suitable for you and your needs.
          I see.

          I'm using WPF buttons to get into trades so the strategy can handle trade management for me.

          At the moment the strategy scales out, trails out, and exits based on time of day.

          Based on this it seems like I may want to go with Exit Orders - I believe this is how you guys refer to ExitLongStopMarket() and ExitShortStopMarket(). Does that seem about right?

          Comment


            #6
            Hello WalterSkinner,

            Yes, you would likely want to use exit orders like ExitLongStopMarket().

            Below is a link to an example of submitting orders from WPF buttons.
            I need some guidance. I need to create a script that has 3 plots that are public and they plot either a 1 or 0. But I need to create another indicator that has 3 chart buttons that sets these variables. The first indicator needs to get those values from the second indicator depending on the button clicks. Because of using
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_ChelseaB you are a legend and I cannot thank you enough. I am so grateful for these.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,605 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              8 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              4 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              13 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X