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

How to Add a sound Alert to the Built-In NT8 VolumeUpDown Indicator

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

    How to Add a sound Alert to the Built-In NT8 VolumeUpDown Indicator

    Hello,

    I've gone through the NT8 @VolumeUpDown.cs Indicator but can't see how to add an alert for specific condition.

    The specific condition is very simple:

    Fire an audio alert every time the current Volume Bar value on each tick is Greater or equal to the average volume of the past x number of bars.
    The Number of bars to look back should be customisable as user input.

    The logic should look something like that for the past 10 bars average (pseudo code as I'm new to C#):

    Code:
    IF
    
         ON EACH TICK CALCULATION
         CURRENTBAR[0] >= AVERAGE(Bar[-10] to Bar[-1])
    
    THEN
    
          FIRE SOUNDFILE.wav
    How do you get that result?
    Thanks for your help.

    Here's the copied @VolumeUpDown.cs code for quick reference

    Code:
    //
    // Copyright (C) 2020, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class VolumeUpDown : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Calculate = Calculate.OnBarClose;
    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionVolumeUpDown;
    DrawOnPricePanel = false;
    IsOverlay = false;
    IsSuspendedWhileInactive = true;
    Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meVolumeUpDown;
    
    AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeUp);
    AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeDown);
    AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
    }
    else if (State == State.Historical)
    {
    if (Calculate == Calculate.OnPriceChange)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnPriceChangeError, Name), TextPosition.BottomRight);
    Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnPriceChangeError, Name), LogLevel.Error);
    }
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (Close[0] >= Open[0])
    {
    UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
    DownVolume.Reset();
    }
    else
    {
    UpVolume.Reset();
    DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
    }
    }
    
    #region Properties
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> DownVolume
    {
    get { return Values[1]; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> UpVolume
    {
    get { return Values[0]; }
    }
    #endregion
    }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private VolumeUpDown[] cacheVolumeUpDown;
    public VolumeUpDown VolumeUpDown()
    {
    return VolumeUpDown(Input);
    }
    
    public VolumeUpDown VolumeUpDown(ISeries<double> input)
    {
    if (cacheVolumeUpDown != null)
    for (int idx = 0; idx < cacheVolumeUpDown.Length; idx++)
    if (cacheVolumeUpDown[idx] != null && cacheVolumeUpDown[idx].EqualsInput(input))
    return cacheVolumeUpDown[idx];
    return CacheIndicator<VolumeUpDown>(new VolumeUpDown(), input, ref cacheVolumeUpDown);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.VolumeUpDown VolumeUpDown()
    {
    return indicator.VolumeUpDown(Input);
    }
    
    public Indicators.VolumeUpDown VolumeUpDown(ISeries<double> input )
    {
    return indicator.VolumeUpDown(input);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.VolumeUpDown VolumeUpDown()
    {
    return indicator.VolumeUpDown(Input);
    }
    
    public Indicators.VolumeUpDown VolumeUpDown(ISeries<double> input )
    {
    return indicator.VolumeUpDown(input);
    }
    }
    }
    
    #endregion

    #2
    Hello Dougtre, thanks for your post, and welcome to the NinjaTrader forum.

    You can use the VOLMA indicator to easily get the moving average value of the instrument's volume:



    I am assuming here you know how to reference indicator data within a script. A prime example of doing this can be found in the "SampleMACrossover" strategy where two SMA objects are created and referenced. If you are not yet comfortable referencing indicator data, please study this sample carefully.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Chris,

      Thanks for the example.
      Code:
      // Evaluates if the current volume is greater than the 20 period EMA of volume
      if (Volume[0] > VOLMA(20)[0])
        Print("Volume has risen above its 20 period average");
      Do you know how to use the VOLMA on each tick calculation?
      There's no reference about that in the previous page.

      Where can I locate the SampleMACrossover strategy?

      It's not returning any find there:


      Thanks.


      Comment


        #4
        Also,

        I can't find example on adding an alert in the guide:


        Can you please help locate that?
        Thanks.

        Comment


          #5
          Hello Dougtre, thanks for your reply.

          You can call the PlaySound method to play an alert sound. See here for documentation:



          Kind regards.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Thanks a lot Chris for that help.


            So here's the code I end up with:

            Code:
            // Fire mySound.wav sound every time Current volume gets greater or equal to the average volume of past 10 volume bars
            if (upVolume[0] >= VOLMA(10)[0])
            {
            PlaySound(@"C:\mySound.wav");
            }
            else if (downVolume[0] >= VOLMA(10)[0])
            {
            PlaySound(@"C:\mySound.wav");
            }
            Else if in C#
            W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


            I've located the "SampleMACrossover" script file in
            C:\Users\<PCNAME>\Documents\NinjaTrader 8\bin\Custom\Strategies

            Code below for reference.

            I don't readily see the way to add the above alert code to the VolumeUpDown indicator.

            Would simply enclosing it like that work?

            Code:
             protected override void OnEachTick()
            {
            if (upVolume[0] >= VOLMA(10)[0])
            {
            PlaySound(@"C:\mySound.wav");
            }
            else if (downVolume[0] >= VOLMA(10)[0])
            {
            PlaySound(@"C:\mySound.wav");
            }
            }
            Any error I'm not aware of?

            Thanks a lot for the help.



            Code:
            //
            // Copyright (C) 2020, NinjaTrader LLC <www.ninjatrader.com>.
            // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
            //
            #region Using declarations
            using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.ComponentModel.DataAnnotations;
            using System.Linq;
            using System.Text;
            using System.Threading.Tasks;
            using System.Windows;
            using System.Windows.Input;
            using System.Windows.Media;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Gui;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Gui.SuperDom;
            using NinjaTrader.Data;
            using NinjaTrader.NinjaScript;
            using NinjaTrader.Core.FloatingPoint;
            using NinjaTrader.NinjaScript.Indicators;
            using NinjaTrader.NinjaScript.DrawingTools;
            #endregion
            
            //This namespace holds strategies in this folder and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.Strategies
            {
            public class SampleMACrossOver : Strategy
            {
            private SMA smaFast;
            private SMA smaSlow;
            
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
            Name = NinjaTrader.Custom.Resource.NinjaScriptStrategyNam eSampleMACrossOver;
            Fast = 10;
            Slow = 25;
            // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
            // See the Help Guide for additional information
            IsInstantiatedOnEachOptimizationIteration = false;
            }
            else if (State == State.DataLoaded)
            {
            smaFast = SMA(Fast);
            smaSlow = SMA(Slow);
            
            smaFast.Plots[0].Brush = Brushes.Goldenrod;
            smaSlow.Plots[0].Brush = Brushes.SeaGreen;
            
            AddChartIndicator(smaFast);
            AddChartIndicator(smaSlow);
            }
            }
            
            protected override void OnBarUpdate()
            {
            if (CurrentBar < BarsRequiredToTrade)
            return;
            
            if (CrossAbove(smaFast, smaSlow, 1))
            EnterLong();
            else if (CrossBelow(smaFast, smaSlow, 1))
            EnterShort();
            }
            
            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
            public int Fast
            { get; set; }
            
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
            public int Slow
            { get; set; }
            #endregion
            }
            }

            Comment


              #7
              Hello Dougtre, thanks for the follow up.

              It looks like you were able to find the issue. I will close this ticket, but If you have any questions just reply here and I will get back to you.

              Best regards.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Hi Chris,

                Thanks for the follow up.

                Follwing this example I ended up using the MAX function instead of the VOLMA function.


                The working snippet:
                Code:
                 if(Volume[0]>MAX(Volume,Period)[1])
                {
                PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\BogartClear.wav");
                BackBrush = Brushes.White;
                }[URL="https://ninjatrader.com/support/forum/forum/ninjatrader-7/indicator-development-aa/70625-max-highest-high-of-an-indicator#post70625"][/URL]

                It works but I can't use the average as a result.

                And I still don't know how to reference indicator data in spite of studying the SampleMACrossOver Strategy script carefully as you suggested. Nothing in it explicitely tells how to reference indicator data.
                Hello, I've gone through the NT8 @VolumeUpDown.cs Indicator but can't see how to add an alert for specific condition. The specific condition is very simple: Fire an audio alert every time the current Volume Bar value on each tick is Greater or equal to the average volume of the past x number of bars. The Number of bars to

                And I didn't find anywhere explicit explanation in the user guide either.

                The SampleMACrossOver code [nothing tells about referencing another indicator or the VLOMA]
                Code:
                //
                // Copyright (C) 2020, NinjaTrader LLC <www.ninjatrader.com>.
                // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
                //
                #region Using declarations
                using System;
                using System.Collections.Generic;
                using System.ComponentModel;
                using System.ComponentModel.DataAnnotations;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;
                using System.Windows;
                using System.Windows.Input;
                using System.Windows.Media;
                using System.Xml.Serialization;
                using NinjaTrader.Cbi;
                using NinjaTrader.Gui;
                using NinjaTrader.Gui.Chart;
                using NinjaTrader.Gui.SuperDom;
                using NinjaTrader.Data;
                using NinjaTrader.NinjaScript;
                using NinjaTrader.Core.FloatingPoint;
                using NinjaTrader.NinjaScript.Indicators;
                using NinjaTrader.NinjaScript.DrawingTools;
                #endregion
                
                //This namespace holds strategies in this folder and is required. Do not change it.
                namespace NinjaTrader.NinjaScript.Strategies
                {
                public class SampleMACrossOver : Strategy
                {
                private SMA smaFast;
                private SMA smaSlow;
                
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
                Name = NinjaTrader.Custom.Resource.NinjaScriptStrategyNam eSampleMACrossOver;
                Fast = 10;
                Slow = 25;
                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                // See the Help Guide for additional information
                IsInstantiatedOnEachOptimizationIteration = false;
                }
                else if (State == State.DataLoaded)
                {
                smaFast = SMA(Fast);
                smaSlow = SMA(Slow);
                
                smaFast.Plots[0].Brush = Brushes.Goldenrod;
                smaSlow.Plots[0].Brush = Brushes.SeaGreen;
                
                AddChartIndicator(smaFast);
                AddChartIndicator(smaSlow);
                }
                }
                
                protected override void OnBarUpdate()
                {
                if (CurrentBar < BarsRequiredToTrade)
                return;
                
                if (CrossAbove(smaFast, smaSlow, 1))
                EnterLong();
                else if (CrossBelow(smaFast, smaSlow, 1))
                EnterShort();
                }
                
                #region Properties
                [Range(1, int.MaxValue), NinjaScriptProperty]
                [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
                public int Fast
                { get; set; }
                
                [Range(1, int.MaxValue), NinjaScriptProperty]
                [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
                public int Slow
                { get; set; }
                #endregion
                }
                }

                What I don't understand and can't find explicit documentation explaining it:

                What's the use of private ?
                Do I need it to use the VOLMA?
                Code:
                private SMA smaFast;

                What's the use of what's between #region and #endregion?
                Do I need if to use the VOLMA?

                Code:
                 #region Properties
                [Range(1, int.MaxValue), NinjaScriptProperty]
                [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
                public int Fast
                { get; set; }
                
                [Range(1, int.MaxValue), NinjaScriptProperty]
                [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
                public int Slow
                { get; set; }
                #endregion
                The VolumeUpDown code part I customized:
                Code:
                 protected override void OnBarUpdate()
                {
                if (VOL()[0] >= VOLMA(10)[1])
                {
                PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\BogartClear.wav");
                }
                
                if (Close[0] >= Open[0])
                {
                UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
                DownVolume.Reset();
                }
                else
                {
                UpVolume.Reset();
                DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
                }
                }
                Here's my Custom full VolumeUpDown indicator:

                Code:
                //
                // Copyright (C) 2020, NinjaTrader LLC <www.ninjatrader.com>.
                // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
                //
                #region Using declarations
                using System;
                using System.Collections.Generic;
                using System.ComponentModel;
                using System.ComponentModel.DataAnnotations;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;
                using System.Windows;
                using System.Windows.Input;
                using System.Windows.Media;
                using System.Xml.Serialization;
                using NinjaTrader.Cbi;
                using NinjaTrader.Gui;
                using NinjaTrader.Gui.Chart;
                using NinjaTrader.Gui.SuperDom;
                using NinjaTrader.Data;
                using NinjaTrader.NinjaScript;
                using NinjaTrader.Core.FloatingPoint;
                using NinjaTrader.NinjaScript.DrawingTools;
                #endregion
                
                //This namespace holds Indicators in this folder and is required. Do not change it.
                namespace NinjaTrader.NinjaScript.Indicators
                {
                public class VolumeUpDown_Alert : Indicator
                {
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Name = "VolumeUpDown_Alert";
                Calculate = Calculate.OnBarClose;
                DrawOnPricePanel = false;
                IsOverlay = false;
                IsSuspendedWhileInactive = true;
                
                AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeUp);
                AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeDown);
                AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
                }
                else if (State == State.Historical)
                {
                if (Calculate == Calculate.OnPriceChange)
                {
                Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnPriceChangeError, Name), TextPosition.BottomRight);
                Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnPriceChangeError, Name), LogLevel.Error);
                }
                }
                }
                
                protected override void OnBarUpdate()
                {
                if (VOL()[0] >= VOLMA(10)[1])
                {
                PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\BogartClear.wav");
                }
                
                if (Close[0] >= Open[0])
                {
                UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
                DownVolume.Reset();
                }
                else
                {
                UpVolume.Reset();
                DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
                }
                }
                
                #region Properties
                [Browsable(false)]
                [XmlIgnore]
                public Series<double> DownVolume
                {
                get { return Values[1]; }
                }
                
                [Browsable(false)]
                [XmlIgnore]
                public Series<double> UpVolume
                {
                get { return Values[0]; }
                }
                #endregion
                }
                }
                
                #region NinjaScript generated code. Neither change nor remove.
                
                namespace NinjaTrader.NinjaScript.Indicators
                {
                public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                {
                private VolumeUpDown_Alert[] cacheVolumeUpDown_Alert;
                public VolumeUpDown_Alert VolumeUpDown_Alert()
                {
                return VolumeUpDown_Alert(Input);
                }
                
                public VolumeUpDown_Alert VolumeUpDown_Alert(ISeries<double> input)
                {
                if (cacheVolumeUpDown_Alert != null)
                for (int idx = 0; idx < cacheVolumeUpDown_Alert.Length; idx++)
                if (cacheVolumeUpDown_Alert[idx] != null && cacheVolumeUpDown_Alert[idx].EqualsInput(input))
                return cacheVolumeUpDown_Alert[idx];
                return CacheIndicator<VolumeUpDown_Alert>(new VolumeUpDown_Alert(), input, ref cacheVolumeUpDown_Alert);
                }
                }
                }
                
                namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
                {
                public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
                {
                public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert()
                {
                return indicator.VolumeUpDown_Alert(Input);
                }
                
                public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert(ISeries<double> input )
                {
                return indicator.VolumeUpDown_Alert(input);
                }
                }
                }
                
                namespace NinjaTrader.NinjaScript.Strategies
                {
                public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                {
                public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert()
                {
                return indicator.VolumeUpDown_Alert(Input);
                }
                
                public Indicators.VolumeUpDown_Alert VolumeUpDown_Alert(ISeries<double> input )
                {
                return indicator.VolumeUpDown_Alert(input);
                }
                }
                }
                
                #endregion

                The ouput on attached screenshot doesn't plot:



                What to do to make the VOLMA method work?

                How to make it work for the OnEachTick calculation?

                Thanks a lot.
                Attached Files

                Comment


                  #9
                  Hello Dougtre, thanks for your reply.

                  There is documentation here on how to set up an indicator within a host script:


                  Here are the important sections from SampleMACrossover to note:

                  Code:
                  //This namespace holds strategies in this folder and  is required. Do not change it.
                  namespace NinjaTrader.NinjaScript.Strategies
                  {
                      public class SampleMACrossOver : Strategy
                      {
                  [B]private SMA smaFast;
                          private SMA smaSlow;[/B]
                          protected override void OnStateChange()
                          {
                              if (State == State.SetDefaults)
                              {
                                  Description = NinjaTrader.Custom.R esource.NinjaScriptStrategyDescriptionSampleMACros sOver;
                                  Name        = NinjaTrader.Custom.R esource.NinjaScriptStrategyNameSampleMACrossOver;
                                  Fast        = 10;
                                  Slow        = 25;
                                  // This strategy has been designed to take advantage  of performance gains in Strategy Analyzer optimiz ations
                                  // See the Help Guide for additional information
                                  IsInstantiatedOnEachOptimizationIt eration = false;
                              }
                              else if (State == State.DataLoaded)
                              {
                  [B]smaFast = SMA(Fast);
                                  smaSlow = SMA(Slow);[/B]
                                  smaFast.Plots[0].Brush = Brushes.Goldenrod;
                                  smaSlow.Plots[0].Brush = Brushes.SeaGreen;
                                  AddChartIndicator(smaFast);
                                  AddChartIndicator(smaSlow);
                              }
                          }
                          protected override void OnBarUpdate()
                          {
                              if (CurrentBar < BarsRequiredToTrade)
                                  return;
                  [B]if (CrossAbove(smaFast, smaSlow, 1))[/B]
                                  EnterLong();
                  [B]else if (CrossBelow(smaFast, smaSlow,  1))[/B]
                                  EnterShort();
                          }
                          #region Properties
                          [Range(1, int.MaxValue), NinjaScriptProperty]
                          [Display(ResourceType = typeof(Custom.Resource), Na me = "Fast", GroupName = "NinjaScriptStrategyParam eters", Order = 0)]
                          public int Fast
                          { get; set; }
                          [Range(1, int.MaxValue), NinjaScriptProperty]
                          [Display(ResourceType = typeof(Custom.Resource), Na me = "Slow", GroupName = "NinjaScriptStrategyParam eters", Order = 1)]
                          public int Slow
                          { get; set; }
                          #endregion
                      }
                  }
                  "What's the use of private ?"

                  Private access means only the class that contains the property can see the property. This is called an Access modifier:
                  All types and type members in C# have an accessibility level that controls whether they can be used from other code. Review this list of access modifiers.


                  "What's the use of what's between #region and #endregion?"

                  Regions are for organizing the code itself, it has not effect on the running code. It simply groups code segments into user-defined regions. They are not required at all.

                  On the VolumeUpDown_Alert modification:

                  When something unexpected happens with a script, always check the Log tab of the Control Center for runtime errors. In this case you are getting a bars ago problem because you are checking VOL()[0] >= VOLMA(10)[1]

                  So when CurrentBar ==0, it causes a problem because there is not 1 bar to look back on. Addin a CurrentBarCheck at the top of OnBarUpdate fixes the problem:


                  Code:
                  protected override void OnBarUpdate()
                  {
                  if(CurrentBar < 1)
                  return;
                  
                  if (VOL()[0] >= VOLMA(10)[1])
                  {
                  Print("VOL()[0] >= VOLMA(10)[1]"); //Print methods can be useful to tell if a piece of code is being reached. 
                  //PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\BogartClear.wav");
                  }
                  
                  //...
                  Please let me know if I can assist any further.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    That's working now. Thanks a lot Chris.

                    Last question:
                    In the code below:
                    Code:
                    if (VOL()[0] >= VOLMA(10)[1])
                    What does the [1] index of the VOLMA means?
                    Does it mean the average takes the 10 bars starting from the immediate bar previous to the current bar (bar 0)? From bars '-1' to bar '-10'?

                    For example:
                    If current bar is 10:10 am, on the 1 minute chart, then

                    VOLMA(10)[1]
                    averages the volumes values from bar 10:09 am to 9:59 am?

                    If instead I input a 2 VOLMA(10)[2], then it would start from 10:08 am to 9:58 am?

                    Thanks.



                    Extraneous request:
                    How did you preserve the C# formatting when pasting your code in your latest answer?

                    Is there a way to highlight/ color code the C# syntax in the advanced editor?
                    if not, can the Support team add it to the advanced editor:
                    Would help efficency and readability and save time and energy in search:
                    https://stackoverflow.com/questions/...hting-text-box


                    Thanks a lot.
                    Last edited by Dougtre; 10-08-2020, 01:06 PM.

                    Comment


                      #11
                      Hello Dougtre, thanks for your reply.

                      When you index like this VOLMA(10)[1] it means you are requesting the VOLMA excluding the current bar (bar 0). So this VOLMA call will take the average volume of bars 1 through 10. Doing VOLMA(10)[0] would take the average volume from bars 0 to 9.

                      We had an issue with the forum a few months ago that caused the code formatting to get messed up. I have already requested we fix this ASAP. I like to use PasteBin when formatting and coloring are needed:

                      Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


                      Kind regards.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Ok Thanks for the explanation.

                        Stackoverflow use highlight.js from sep 10th
                        In a code fragment like the following ... class Foo { internal Foo() { for (int i = 0; i &lt; 42; ++i); } } ... its various keywords and so on are color-coded...

                        Update 2020-09-24 This is now live network-wide. Update This is now live on Meta Stack Exchange and Meta Stack Overflow. Any bugs and feedback can be posted here as an answer. I&#8217;m Ben and I&#8217;m a de...


                        Others:

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Austiner87, Today, 05:02 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post Austiner87  
                        Started by tonynt, 05-21-2019, 06:27 AM
                        10 responses
                        530 views
                        1 like
                        Last Post fiendtrades  
                        Started by awwenzovs, Today, 08:03 AM
                        2 responses
                        14 views
                        0 likes
                        Last Post NinjaTrader_Eduardo  
                        Started by Ashkam, 04-29-2024, 09:28 AM
                        4 responses
                        44 views
                        0 likes
                        Last Post Ashkam
                        by Ashkam
                         
                        Started by nightstalker, Yesterday, 02:05 PM
                        1 response
                        30 views
                        0 likes
                        Last Post NinjaTrader_Eduardo  
                        Working...
                        X