Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy TEMPLATES ?

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

    #16
    r2kTrader,

    If you are using Market Replay this is accurate behavior. It does not make sense to persist strategies running on the replay as each rewind, reconnect, etc. means you have to clear out the Replay101 account and start it all over again otherwise you would be doubling up strategy performance and other things like that.

    Thank you for the side bug report. We will look into it.
    Josh P.NinjaTrader Customer Service

    Comment


      #17
      r2kTrader,

      The side note bug will be fixed in the next version. Thanks.
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        strategies

        Hey, if anyone here has ever managed to START a strategy from within an indicator... ha ha... umm please post the code.

        Reason I want to do this is because, I know a strategy can't be started when ninjatrader is disconnected.

        SOOOO... I force ninjatrader to connect using the trusty code:

        CheckStatus = NinjaTrader.Cbi.Globals.Connections[0].Status.ToString();
        if (CheckStatus == "" || CheckStatus == "Disconnected")
        NinjaTrader.Cbi.Globals.Connections.Connect("my_co nnection/account_name_found_under_File>Connect");

        Har har. har.

        Just don't let the above code run more than once, or it might double-connect (happened a few times to me, had TWO "connected" statuses on the status bar hehe).

        Anyway so, my goal is basically to make ninjatrader automatically restart every day, and of course reconnect when it does so, and of course start all my charts too, and start all my indicators, and let's not forget to start all my strategies, even if I'm snoring away or watching TV.

        Reason is, because, Ninjatrader crashes, and... other stuff, like when it disconnects, and then reconnects, and it never re-downloads the bars that it missed when it was disconnected, which then throws off my indicators for a long time.

        And if ninjatrader misses some bars and you don't restart ninjatrader within 24 hours, guess what? Then it doesn't re-download those bars... ever! (at least that's my theory anyway). Unless of course you go and specifically delete your historical data and tell it to refresh it. But that's work.

        SOOOO!!! I wrote an external program to crash ninjatrader, with the handy code:

        Dim tempProc As Process() = Process.GetProcesses()
        Dim a As Integer = 0
        For a = 0 To tempProc.Length - 1
        If tempProc(a).MainWindowTitle.StartsWith("Control Center") = True Or _
        tempProc(a).ProcessName = "NinjaTrader" Then
        TextBox1.Text = Now.ToString() & ": Killing " & tempProc(a).MainWindowTitle & vbNewLine & TextBox1.Text
        tempProc(a).Kill()
        tempProc(a).WaitForExit()
        End If
        Next a

        Then I told it to refresh the ninjatrader database with a "just as though ninjatrader just got installed" database (you gotta save the database that it installs when you first install NT (AFTER you set up a few things, otherwise your indicators might not work), in order to zap all old historical data on all markets, with the handy code:

        System.IO.File.Move (you get the idea).

        Now, I'm enjoying my awesome ninjatrader that gets crashed at exactly 4am every night, so I wake up to a perfectly good ninjatrader, with all my charts, all my indicators, and perfectly beautiful historical data with no gaps in it.

        But I still have to manually start all my strategies (boo).

        I'm trying to use ChartControl.Add(new NinjaTrader.Strategy.MyStrategyName()).

        Pops up a nasty "Assertion Failed" error box, with the options to crash, crash, or not to crash. I click not to crash, but that's the ignore button.

        I also capture an exception on that line, the exception is: Object reference not set to an instance of an object. Tried I few things to make that exception go away, but no luck.

        Doing all this on NT 6.5. Anyone want to invest their time to figure this out, please let me know.

        I already know that none of the above is supported by Support.

        Comment


          #19
          Oh well, since I asked for help (below), I might as well give some help.

          For those of you who want a strategy template. Well, here is a little bit to help you out.

          In the strategies' Initialize() area, you can tell it to detect the instrument that the strategy is being loaded on, via the handy if statement:

          if (Instrument.FullName=="name of a market symbol you frequently use")
          {
          // code here to load this instrument's settings from a file you already made
          }


          Anyway, the above code will help some of you I think.

          Remember that some strategy settings can only be set in the Initialize() function area. I don't remember which, sorry. But I think you'll see errors if you try to change a setting outside of the Initialize() area, when you can't do that. And other times, you can. And other times, you have to, because you'll get an error if you try to change it in the Initialize() area. So if you get an error in OnBarUpdate(), try to move it to Initialize(). Or vise versa.

          Stuff you can set in Initilize()... (stuff I haven't tested I commented out)

          //AccountSize = 50000;
          BarsRequired = 200;
          CalculateOnBarClose = false;
          //CandleOutlineColor = Color.Black;
          //DataSeriesConfigurable = true;
          DefaultQuantity = 1;
          EntriesPerDirection = 1;
          EntryHandling = NinjaTrader.Strategy.EntryHandling.UniqueEntries;
          //ExcludeWeekend = false;
          ExitOnClose = false;
          //ExitOnCloseSeconds = 20;
          //Instrument = this.Instrument; //Also can try: new Instrument(new MasterInstrument("EURUSD", InstrumentType.Currency), Exchange.Default, DateTime.Today, 0, NinjaTrader.Cbi.Right.Unknown);
          //MaxProcessedEvents = ??; //<-- no idea what this is
          //Name = "My strategy name";
          QuantityType = NinjaTrader.Strategy.QuantityType.Strategy;
          RealtimeErrorHandling = NinjaTrader.Strategy.RealtimeErrorHandling.TakeNoA ction;
          Slippage = 0;
          StopTargetHandling = NinjaTrader.Strategy.StopTargetHandling.PerEntryEx ecution;
          //TraceOrders = false;
          TimeInForce = TimeInForce.Gtc;
          //IncludeCommission = false;
          FillType = new NinjaTrader.Strategy.LiberalFillType();

          Anyway, you can save the above settings to file, then load them in the Initilize() area based on the name of the instrument (found using the above code). Also, if your strategy has variables (most do), you can change those variables in the OnBarUpdate.

          To do this, use a bool variable to remember if you are on the first bar. Aka: bool FirstBar = false; //<-- put this in the global variable area at the top, above the Initilize() function. Then in onbarupdate: if (FirstBar == false) {FirstBar = true; //Your Code then follows here }

          In the "Your Code then follows here" area, put code to check the name of the instrument, along with checking for any important settings that you optionally inputted when you started the strategy (those settings would have been set by you and your mouse, when you started the strategy, in one or more of your optional variable input boxes, yep). Use that info to determine which strategy template file should be loaded. Then load it. Then change all of the rest of your strategy's variables according to the information found in that file.

          That way, let's say you have 10 different strategies that run on each instrument (market), and you run all 10 strategies on 10 different markets. Total strategy variations: 100. Not fun to input all of that manually.

          Well, the above code could help you out.

          I'd recommend you combine all 10 strategies into one big strategy, with a single variable that you can type a single number between 0 and 9, to specify which variation of strategy to run. That way, if you set the variable to 0 when you start the strategy, it will run that code, and skip all other strategy variations. Just an idea.

          That way, for all 10 markets, and all 10 variations on all 10 markets: it's always the same strategy file. Then you can't "make a user error" by accidentally loading the wrong strategy file, because the strategy file is always the same.

          THEN if you are really crazy about speed and not making mistakes... tell your strategy to automatically figure out which number you are on. To do this... in the OnBarUpdate, tell it to increment a file with the name of the isntrument (aka... EUR.txt for the EUR forex market, etc -- be sure your strategy auto-detects the instrument name using the code I gave above). That file will contain a number value, for example, 0 (zero). When you start your strategy, it will load that file, and set itself to use zero for it's number (and then it will, of course, automatically load the "0" file and set all its settings to what is in that file). It will also increment the file, and change it to 1. So when you start the strategy again on that market, it will load "1" for its number, etc. Might have to tweak with that to get it to work right for you.

          Of course, all the above code still doesn't fix the fact that your strategy will still need you to sit there and load all the strategies. But at least the settings for each strategy should sort of load themselves.

          You'll then want to change your strategy so that there is no other input that you'll have to look at when you open your strategy, other than just the one input to input the strategy's variation number (from 0 to 9, in this example).

          Then, pretty much, all you would to do is open a chart, then open the strategy box, select your strategy, type a number between 0 and 9 into the box, and click ok. It would then detect the name of the market, and load the appropriate file, for example, if the market name was EUR, and the number you typed in was 5, it would load: EUR_5.txt. It would then set ALL of its internal settings automatically, and you're done.

          Open chart on any market, open strategy window, select strategy, type a number, done. Can't really get any faster than that for 6.5, unless of course someone tells me how to automatically open a strategy from within an indicator (see my beautiful post below, lol).

          Comment


            #20
            @behealed


            Have a look at my code samples NTMT utilities.

            You can launch a strategy from another strategy and also from an indicator. Once launched, the strategy lives on its own and you know only via the account performance what happens.

            If you have a bigger project in mind, these tools are a good starting point.

            Andreas
            www.zweisteintrading.eu

            Comment


              #21
              By this, do you mean that this is an ATM strategy? Will it enter and exit real trades? That's two questions, not one.

              Originally posted by zweistein View Post
              @behealed

              Once launched, the strategy lives on its own and you know only via the account performance what happens.

              Comment


                #22
                @benealed

                all strategies from the new strategy dialalog can be called.


                regards


                p.s. if your account is real it will trade real.

                Comment


                  #23
                  Josh,

                  Flushing the performance is one thing, blowing out the strategies is another. Especially considering that replay is used for "testing".

                  Please give us the ability to persist in market replay. I know I am not alone on this. To have to reconstruct everything on a reboot is a pain.

                  So please feel free to clear the account and performance, but don't take down my strategies! It's SOOOOO much time to reconstruct EVERY time. (even more during beta of course).

                  Thanks for the consideration.



                  Originally posted by NinjaTrader_Josh View Post
                  r2kTrader,

                  If you are using Market Replay this is accurate behavior. It does not make sense to persist strategies running on the replay as each rewind, reconnect, etc. means you have to clear out the Replay101 account and start it all over again otherwise you would be doubling up strategy performance and other things like that.

                  Thank you for the side bug report. We will look into it.

                  Comment


                    #24
                    Behealed,

                    I figured out how to launch a strategy from indicator. It's actually pretty easy. I think you just have to edit the xml file ( I think you have to do it via a workspace maybe?) if I recall, not sure. I have the notes somewhere and I think it might be on my thread regarding undocumented/supported features of NT.

                    Also, go to NT7 straight away, it will get you ahead of schedule.

                    Also, zweistein showed me a slick way to force parameters. I have this all documented, just need to re-visit.

                    Also, I found a way to force the instrument, but it's not 100%, you have to click the drop down menu for the instrument, and it will "lock" onto the instrument that you programmed. So it's not perfect, but will prevent a fat finger. I am sure a better programmer could take what I did and make it default to that contract/instrument. I essentially hit the form directly.

                    Oh, zweistein also helped me get the code for making sure you get the spot contract for the month or the front month if you want that as well. It's really slick. I got it working and it's a nice way to make sure you are on the current month's contract. You can also adjust if you want to be on the front month near expiration.

                    Let's connect.

                    Originally posted by behealed View Post
                    By this, do you mean that this is an ATM strategy? Will it enter and exit real trades? That's two questions, not one.

                    Comment


                      #25
                      r2kTrader,

                      Thanks for the suggestion.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #26
                        Does anyone know a way to save strategy templates (like Fibonnacci tool), so I don't have to input all parameters every time I want to backtest with different set of parameters? Could it be implemented?

                        Comment


                          #27
                          There is no way to save multiple variations of strategy templates. The only thing you can do is save a "Default" set by right clicking in the property grid for a strategy. Your suggestion though is noted.
                          RayNinjaTrader Customer Service

                          Comment


                            #28
                            To solve this problem, I use a windows macro program called workspace macro. It records mouse movements, mouse clicks and keystrokes across windows applications. If you are using the same instruments with the same settings, then it makes it fast and easy to load the strategies. You only have to load the strategies once and then replay it each time you want to reload them again. I use this one bacause it has an easy to use macro editor , so you can make changes without having to learn a new scripting language or recreate the entire macro, e.g. you decide to change profit target from 70 to 65 pips, then you can easily edit only those keystrokes. Just create a separate macro for each instrument set, strategy, and account.

                            You can also set a schedule so they will run at a specified time. For example, I also use it to reset the time in tws. At 11:45 a.m. and 11:45 p.m., the macro runs and clicks configure, global configuration, lock and exit, then changes the time from AM to PM and then back again 12 hours later. This way tws doesn't shut down. You could also use it to close down nt, reopen, and reload historical data every day as behealed suggests.

                            Note that it has 3 different speeds. I have found that some macros will not run correctly at the fastest speed with certain applications because the application response time is too slow. It tries to account for this, but it doesn't always work, e.g. it may run 50 times correctly, then bomb out on the 51st time. So far I haven't had any problems running it at the fastest speed with nt though. I just mention it, because it may be prudent to schedule it to run earlier at the slow speed, if say you want to sleep an hour later, but you don't want to get fired or miss an hour of trading because it didn't run correctly.

                            Comment


                              #29
                              It would be great if this could be implemented along with strategy templates (just like fibo tool) and optimization results autosave feature, so one could just schedule a set of optimizations with different strategies/parameters to be run at night.

                              Comment


                                #30
                                fafura,

                                Thank you for your comments. It is on our feedback list.
                                Josh P.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                627 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                359 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                562 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                567 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X