Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy adjusting stop loss using SetStopLoss is causing chart to freeze

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

    #16
    Hello lorem,

    I'm getting this from the log and trace you provided, that you produced on your end.

    From the log you provided:

    2024-05-13 11:33:46:952|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Change submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:016|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Accepted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:040|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Change submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:098|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Accepted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:201|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Change submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:263|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Accepted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:263|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Change submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277.75 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:326|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Accepted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18277.75 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:915|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Change submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18278 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
    2024-05-13 11:33:47:978|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Accepted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18278 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''​

    However, I'm not sure I'm looking at the right order as this order was cancelled by the Chart Trader Close button being clicked.

    That said, it sound like you were able to resolve the issue by modeling the code after the example, is this correct?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      I just edited my strategy to only enter the first stop loss adjustment (when hitting profit target) and make no further adjustments. In other words, at most it is submitting a stop loss on order creation and then updating that stop loss once.
      The freezing error occurred again nonetheless. It doesn't seem to be the subsequent stop loss adjustments that causes the problem, but submitting any stop loss adjustment at all :/

      5.13 log 2: https://drive.google.com/file/d/1Rqd...ew?usp=sharing
      5.13 trace 2: https://drive.google.com/file/d/1cTY...ew?usp=sharing

      So to confirm, the order of events was:
      1) Order submitted and accepted
      2) Initial stop loss is created beneath our entry price
      3) Profit target is hit, stop loss is adjusted once to a higher stop loss price
      4) Chart freezes - Sell STP is orange, price action is frozen, PnL continues to change

      Comment


        #18
        Hello lorem,

        The example I provided you is changing the stop price without any issues, and is working correctly, but your custom script is not, is this correct?
        This would suggest something in the code is causing the behavior.

        However, you have not confirmed what order you wanted me to investigate in the previous log and trace.

        Note, your log and trace contain sensitive information. Please do not post these on the forum. Also, do not post your email, phone number, address, social security, account number, or any other personal information on the forum.


        "Profit target is hit, stop loss is adjusted once to a higher stop loss price"

        Do you have multiple stops and targets?
        If not, if the profit target fills, the stop loss should be cancelled due to OCO. Are you attempting to change an order that has already been filled or cancelled?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Okay, let me explain my strategy a bit better.
          When my "profit target" is hit, that means we have reached a certain amount of profit which triggers my trailing stop loss. It is not a traditional profit target order, I can see now that this was unclear; Sorry for the confusion. In other words, when my trade hits 1pt in profit, the trailing stop loss is initiated and the stop is adjusted whenever profit increases beyond that point. The stop loss that was placed when the order was first created is adjusted using SetStopLoss.

          183957821​ should be the correct order. On your end it looks like you are seeing the stop losses being accepted and changed. On my end, all I saw was a frozen chart. I clicked "Close" manually after restarting NinjaTrader, since the order was still active despite the chart having been frozen.

          Yes, your example was working once modified. I know this suggests that something is wrong with my strategy, but the stop loss adjustment code was literally identical. Additionally, the freeze is still happening even if the stop loss is only modified a single time.

          (I will go back and remove all of my log + trace uploads now, ty. Not sure how else to send them to you without causing a security issue.)

          Comment


            #20
            Hello lorem,

            If you would like our team to look through a log and trace, we are happy to do so and we ask that you email these to our support. For programming NinjaScript related inquiries specifically these can be emailed to scriptingsupport[at]ninjatrader.com.

            But I am taking a look at what you have provided.

            From what I am seeing in the first log you've provided, on line 155, this order 183957821 originated from the example I provided you. Does this mean you are able to reproduce the freezing with the ProfitChaseStopTrailSetMethodsExample?

            From the log:

            The example strategy was working and was disabled and re-enabled.

            2024-05-13 11:32:31:873|1|4|Disabling NinjaScript strategy 'ProfitChaseStopTrailSetMethodsExample/319936538'

            2024-05-13 11:32:37:674|1|4|Enabling NinjaScript strategy 'ProfitChaseStopTrailSetMethodsExample/319936538' : On starting a real-time strategy - StartBehavior=ImmediatelySubmitSynchronizeAccount Position=NQ JUN24 1L, NQ JUN24 1L AccountPosition=NQ JUN24 1L EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes

            The strategy is using Calculate.OnEachTick though this example script only reacts to price changes. I would recommend using Calculate.OnPriceChange for any scripts that are not working with volume, (such as calling the VOL() indicator which does need to update for each tick). This will use less CPU resources if this is causing a performance impact on your machine.

            Using the Immediately Submit Synchronize account setting, the strategy and account position are the same so the stop loss is submitted (and the previous stop loss cancelled).

            2024-05-13 11:32:37:794|1|4|NinjaScript strategy 'ProfitChaseStopTrailSetMethodsExample/319936538' submitting order
            2024-05-13 11:32:37:805|1|32|Order='93593951a517453b8875c3eea 800fae3/[redacted]' Name='Stop loss' New state='Submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18269.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''

            The order is accepted and is working.
            2024-05-13 11:32:37:863|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Accepted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18269.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''

            The order is changed successfully several times (27 times) from 11:32 to 11:33.

            2024-05-13 11:32:39:485|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Change submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18269.75 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''
            ...
            2024-05-13 11:33:47:915|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Change submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18278 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''

            2024-05-13 11:33:47:978|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Accepted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18278 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''​


            The order appeared to be working and updating fine a few seconds before the chart trader close button was pressed.

            2024-05-13 11:33:49:657|1|4|Chart Trader close position

            2024-05-13 11:33:49:665|1|128|Disabled strategy='ProfitChaseStopTrailSetMethodsExample/319936538'
            2024-05-13 11:33:49:664|1|4|Disabling NinjaScript strategy 'ProfitChaseStopTrailSetMethodsExample/319936538'

            And after this the order appears to have been cancelled successfully.

            2024-05-13 11:33:49:673|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Cancel submitted' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18278 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''

            2024-05-13 11:33:49:747|1|32|Order='183957821/[redacted]' Name='Stop loss' New state='Cancelled' Instrument='NQ JUN24' Action='Sell' Limit price=0 Stop price=18278 Quantity=1 Type='Stop Market' Time in force=GTC Oco='NT-00636-363' Filled=0 Fill price=0 Error='No error' Native error=''​

            I am not seeing any evidence that NinjaTrader was shutdown or restarted around this time. (We see startup information such you see at the top of the log file when NinjaTrader is restarted)

            After the chart trader close button order closes the position, cancels any working orders, and disables working strategies I am seeing the ColorGameBasic strategy was enabled and disabled, and then this is the end of the file.

            2024-05-13 11:34:04:096|1|4|Enabling NinjaScript strategy 'ColorGameBasic/319936539' : On starting a real-time strategy - StartBehavior=ImmediatelySubmitSynchronizeAccount EntryHandling=Unique entries EntriesPerDirection=5 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions, ignore order rejections ExitOnSessionClose=True / triggering 120 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes
            2024-05-13 11:34:18:369|1|4|Disabling NinjaScript strategy 'ColorGameBasic/319936539'



            You mentioned you modified the example?
            Does the original unmodified example produce the freezing behavior?​
            If yes, may I confirm that you are not able to reproduce on the Sim101 account and that you are able to reproduce on the Topstep account?
            Further, are you able to place a manual stop order and manually adjust the price of it (on the account you are able to reproduce on, Sim101 preferably if this is able to reproduce)?

            I've tested to make sure the original script runs correctly, and it appears to work without issue using the Calculate.OnPriceChange() setting on the Sim101 account.

            Below is a link to video I've made testing the behavior.



            If the original example does not produce the behavior, can you provide an export of the script that is able to reproduce the behavior?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Okay, I misunderstood where you got that order number from (183957821​). That is not the order in question.

              The strategy you provided worked fine both before and after I modified it to fit my stop loss adjustment code. It works the same way on my end as it did in your video.

              The only strategy that has given me issues is my custom strategy, ColorGameBasic. I was attempting to send you a log and trace for that strategy. Not sure why the file ended the way it did, I thought I grabbed it right after testing with my strategy again.

              Manually placing an order or manually moving the stop loss associated with my strategy's order does not cause the freezing issue; it works just fine.
              However, I am still able to reproduce the issue on my end using my strategy.​
              Last edited by lorem; 05-15-2024, 09:10 AM. Reason: Removed script

              Comment


                #22
                Hello lorem,

                Without a date and time, or OrderID of an affected order I went to the last order in the log.

                To investigate an order, I'll need an OrderID or a date and time to look in the log for behavior.

                I'm not seeing in this log that ColorGameBasic has placed any real-time orders.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Hmm, okay. That's odd. I'll have to wait until the morning when there's enough volume on the live charts to recreate this problem (since it does not happen in Playback at all.) I'll send you an updated log + trace file tomorrow and delete them once you've had a chance to download them on your end.

                  Comment


                    #24
                    Alright, I was able to recreate the problem again this morning.

                    I took one trade on Sim101, that seemed to work fine. That was order 58b10fe07c0d41e598b43db193aaaf97.

                    After that, I took a trade on my Practice account, I saw the freeze issue almost immediately.
                    The associated order numbers seem to be:
                    5c0bbf319a5049879a149ff4ce6f1e7a
                    184507225
                    3026516478824cf99865228515b81c8d
                    184507230 - this seems to be where it got stuck

                    I had to force-close Ninjatrader at this point. After restarting, I recreated the issue once more on the Practice account:
                    4b145252275740478718b191f0a7ea53
                    184512986 - this is where it got stuck again

                    So that's two instances of it getting stuck, and the issue only seems to appear on the live accounts as previously seen(no issues on Sim or Playback)
                    Last edited by lorem; 05-15-2024, 09:04 AM.

                    Comment


                      #25
                      Hello lorem,

                      "I took one trade on Sim101, that seemed to work fine. That was order 58b10fe07c0d41e598b43db193aaaf97.
                      After that, I took a trade on my Practice account, I saw the freeze issue almost immediately."​

                      Just to further confirm, the behavior cannot be reproduced on the Sim101 as you have stated in post # 1?:

                      "This happens on both my Sim101 account and my TopStep live accounts, utilizing the Rithmic R|Trader Pro data connection."

                      I want to double check, the ProfitChaseStopTrailSetMethodsExample on the Practice account is not able to reproduce, is this correct?

                      If you would like log and trace files reviewed, do not post these on the forum, send these to support[at]ninjatrader.com.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Understood, Chelsea. I have sent my log and trace files to that email address for review.

                        To confirm,
                        1) Yes, I previously saw issues on Sim101 but today it seems to be working fine with that account. Alternatively it may require a few stop loss adjustments to cause the issues with that account? All I know is I saw it adjust the stop without issues multiple times today on Sim101, while the very first stop adjustment on Playback immediately caused a freeze.

                        2) Yes, ProfitChaseStopTrailSetMethodsExample was fine even though I had copied my trade logic over. My current strategy is managing the stop losses in the *exact same way* that ProfitChaseStopTrailSetMethodsExample was after my adjustment, so the discrepancy is odd.

                        3) I have sent in my logs for review, and added two more instances of log + trace after repeating the issue yet again. You should be able to directly compare how NinjaTrader is responding with my Sim101 trades vs. my Live trades.

                        Comment


                          #27
                          I replied via email, but I am pasting my response here as well since my responses weren't coming through last time I tried to contact y'all via email -

                          I'm so sorry, I misspoke on that forum post - I meant to say first stop adjustment on Live* immediately caused a freeze. Please forgive the confusion.
                          This issue has never appeared on Playback, only on my Live accounts. I've attached my custom strategy here as requested.

                          > Use this as the basis for your custom script (make a copy with the desired name and change the entry logic).

                          That's what I'll be doing if we can't find a solution - I have no choice but to remake the strategy from scratch and hope that the issue doesn't reappear.​
                          Attached Files

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Yesterday, 05:17 AM
                          0 responses
                          56 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          132 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          73 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          45 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          49 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X