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

Starting Strategy Through Addon

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

    Starting Strategy Through Addon

    Hi,

    Is it possible to start and stop a strategy through an addon?

    I see there's a class NinjaTrader.Cbi.StopStrategy.

    Thanks

    #2
    Hello tmfdouglas,

    There are no documented / supported ways to enable or disable a strategy from an Addon.

    If you would like we can submit a feature request to add this functionality to a future version of NinjaTrader. Would you like to submit a feature request to the NinjaTrader Development?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes please add a feature request.

      Thanks

      Comment


        #4
        Hello tmfdouglas,

        Our development has provided a tracking ID for your feature request.
        Your request to disable/enable NinjaScript Strategies via code is being tracked with ID #SFT-977.

        It is up to the NinjaTrader Development to decide if and when a feature request will be implemented.

        We appreciate you taking the time to provide feedback.
        Please let us know of any other suggestions you have for the NinjaTrader platform.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Im also interested in such option, and I think I was already asked that ...
          This way we could be able to re enable a strategy from an indicator or addon
          pmaglio
          NinjaTrader Ecosystem Vendor - The Indicator Store

          Comment


            #6
            Is there any progress now? I have the same request. Do you have any solution before you add this feature?

            Comment


              #7
              Hello gutuc,

              Thank you for your post.

              There is no solution to start or stop a strategy through an Add On.

              Please let me know if you have any questions.

              Comment


                #8
                It's possible, but NOT trivial

                Originally posted by NinjaTrader_PatrickH View Post
                Hello gutuc,

                Thank you for your post.

                There is no solution to start or stop a strategy through an Add On.

                Please let me know if you have any questions.
                While @NinjaTrader_PatrickH is absolutely right in that there is no available solution (I've looked everywhere), it can be done but you'll need to be very comfortable with invoking private static methods in classes which may not be public. Long story short, it's not for the faint of heart but is possible. If you're not a seasoned developer, it'll also be expensive...

                Here's a (very) general outline:

                1) Visual Studio debug settings: disable "Just My Code". This allows you to see everything in the call stack including non public methods NT uses to achieve things like adding or enabling a strategy. This will expose the method's name which you'll need if that method is not public (or the class is not public) and you want to invoke that method.

                2) Set visual studio break points in a simple strategy which does nothing but has all the overrides. I created a stripped down 3rd party dll which allows me to create custom constructors and set break points all over the place to see exactly what NT method calls are happening underneath. NT does some weird stuff like creating 2-3 instances of a strategy when you open the "New Strategy" dialog menu. My best guess is they create a temp strategy so the properties pane on the right can be populated. Then another instance once you add the strategy. Then yet another via cloning once you click ok (this is the one you really need to watch and is the 'actual' strategy object).

                3) You'll need to be able to grab the control center (examples all over the forum) object. From there, you'll have to get the strategy tab object. Short version is you'll have to recursively get objects' "Content" property, figure out what to cast it to (so you can then see it's corresponding properties), check it for null, rinse and repeat until you get exactly the obect you need. For strategies, you'll need the strategy tab and the grid obect in that tab. From memory, I believe StrategyGrid class is accessable but the "AddStrategy" static method is not so you'll have to resolve it into a MethodInfo object then use invoke to "call" it. I think I counted 8+ levels of nested if checks before I got the object I needed.

                4) Enabling strategies programmatically is NOT easy. Creating, adding, deleting is easy compared to enabling/disabling strategies. If you're not following 1-3 and able to do it all yourself, pay someone to do this because if you mess it up, you'll have rogue strategies starting and stopping unexepectedly. Or, even worse, you'll have critical exceptions being thrown which may completely take down your NT. Don't forget the edge case of a manually created user strategy thrown in with all of the programmatically created ones. Having fun yet?

                5) NinjaTrader uses a static singleton collection for it's strategies in the StrategyBase class. This is a Collection<StrategyBase> type object which means it doesn't have those nice CollectionChanged events firing for you. Yet another long story short, you'll have to devise your own mechanism for firing custom events when strategies are added or removed from this NT collection. If you're not familar with thread looping (aka polling), I'd HIGHLY recommend hiring a developer who is to tackle this task. Otherwise, you'll be wasting valuable CPU resources via badly designed pollers which could instead be used to calculate your strategies' logic. [soapbox] Anything which needs to scale, you must be a good steward of CPU resource usage.

                6) Logging, logging, logging. When somthing goes wrong, you'll need a complete logging solution so you can exactly what went wrong, why, and who the offender was. Exception analysis, stack tracing, etc are your only clues and those objects don't hang around long once something goes wrong enough to trigger them. https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx was my savior here and allowed me to write everything out before NT went down hard. This was a painful learning curve!

                In closing, if you're very good with Visual Studio and reflection, NT8 can be bent to virtually any will you can imagine. The horrific thought though is all of this is way beyond "not supported" so if any NT internal logic changes, you could have thousands of lines of code which are now very effecient exception generators or NT crashers. If you have a working solution, you'll be frozen on the version of NT this was developed on until you can completely test any NT updates pushed (I use virtual machines for clean environments to test new NT versions).

                Finally, with the amount of work required to make this programmatically possible, IMO you should only pursue this if you have a known successful strategy which you need to scale to something like 100+ instruments. Otherwise, you'll save yourself time (read $$$ if you're not a seasoned developer) and heartache by just going through the monotonous process of doing everything manually.

                Good luck,

                Jason

                Comment


                  #9
                  +1

                  Please add my vote.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by tkaboris, Today, 08:01 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post tkaboris  
                  Started by BarzTrading, Today, 07:25 AM
                  1 response
                  11 views
                  1 like
                  Last Post NinjaTrader_Clayton  
                  Started by EB Worx, 04-04-2023, 02:34 AM
                  7 responses
                  161 views
                  0 likes
                  Last Post VFI26
                  by VFI26
                   
                  Started by Mizzouman1, Today, 07:35 AM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by Radano, 06-10-2021, 01:40 AM
                  20 responses
                  616 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X