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

Can I create an indicator to start my automated strategies each day?

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

    Can I create an indicator to start my automated strategies each day?

    Hello all,

    I have 3 automated trading strategies that I run each day on the chart. All 3 are intraday strategies that have "Exit on session close" set to true. I have to re-enable the strategies each morning before market open, input their settings and configure the data series for each. I was wondering if there was a way to automate this process as well. That got me thinking...

    Is it possible to create an indicator that will run on the chart 24/7, assuming NT is open and the PC is on, and do the following:

    1) Automatically enable the same 3 strategies each morning at a specific time, say 8:30 am EST.
    2) Apply the relevant settings to each strategy, either by loading each strategy template or some other way.
    3) Pull up a chart window with each strategy chart loaded in a separate tab so that I can visually confirm correct behavior.
    4) Turn the strategies off at a set time each day, say end of equities RTH at 4pm EST.
    5) Repeat

    Is my thinking on the right track here? Love the ability to create an have automated strategies, but I want to reduce the amount of configuring and interference I have to do as much as possible. Would like to just be an overseer who checks in periodically to make sure my strategies haven't gone rogue and I need to mortgage the house.

    Any thoughts on this approach would be helpful, thank you.


    - Jay
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    I would suggest looking at "auto-it" (a scripting tool).
    I currently have scripted my daily start-up which includes connecting to IB, then connecting the IB connection in NT , and then activating the strategies.
    >> It will take some effort, but well worth it as I auto-start my process on Sunday and let it go until Friday... and it handles it all

    You can download the main AutoIt package and other related scripting tools from this page.

    Comment


      #3
      Thanks waltFX, I will look into "auto-it" if I cannot find another solution within the NT ecosystem itself.
      jaybedreamin
      NinjaTrader Ecosystem Vendor - Zion Trading Algos

      Comment


        #4
        Hello Jay,

        Just to confirm, the external application solution would be necessary, as there is no support for enabling NinjaScript Strategies with code.

        This is intentional, as we want users to manually enable the strategy, fully aware the strategy is about to start auto trading.

        It is possible to Ctrl + a on the Strategies tab of the Control Center, then right-click and select Enable to manually enable all strategies at the same time.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea,

          So something like this would not be possible from inside an indicator?

          Code:
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = "MyIndicator";
          }
          else if (State == State.Configure)
          {
          // Add the indicator to a chart
          ChartControl.AddChartIndicator(this, true);
          
          // Enable the indicator
          IsOverlay = true;
          Enabled = true;
          }
          }
          
          protected override void OnBarUpdate()
          {
          // Check if the current bar is on a new trading day
          if (Time[0].Date > currentDay)
          {
          // Update the current day variable
          currentDay = Time[0].Date;
          
          // Check if the current time is 9:30 AM
          if (Time[0].TimeOfDay == new TimeSpan(9, 30, 0))
          {
          // Enable the "MyOtherStrategy" strategy
          foreach (var strat in Strategies)
          {
          if (strat.Name == "MyOtherStrategy")
          {
          strat.Enabled = true;
          strat.Template = "MyTemplate";
          strat.Instrument = InstrumentList.GetInstrument("AAPL", InstrumentType.Stock);
          strat.AddDataSeries(BarsPeriodType.Minute, 5);
          
          // Open a new chart for the strategy
          ChartControl.NewChart(strat.Name, strat.Instrument.FullName,
          new ChartTemplate(strat.Template),
          ChartControl.ChartStyle.CandleStick,
          ChartControl.BarType.Time, 5);
          
          break;
          }
          }
          }
          }
          }
          ​
          I asked ChatGPT if this was possible and it said yes, and gave me a rough outline of how to go about it. But I'm guessing it was wrong since your answer basically says the opposite.
          jaybedreamin
          NinjaTrader Ecosystem Vendor - Zion Trading Algos

          Comment


            #6
            Originally posted by jaybedreamin View Post
            I asked ChatGPT if this was possible and it said yes, and gave me a rough outline of how to go about it. But I'm guessing it was wrong since your answer basically says the opposite.
            I am sure you understand that ChatGPT is just vomiting up bits of regurgitated text that it has encountered, rearranged and smooshed together again. For instance, I asked ChatGPT if I could log into NinjaTrader without my username and password, and it said:

            Click image for larger version  Name:	image.png Views:	0 Size:	48.5 KB ID:	1243073
            Anyone who has actually used NinjaTrader knows this is complete nonsense, as is, of course, the answer it provided to your question. It has some of the right words in it, but the answer implies a total lack of understanding.
            Last edited by QuantKey_Bruce; 03-27-2023, 03:17 PM.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #7
              Thanks QuantKey_Bruce,

              That's hilarious, first of all, and makes sense. I know it gets a lot of things wrong, especially on the technical side but it has been useful in helping to flesh out ideas at a high level. I guess my best odds are looking into the auto-it tool that waltFx mentioned.

              Thanks all
              jaybedreamin
              NinjaTrader Ecosystem Vendor - Zion Trading Algos

              Comment


                #8
                Originally posted by jaybedreamin View Post
                Thanks QuantKey_Bruce,

                That's hilarious, first of all, and makes sense. I know it gets a lot of things wrong, especially on the technical side but it has been useful in helping to flesh out ideas at a high level. I guess my best odds are looking into the auto-it tool that waltFx mentioned.

                Thanks all
                Here's another one, in which I asked ChatGPT if I could eat my own head, and if not, why not? It correctly told me that I could not, but completely misunderstands the most important reason I cannot, a reason which is obvious to anyone who actually has a head.

                Click image for larger version

