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

How can I prevent a strategy from auto disabling after position is closed?

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

    How can I prevent a strategy from auto disabling after position is closed?

    I have created a new strategy and specified AUDUSD as the instrument. The strategy currently closes any open positions that are opened by a human. If I manually open a position on EURUSD, the strategy works fine and closes the position while leaving the strategy enabled. If I then manually open a position on AUDUSD, the instrument the strategy is attached to, the strategy closes the position and then automatically disables itself. In the code I am using the position.Close() method. I would like for the strategy to never automatically disable itself. How can I prevent this? Thank you.

    The log shows a category="Default "and Message="Disabling NinjaScript strategy 'MyStrategy/205101387'

    Right now, the only workaround I can think of is to create a new strategy and specify a different instrument such as "NZDUSD" and then I should be able to close EURUSD & AUDUSD positions without the strategy auto disabling itself. I am hoping there is a better way such as overriding what appears to be default behavior.
    Last edited by RFrosty; 07-03-2020, 01:35 PM.

    #2
    Hello RFrosty,

    Welcome to the NinjaTrader forums!

    A strategy will only become automatically disabled if an error occurs or if the connection is disconnected. Otherwise the strategy will keep running and will not be disabled.

    Are you certain that CloseStrategy() or setting the State is not in the code?

    Do you see any errors appearing on the Log tab of the Control Center when the strategy is disabled?

    Is the connection still connected?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I don't see any errors in the logs and I am not calling CloseStrategy anywhere.

      Comment


        #4
        I have attached the source to validate.
        Attached Files

        Comment


          #5
          Hello RFrosty,

          This strategy doesn't submit any orders. If there are no orders being submitted, I highly doubt this strategy is becoming disabled automatically.

          I ran this myself and it didn't disable. I'll leave it running in real-time for a while, but I highly doubt this strategy will disable as there are no orders being placed.
          https://drive.google.com/file/d/1_-B...w?usp=drivesdk

          Personally, I think what you provided is not the same script you are testing.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            I am manually opening an EURUSD and AUDUSD positions while the strategy is enabled. When I manually open the EURUSD, the Strategy closes the position which is expected. When I manually open the AUDUSD (the instrument the strategy is attached), the position is closed by the strategy as expected but the strategy is then auto disabled. I am expecting the strategy to remain enabled even if all positions are made flat by the strategy.
            Last edited by RFrosty; 07-05-2020, 08:18 PM.

            Comment


              #7
              Hello RFrosty,

              Manual orders are not able to be seen by NinjaScript Strategies.

              Manually clicking the Close button specifically will disable a strategy on the same instrument and account, so don't do this.
              If you want to manually close a position, place an order in the opposite direction and don't click Close.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea,

                My strategy always auto-disables itself after 30 seconds or so.

                The strategy is supposed to auto Exit Manually entered trades, both long trades and short trades, using the unmanaged approach.

                The strategy works without auto-disabling itself when with the Long side code only.

                But it does auto-disable itself when both the long and short sides code is set.

                What I get in the Output Window:

                Enabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Ignore all errors ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=True MaxRestarts=4 in 5 minutes

                Disabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863'

                Enabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition AccountPosition=CL 09-21 1L EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Ignore all errors ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=True MaxRestarts=4 in 5 minutes

                Disabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863'



                Why does it auto-disable itself?

                How to make it not auto-disable itself?

                Here's a demo vid:

                Comment


                  #9
                  Hello Cormick,

                  Does the strategy call CloseStrategy() or SetState() anywhere in the script?

                  Do any errors appear on the Log tab of the Control Center?

                  Can you reproduce this with the SampleMACrossover included with NinjaTrade?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Chelsea,

                    Thanks for the answer.

                    No CloseStrategy() nor SetState() anywhere in the script.

                    The log shows no error (no colored highlighted lines), only regular logging.

                    I'm not sure what you suggest with reproducing with the SampleMACrossover.

                    How would I reproduce it?

                    Do you mean loading the SampleMACrossover on the chart and testing it it executes without auto-disabling itself?

                    Comment


                      #11
                      Hello Cormick,

                      Yes, I mean if you run the SampleMACrossover on a chart does it become disabled?

                      Reduce a copy of your custom script. Remove all logic that is not necessary for reproducing the behavior.

                      For example try removing all logic in OnBarUpdate(). Does the behavior still occur?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chelsea,

                        I did not test the SampleMACrossover.

                        But when I comment out the If() Else If() code from the OnBarUpdate in my strategy
                        (The If() contains the Long side code, and the Else It() the Short side code),
                        The strategy does not auto-disable.

                        I tested commenting out the all the Long side only and placing a long trade, and it does not auto-disable itself in this test.

                        When I comment out only part of the Long Side Only, it auto-disables itself.

                        And when I comment out All the Short side (Else IF ()) only code it does auto-disable itself.



                        A demo vid:
                        https://drive.google.com/file/d/1twi...ew?usp=sharing

                        00:00 - 1:25 = Part of the Long Side code commented out (Short Order)
                        1:28 - 3:25 = All the Long Side code commented out (Long Order)
                        3:25 - 4:04 = All the Short Side code commented out (Long Order)
                        4:05 - 5:45 = Both the Long and the Short Sides code commented out (Long Order)

                        Comment


                          #13
                          Hello Cormick,

                          Testing the SampleMACrossover lets us know if the issue is with NinjaTrader or an issue with your custom logic.

                          It sounds like you have identified the line of code causing the issue. What specific line of code when uncommented causes the behavior?

                          Is the 'if, else if' written correctly and not causing an error with the inner action block logic commented out?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Chelsea,

                            Thanks for pointing the right direction.

                            I'm not finding the cause yet.

                            I'll do more testing tomorrow and be back asap with results.

                            Be well!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by XXtrader, Today, 11:30 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post XXtrader  
                            Started by MarianApalaghiei, Today, 10:49 PM
                            2 responses
                            9 views
                            0 likes
                            Last Post MarianApalaghiei  
                            Started by love2code2trade, Yesterday, 01:45 PM
                            4 responses
                            28 views
                            0 likes
                            Last Post love2code2trade  
                            Started by funk10101, Today, 09:43 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post funk10101  
                            Started by pkefal, 04-11-2024, 07:39 AM
                            11 responses
                            37 views
                            0 likes
                            Last Post jeronymite  
                            Working...
                            X