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

Running code when a strategy is shut down by the user

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

    Running code when a strategy is shut down by the user

    Hi, I would like to run some code when the custom strategy is shut down by the user.
    • Strategy is removed from chart
    • Connection is lost
    • etc
    What's the best way to catch this occurrence?
    Thank you!!
    Ben

    #2
    Ben,

    Please see the OnConnectionStatus() method. If you remove a strategy there is no more processing of any logic.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh,
      I had noticed that method, which will certainly work when the user disconnects the strategy, or the connection fails.
      Will it also help when the user manually removes the strategy from the chart?
      cheers / Ben

      Comment


        #4
        It's not that I want to do any more trading logic at this time ... I want to shut down another thread that I have running ... a user's control panel inheriting from System.Windows.Form.

        When the strategy closes, the form stays open, and I want to catch the strategy closing so I can close the form.

        cheers / Ben

        Comment


          #5
          No. If you wanted to halt your strategy see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=4804

          It does not remove the strategy. It just negates all logic.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            What you want is not supported.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              ok, thanks anyway ...

              I am currently making the controlpanel check with the strategy to see if the strategy has received any market data within the last few seconds. If not, then the control panel assumes the strategy is no longer active, and hides itself from view ... not the best solution.

              I tried putting some code in the strategy destructor method, but it never seemed to run

              Comment


                #8
                Josh, not supported doesn't mean not working in this case am I correct? With the Dispose() methode it is possible to free resources reliable. I use it to remove the extension I appended to the chart's context menu and that never failed.

                bboyle1234, the destructor is a very unsave place to free resources, that is different compared with standard-C. It is because the purpose of the destructor in C# is a different compared with C.

                Regards
                Ralph

                Comment


                  #9
                  It means this is well beyond the level of support we can offer. We can help with NinjaScript, but you guys are trying to do things with external apps and such. Unfortunately we just don't have the bandwidth to be able to extend our support out there and you will be on your own for this endeavour.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Ok Josh.

                    bboyle1234, I use the following code with an indicator, but should work the same with a strategy. I use the additional flag, because Dispose() is called twice some time.

                    Regards
                    Ralph
                    Code:
                    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Dispose()[/SIZE][/FONT]
                    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (disposalDone == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
                    [SIZE=2][FONT=Courier New]  {[/FONT][/SIZE]
                    [SIZE=2][FONT=Courier New]    <Your Code>[/FONT][/SIZE][/SIZE][/FONT]
                    [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]    disposalDone = [/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                    [SIZE=2][FONT=Courier New]  }[/FONT][/SIZE]
                    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]  base[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Dispose();[/SIZE][/FONT]
                    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                    [/SIZE][/FONT]

                    Comment


                      #11
                      Guys, as Josh pointed out there are limitations of what NT can provide to you at this time. We understand your request since it's very reasonable. Therefore NT7 comes with a new concept which will meet your requirements.

                      Thanks for your patience and your understanding.

                      Comment


                        #12
                        Thanks everybody for your help.
                        Ralph, I feel a bit embarrassed to have been trying to use the destructor instead of the dispose method. Appreciate you pointing it out for me.
                        cheers / Ben
                        Last edited by bboyle1234; 01-20-2009, 04:30 PM. Reason: used the wrong name!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by sgordet, Today, 05:24 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post sgordet
                        by sgordet
                         
                        Started by royhagerman, Today, 04:30 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post royhagerman  
                        Started by haas88, 03-21-2024, 02:22 AM
                        18 responses
                        208 views
                        0 likes
                        Last Post haas88
                        by haas88
                         
                        Started by Board game geek, Today, 02:20 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post Board game geek  
                        Started by knighty6508, Today, 01:20 AM
                        2 responses
                        16 views
                        0 likes
                        Last Post knighty6508  
                        Working...
                        X