Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volume Triggers

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

    Volume Triggers

    Hi Guys, trying to setup a simple volume trigger. What should happen is once the current bar (working on 5 minute chart) exceeds a volume trigger - volume 1, 2, 3, 4 it gives a sound alert. No sound is playing when exceeded. The problem is I had this working then now doesn't. I though maybe because trigger was 0 so changed to 1. Any ideas would be appreciated as I'm stuck!. Thanks. DJ


    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class volume : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int volume1 = 50000; // Default setting for Volume1
    private int volume2 = 30000; // Default setting for Volume2
    private int volume3 = 20000; // Default setting for Volume3
    private int volume4 = 10000; // Default setting for Volume4
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Volume[0] > Volume1)
    {
    Alert("MyAlert72", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 1.wav", 1, Color.White, Color.Black);
    }

    // Condition set 2
    if (Volume[0] > Volume2)
    {
    Alert("MyAlert73", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 2.wav", 1, Color.White, Color.Black);
    }

    // Condition set 3
    if (Volume[0] > Volume3)
    {
    Alert("MyAlert74", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 3.wav", 1, Color.White, Color.Black);
    }

    // Condition set 4
    if (Volume[0] > Volume4)
    {
    Alert("MyAlert75", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 4.wav", 1, Color.White, Color.Black);
    }
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int Volume1
    {
    get { return volume1; }
    set { volume1 = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int Volume2
    {
    get { return volume2; }
    set { volume2 = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int Volume3
    {
    get { return volume3; }
    set { volume3 = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int Volume4
    {
    get { return volume4; }
    set { volume4 = Math.Max(1, value); }
    }
    #endregion
    }

    #2
    Hi djkiwi,

    I don't spot anything immediately, are you getting any errors in the Log tab of the Control Center?

    Try adding Print() statements just above the Alert() lines, so that we can narrow down if the condition is being satisfied, or if the issue is the Alert code.
    TimNinjaTrader Customer Service

    Comment


      #3
      Hi Tim. Thanks for the fast reply. Well I changed this to test whether the close of the last volume bar closes it exceeds the stated volume criteria. What I notice is the alerts works the first time but never rearms, thats what happened last time, I got it to work on the first bar then that was it never heard an alert again. Here is the revised code with print statements (note I am using the analyzer as cannot program at this point so not sure if those print statements are the right ones or what they do). I have no errors in the log in the control panel. I think the issue is a rearming one. The alert rearms works ok when I use them in market analyzer.....

      Any ideas on this one?
      Thanks, DJ

      /// <summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      /// </summary>
      protected override void Initialize()
      {
      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (Volume[1] > 10000)
      {
      Alert("MyAlert76", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 1.wav", 1, Color.White, Color.Black);
      PrintWithTimeStamp("Has it worked");
      }

      // Condition set 2
      if (Volume[1] > 20000)
      {
      Alert("MyAlert77", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 2.wav", 1, Color.White, Color.Black);
      PrintWithTimeStamp("Has it worked");
      }

      // Condition set 3
      if (Volume[1] > 30000)
      {
      Alert("MyAlert78", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 3.wav", 1, Color.White, Color.Black);
      PrintWithTimeStamp("Has it worked");
      }

      // Condition set 4
      if (Volume[1] > 40000)
      {
      Alert("MyAlert79", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 4.wav", 1, Color.White, Color.Black);
      PrintWithTimeStamp("Has it worked");
      }
      }

      #region Properties
      [Description("")]
      [GridCategory("Parameters")]
      public int MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(1, value); }
      }
      #endregion

      Comment


        #4
        Hi djkiwi,

        Nice implemenation of the Print()'s.

        Try changing your CalculateOnBarClose setting to false, instead of true.

        TimNinjaTrader Customer Service

        Comment


          #5
          Thanks Tim, ok well managed to get it all working now. Putting the less thans in for each brackets seemed to help. The new problem is getting the times of day to work. So what I'm trying to do is have different volume triggers for each time of the day. For example this alert should only go off between 1100 AM and 1130 AM but instead it went off after 12:00 PM. You will see this in the code below:

          && ToTime(11, 0, 0) < ToTime(11, 30, 0))

          Basically am I using the time function correctly because it doesn't work the way I'm doing it?

          Thanks
          DJ

          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Strategy;
          #endregion

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          /// <summary>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class volume2 : Strategy
          {
          #region Variables
          // Wizard generated variables
          // User defined variables (add any user defined variables below)
          #endregion

          /// <summary>
          /// This method is used to configure the strategy and is called once before any strategy method is called.
          /// </summary>
          protected override void Initialize()
          {
          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (Volume[0] > 10000
          && Volume[0] < 20000
          && ToTime(11, 0, 0) < ToTime(11, 30, 0))
          {
          Alert("MyAlert83", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 1.wav", 10, Color.White, Color.Black);
          PrintWithTimeStamp("Has it worked");
          }

          // Condition set 2
          if (Volume[0] > 20000
          && Volume[0] < 30000
          && ToTime(11, 0, 0) < ToTime(11, 30, 0))
          {
          Alert("MyAlert82", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 2.wav", 10, Color.White, Color.Black);
          PrintWithTimeStamp("Has it worked");
          }

          // Condition set 3
          if (Volume[0] > 30000
          && Volume[0] < 40000)
          {
          Alert("MyAlert81", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 3.wav", 10, Color.White, Color.Black);
          PrintWithTimeStamp("Has it worked");
          }

          // Condition set 4
          if (Volume[0] > 40000)
          {
          Alert("MyAlert80", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\TNA vol 4.wav", 10, Color.White, Color.Black);
          PrintWithTimeStamp("Has it worked");
          }

          Comment


            #6
            Hi djkiwi,

            You are comparing two explicit values, and it is returning as true since the statement is true.

            You will need to check the current bar against a time, something like...
            ToTime(Time[0]) < 113000)

            As seen in this sample: http://www.ninjatrader.com/support/f...ead.php?t=3226
            TimNinjaTrader Customer Service

            Comment


              #7
              Thanks Tim, I see my application was incorrect. The question though is how do you get this part in strategy analyzer?

              ToTime(Time[0])

              When I go to time and time value and put in zero in the input bx it says property value not valid. I also put in the 113000 in the numeric value field. Thanks. DJ

              Comment


                #8
                Hi Tim, thanks for the link very useful. I got the first part ok, not sure how to get the 113000? This is what I have now. I tried putting the 113000 as a numeric value and also put it in time as a series but can't get it how you have it

                ToTime(Time[0]) < ToTime(Time[113000])

                Thanks DJ

                Comment


                  #9
                  Hi djkiwi,

                  Can you provide a screenshot of where you are putting this?


                  To send a screenshot press Alt (sometimes Fn key) + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CRTL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.
                  TimNinjaTrader Customer Service

                  Comment


                    #10
                    Volume

                    Hi Tim, here you go. When putting as a numeric value as the second one it wouldnt let me and said "return type of left expression 'date time' and right expression 'double' do not match. You need to select a different item.

                    Cheers
                    DJ
                    Attached Files

                    Comment


                      #11
                      Hi djkiwi,

                      If you want to use the wizard for this, select Time Value instead and use "11:30 AM"
                      TimNinjaTrader Customer Service

                      Comment


                        #12
                        Multi time frame trend

                        Thanks Tim, it works perfectly, great job! The other issue I'm grappling with is multiple timeframes and was helping you could point me in the right direction. For example if you look at file tim3.jpg below you will see a 6 Renko timeframe with the arrows showing if SAR crossed. The thing is I only want the arrow to show if the longer term trend supports it. For example if you look at tim4.jpg you will see that the trend for the day on a 25 renko chart is up and only an up arrow showing. So what I am trying to do is on the 6 renko only show the parabolic cross arrow if the renko 25 shows the same. For example there should be no down arrows on the 6 renko because the trend on the 25 renko the trend is up. Any ideas on this one? Thanks. DJ
                        Attached Files

                        Comment


                          #13
                          Hi djkiwi,

                          To clarify, is this the default Renko being used, or a custom one?
                          TimNinjaTrader Customer Service

                          Comment


                            #14
                            Hi Tim. I am just using standard renko options in ninjatrader. I have found this post on different timeframes but not sure what to do with it.



                            Basically my code is as below. So what I'm trying to do is say if the trend is up on a renko 25 and there is a parabolic SAR cross then the parabolic crossover will show only on crosses to the upside on lower timeframes. Cheers. DJ

                            #region Using declarations
                            using System;
                            using System.ComponentModel;
                            using System.Diagnostics;
                            using System.Drawing;
                            using System.Drawing.Drawing2D;
                            using System.Xml.Serialization;
                            using NinjaTrader.Cbi;
                            using NinjaTrader.Data;
                            using NinjaTrader.Indicator;
                            using NinjaTrader.Gui.Chart;
                            using NinjaTrader.Strategy;
                            #endregion

                            // This namespace holds all strategies and is required. Do not change it.
                            namespace NinjaTrader.Strategy
                            {
                            /// <summary>
                            /// This sample demonstrates the use of the Rising and Falling conditions within the Strategy Wizard.
                            /// </summary>
                            [Description("This sample demonstrates the use of the Rising and Falling conditions within the Strategy Wizard.")]
                            public class ESSAR : Strategy
                            {
                            #region Variables
                            // Wizard generated variables
                            private int eMAPeriod = 8; // Default setting for EMAPeriod
                            // User defined variables (add any user defined variables below)
                            #endregion

                            /// <summary>
                            /// This method is used to configure the strategy and is called once before any strategy method is called.
                            /// </summary>
                            protected override void Initialize()
                            {

                            CalculateOnBarClose = true;
                            }

                            /// <summary>
                            /// Called on each bar update event (incoming tick)
                            /// </summary>
                            protected override void OnBarUpdate()
                            {
                            // Condition set 1
                            if (Rising(EMA(EMAPeriod)) == true
                            && CrossAbove(Close, ParabolicSAR(0.015, 0.4, 0.04), 1))
                            {
                            DrawTriangleUp("My triangle up" + CurrentBar, false, 1, Close[0] + -20 * TickSize, Color.Lime);
                            PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\ES SAR Buy signal.wav");
                            }

                            // Condition set 2
                            if (Falling(EMA(EMAPeriod)) == true
                            && CrossBelow(Close, ParabolicSAR(0.015, 0.4, 0.04), 1))
                            {
                            DrawTriangleDown("My triangle down" + CurrentBar, false, 1, Close[0] + 20 * TickSize, Color.Red);
                            PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\ES SAR Sell signal.wav");
                            }
                            }

                            #region Properties
                            [Description("")]
                            [GridCategory("Parameters")]
                            public int EMAPeriod
                            {
                            get { return eMAPeriod; }
                            set { eMAPeriod = Math.Max(1, value); }
                            }
                            #endregion
                            }
                            }

                            Comment


                              #15
                              Hi djkiwi,

                              I see, for this you will want to setup a Multi-Series Strategy, which shares a similar setup as the link you provided.

                              Please see this sample/tutorial for more info - http://www.ninjatrader-support.com/H...ameInstruments
                              TimNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              72 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              43 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              25 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              28 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              59 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X