Name:	image.png
Views:	207
Size:	82.6 KB
ID:	1243084
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #9
                  "It is strongly advised that you do not attempt to do so under any circumstances"

                  That's it, my night is made LOL
                  jaybedreamin
                  NinjaTrader Ecosystem Vendor - Zion Trading Algos

                  Comment


                    #10
                    Hello jaybedreamin,

                    Just verify, no, the suggested code in post # 5 is not going to work.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      jaybedreamin,
                      If your new to "auto-it", the attached is the NT auto-login exe & script to give you an "auto-it" kickstart...
                      Attached Files

                      Comment


                        #12
                        Unless I'm missing something here, I think there's an easy solution within NT8.

                        Have your strategy do a time of day check. If within trading times, then trade, if not, don't. That way, you could set your strategies once Sunday evening and let them run for the week. You can check in on them at any time throughout the day/week. You would not need the "Exit on session close" check. Then, you manually disable on Friday after market close. I have successfully done this.

                        Here's a code snippet that handles this.
                        Code:
                        isPassFilters = true;
                        
                        int hr = Time[0].Hour;
                        int min = Time[0].Minute;
                        int intTime = hr * 100 + min;
                        // Session check
                        if (hr == 16 || hr == 17 || hr == 18) {
                            Print(" Session transition - no new trades");
                            isPassFilters = false; // Don't start any trades within 1 hour of the end/begin of session.
                            // Add text at the top of the bar indicating session transition
                            Draw.Text(this, "currBar" + CurrentBar, true, "xEOS", 0, High[0] + (20 * TickSize), 0, Brushes.IndianRed, theTextFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                        }
                        ​
                        While not used in this snippet, the intTime (military/24 hour time represented by a simple integer) can be easily compared to for any time in the day. For example, don't trade the RTH open 30 minutes:
                        if (intTime >= 930 && intTime <= 1000) then return;

                        Mind you, this is time zone (US Eastern) specific, so not necessarily the "right" go about this. It is an easy, convenient solution, though, without messing with the complexities of DateTime object.

                        Hope that helps!
                        Matt

                        Comment


                          #13
                          Matt, yes, that would probably work for Jay as long as the connection he uses is rock-solid and stays active.
                          In my case, Interactive Brokers goes off-line each night for about 15 minutes, so NT gets disconnected.
                          >>I actually auto shut-down at 23:40 and auto restart at 01:00 as IB shuts-down anywhere from 23:45 to 00:45 for daily maintenance...

                          Comment


                            #14
                            Originally posted by StealthM93 View Post
                            Unless I'm missing something here, I think there's an easy solution within NT8.

                            Have your strategy do a time of day check. If within trading times, then trade, if not, don't. That way, you could set your strategies once Sunday evening and let them run for the week. You can check in on them at any time throughout the day/week. You would not need the "Exit on session close" check. Then, you manually disable on Friday after market close. I have successfully done this.

                            Here's a code snippet that handles this.
                            Code:
                            isPassFilters = true;
                            
                            int hr = Time[0].Hour;
                            int min = Time[0].Minute;
                            int intTime = hr * 100 + min;
                            // Session check
                            if (hr == 16 || hr == 17 || hr == 18) {
                            Print(" Session transition - no new trades");
                            isPassFilters = false; // Don't start any trades within 1 hour of the end/begin of session.
                            // Add text at the top of the bar indicating session transition
                            Draw.Text(this, "currBar" + CurrentBar, true, "xEOS", 0, High[0] + (20 * TickSize), 0, Brushes.IndianRed, theTextFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
                            }
                            ​
                            While not used in this snippet, the intTime (military/24 hour time represented by a simple integer) can be easily compared to for any time in the day. For example, don't trade the RTH open 30 minutes:
                            if (intTime >= 930 && intTime <= 1000) then return;

                            Mind you, this is time zone (US Eastern) specific, so not necessarily the "right" go about this. It is an easy, convenient solution, though, without messing with the complexities of DateTime object.

                            Hope that helps!
                            Matt
                            Oh man, this might be just what I was looking for. Seems I have an incorrect understanding of how "Exit on session close" works, however.

                            I thought this check was needed to ensure that trades are closed by the end of the session if neither a profit target or a stop loss are hit. Are you saying that I can enable my strategies on Sunday, add the timing logic(already have this as it's part of my strategy), and the strategies will still pretty much behave as they are now, until I manually disable on Friday?
                            jaybedreamin
                            NinjaTrader Ecosystem Vendor - Zion Trading Algos

                            Comment


                              #15
                              Originally posted by waltFX View Post
                              jaybedreamin,
                              If your new to "auto-it", the attached is the NT auto-login exe & script to give you an "auto-it" kickstart...
                              Downloaded and saved to my PC. Walt, you're the man. Thank you!
                              jaybedreamin
                              NinjaTrader Ecosystem Vendor - Zion Trading Algos

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fx.practic, 10-15-2013, 12:53 AM
                              5 responses
                              5,404 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by Shai Samuel, 07-02-2022, 02:46 PM
                              4 responses
                              95 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by DJ888, Yesterday, 10:57 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by MacDad, 02-25-2024, 11:48 PM
                              7 responses
                              159 views
                              0 likes
                              Last Post loganjarosz123  
                              Started by Belfortbucks, Yesterday, 09:29 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post Belfortbucks  
                              Working...
                              X