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

Enagled not set false after close position via SL or TP order in atm strategy

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

    Enagled not set false after close position via SL or TP order in atm strategy

    1. I run the strategy by setting enabled = true
    2. automatic stop order or take proffit order triggered
    3. property enabled = true after position is closed

    why?
    I think that the enabled property should be false after the automatic orders are triggered ...

    ** i see that Enabled = true when i click right mouse button on chart and check "Strategies"
    (in "General" table)

    thanks!

    #2
    Hello Solo_fk,

    Welcome to the NinjaTrader support forum.

    Yes, this would be correct for a NinjaScript strategy even if it uses ATM strategies. A Strategy should not disable after closing a position, it should keep running and continue executing your logic.

    If you need the strategy to stop after a position is closed, you would need to do that using the strategies logic or prevent it from trading further.

    We have the following example that shows some ways to stop a strategy after a condition is met: https://ninjatrader.com/support/foru...ad.php?t=19289

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I understand, thank you very much

      Comment


        #4
        Hi, Jesse
        one more question, see: the same situation:
        1. I run the strategy by setting enabled = true (ok)
        2. automatic stop order or take proffit order triggered (ok)
        3. position is closed (ok)
        4. My strategy is still working (ok)
        5. The new position can be opened by the same logic condition as previous position (because there is no open position at the moment) (correctly?)
        6. the new position does not open and line Print("something") in OnBarUpdate section is not printed when a new bar is formed (stragegy enabled = true, it's working)

        question:
        Do I understand correctly that the OnBarUpdate block stops working after closing the position and that something needs to be done in the code to activate it again?

        thanks!

        Comment


          #5
          Hello Solo_fk,

          I'm responding on behalf of Jesse who is out of the office.

          Do I understand correctly that the OnBarUpdate block stops working after closing the position and that something needs to be done in the code to activate it again?
          No, OnBarUpdate() will iterate when the strategy is enabled and will process any logic within that method. It does not automatically disable. You will need to add you own logic to limit your trading actions if that is what you are after.

          For item 5, this is correct.

          For item 6, you should add prints outside of the conditions written that tell you the values used to evaluate the condition. This way, so you can see the values that allow the conditions to become true. If an order method isn't firing, the logic should tell the tale on why that code was not reached.

          Please let me know if you have any additional questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            other small question :

            Why in the Strategies tab I have two strategies,
            although the chart with strategy in my workspace is only one?
            Is it normal?

            ( https://gyazo.com/d0f43602c3f5272d1369fdbb6da67f97 )

            thanks!

            Comment


              #7
              Hello Solo_fk,

              The Control Center will list all active and stopped NinjaScript Strategies. A chart will show an instance of a NinjaScript strategy if it has been added to it. Without full view of the Strategies tab of the Control Center, I cannot specify if you have added two instances on the same account, or on separate accounts. But it does show 2 inactive instances.

              I've included a link to our documentation on the Strategies tab for more information - https://ninjatrader.com/support/help...egies_tab2.htm

              Please let us know if you have any additional questions.
              JimNinjaTrader Customer Service

              Comment


                #8
                thanks, Jim
                I realized that:
                1. two strategies in the list most likely I had because of the fact that I used both Sim101 and MarketReplay connections
                2. the Print() did not go into OnBarUpdate because in OpPositionUpdate() I had a line
                if (this.Enabled) this.Enabled = false;

                Comment


                  #9
                  One more question:

                  1. In my strategy template stoploss = 20 tick (ok)
                  2. In OnPositionUpdate() block i change stoploss to 40 tick using this line (ok)

                  AtmStrategyChangeStopTarget(0, GetAtmStrategyPositionAveragePrice(atmStrategyId) - 40 * TickSize, "STOP1", atmStrategyId);

                  3. the first time the stop loss changes successfully after the position is opened (was changed to 40 tick) (ok)
                  4. automatic stop order or take proffit order triggered (ok)
                  5. the strategy continues to work (ok)
                  6. the same logic opens the second position after the first was closed (ok)
                  7. stoploss = 20 tick, OnPositionUpdate () does not work when the position is opened a second time and the stoploss remains set to 20, as stated in the strategy template

                  Why OnPositionUpdate does not work when opening the next position after the first one was closed on the stoploss or takeproffit order?

                  thanks!
                  Last edited by Solo_fk; 03-06-2018, 09:32 PM.

                  Comment


                    #10
                    Hello Solo_fk,

                    Thanks for your question.

                    Why OnPositionUpdate does not work when opening the next position after the first one was closed on the stoploss or takeproffit order?
                    NinjaScript strategies that invoke ATM strategies do not own the ATM strategy. This means that OnPositionUpdate() OnOrderUpdate() or OnExecutionUpdate() events as well as strategy performance will not be seen for ATM strategies in NinjaScripts.

                    Please see the publicly available documentation on Using ATM strategies for more information on what can and can't be done with ATM strategies in NinjaScript.

                    Using ATM strategies - https://ninjatrader.com/support/help...strategies.htm

                    Please let us know if there is anything else we can do to provide assistance.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Jim, thx for your answer,

                      NinjaScript strategies that invoke ATM strategies do not own the ATM strategy
                      Why then worked the first stop loss correction? (from 20 to 40 tick)

                      thanks!

                      Comment


                        #12
                        Hello Solo_fk,

                        Without the complete code and testing, I could not say why your strategy behaved the way it did. I may suspect other order methods being used that the Strategy does own, but I cannot say without reviewing the code fully.

                        Debugging client code exceeds the scope of services we may provide, but I have provided a video demonstration of the expected behavior and have provided a modified version of the SampleAtmStrategy example that is included with NinjaTrader to demonstrate the expected behavior.

                        You may use this test on your end to further look into the behavior with your strategy.

                        Demo: https://www.screencast.com/t/kwcyE8GN

                        If you are seeing something different, please let me know.
                        Attached Files
                        JimNinjaTrader Customer Service

                        Comment


                          #13
                          Hello Jim,

                          I found a list of typical solutions for strategies and indicators:


                          I would like to ask if this is a complete list or is there still?

                          thx!

                          Comment


                            #14
                            Hello Solo_fk,

                            The link you have provided is to the Reference Samples Forum which provides working examples to show how something can be accomplished with NinjaScripts. They can also be used as a basis for your works.

                            The Development Tips forum is similar to an FAQ where solutions, advise on troubleshooting, or best practices can be referenced. These tips are to address the most common issues that users face when developing NinjaScripts. There are many less common items that are not included in that forum.

                            For the thread's reference, I've included direct links to these forums below.

                            Reference Samples - https://ninjatrader.com/support/foru...aysprune=&f=30

                            Development Tips - http://ninjatrader.com/support/forum...splay.php?f=31

                            If you have any additional questions, please don't hesitate to ask.
                            JimNinjaTrader Customer Service

                            Comment


                              #15
                              Hello Jim,
                              thank for your answers

                              I've got one more question:

                              1. I'm trying to use strategy this strategy - SampleHaltBasicStrategy (from here - https://ninjatrader.com/support/foru...ead.php?t=4804) (ok)
                              2. I work in the market replay mode (account Replay101) (ok)
                              3. I added a strategy to the chart, included its property Enable = true (ok)
                              4. property Performance.AllTrades.TradesPerformance.Currency.C umProfit = -412
                              5. why is not it = 0? because not a single position is open, testing is just started ..
                              6. ** I tried to reset the history with these actions - Tools -> Options -> simulator -> reset -> check Replay101 account and clear history - The result is the same, Performance.AllTrades.TradesPerformance.Currency.C umProfit = -412, not zero

                              that is, the result of all previous trades is displayed, without discarding it with a new test
                              I think that something I do not understand or something has not dropped yet

                              why?

                              thx!

                              hmmm ... look:
                              *** the account Replay101 was reset after the NT7 was restarted (may be disconnect ->connect would work too ..) is restart important after reset?

                              reset occurred only once (after restart NT7), I saw the correct profit number = 137

                              After I moved the time on the chart back (for about an hour to make a new replay), the profit again became = -412
                              very interesting ...

                              (I use debug in Visual Studio and i see Performance.AllTrades.TradesPerformance.Currency.C umProfit by my breakpoint in OnBarUpdate, debug is OK)

                              thx!
                              Last edited by Solo_fk; 04-09-2018, 09:03 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TheMarlin801, 10-13-2020, 01:40 AM
                              20 responses
                              3,913 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by timmbbo, 07-05-2023, 10:21 PM
                              3 responses
                              150 views
                              0 likes
                              Last Post grayfrog  
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              30 responses
                              804 views
                              1 like
                              Last Post grayfrog  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Johnny Santiago, 10-11-2019, 09:21 AM
                              95 responses
                              6,194 views
                              0 likes
                              Last Post xiinteractive  
                              Working...
                              X