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

PPrint doesn't output?

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

    PPrint doesn't output?

    Hello there,

    I wrote an indicator and stumbled on this. Basically, the Print doesn't generate any output in the Output Window. It should at least output the text "BLARGHH".

    Code is below.

    Many Thanks, Caesar.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        /// <summary>
        /// cmsSqueeze Bands are plotted at standard deviation levels above and below a moving average.
        /// Since standard deviation is a measure of volatility, the bands are self-adjusting:
        /// widening during volatile markets and contracting during calmer periods.
        /// </summary>
        public class cmsSqueeze : Indicator
        {
            private SMA        sma;
            private StdDev    stdDev;
            private double    Avg;
            private double    Shift;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = "cmsSqueeze";
                    Name                        = "cmsSqueeze";
                    IsOverlay                    = true;
                    IsSuspendedWhileInactive    = true;
                    NumStdDev                    = 2;
                    Period                        = 14;
    
                    AddPlot(Brushes.Lime, "Bollinger Upper Band");
                    AddPlot(Brushes.Lime, "Bollinger Middle Band");
                    AddPlot(Brushes.Lime, "Bollinger Lower Band");
    
                    AddPlot(Brushes.DeepSkyBlue, "Keltner Upper Band");
                    AddPlot(Brushes.DeepSkyBlue, "Keltner Lower Band");
    
                }
                else if (State == State.DataLoaded)
                {
                    sma        = SMA(Period);
                    stdDev    = StdDev(Period);
                }
            }
    
            protected override void OnBarUpdate()
            {
                double sma0        = sma[0];
                double stdDev0    = stdDev[0];
    
                // Calculate and plot cmsSqueeze Band
                BUpperBand[0]        = sma0 + NumStdDev * stdDev0;
                BMiddleBand[0]        = sma0;
                BLowerBand[0]        = sma0 - NumStdDev * stdDev0;
    
                // Calculate Keltner Channel
                Avg = SMA( Close, MomentumLength )[0] ;
                Shift = ATRPeriod * ATR( Close, MomentumLength )[0] ;
                KUpperBand[0] = Avg + Shift ;
                KLowerBand[0] = Avg - Shift ;
    
                // If Bollinger bands are inside the ketler channel then alert, get ready for squeeze }
                if ((BUpperBand[0] <= KUpperBand[0]) && (BLowerBand[0] >= KLowerBand[0]))
                {
                    // Now show me the Squeeze }  
                    Print("SQUEEZE");
                    //Squeeze[0] = 0;
                }
                else
                {
                    Print("EXPANSION");
                }
                Print("BLAAARGGHHH");
            }
    
            #region Properties
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> BUpperBand
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> BMiddleBand
            {
                get { return Values[1]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> BLowerBand
            {
                get { return Values[2]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> KUpperBand
            {
                get { return Values[3]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> KLowerBand
            {
                get { return Values[4]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> Squeeze
            {
                get { return Values[5]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public Series<double> Expansion
            {
                get { return Values[6]; }
            }
    
            [Range(0, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "NumStdDev", GroupName = "NinjaScriptParameters", Order = 0)]
            public double NumStdDev
            { get; set; }
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 1)]
            public int Period
            { get; set; }
    
            [Range(1, double.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "ATR Period", GroupName = "NinjaScriptParameters", Order = 2)]
            public double ATRPeriod
            { get; set; }
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Momentum Length", GroupName = "NinjaScriptParameters", Order = 3)]
            public int MomentumLength
            { get; set; }        
            #endregion
        }
    }​

    #2
    Hello Caesar,

    Thank you for your post.

    Do you receive any errors on the screen or on the Log tab of the Control Center? I suspect you may have a message about "Index was out of range" or something similar. You may need to add a check to make sure there are enough bars in the series you are accessing, as described on the following page:


    Please let me know if I may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      I suspect you're right. I did not check bars ago in the method.

      Many Thanks, Caesar.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by SantoshXX, Today, 03:09 AM
      0 responses
      12 views
      0 likes
      Last Post SantoshXX  
      Started by DanielTynera, Today, 01:14 AM
      0 responses
      2 views
      0 likes
      Last Post DanielTynera  
      Started by yertle, 04-18-2024, 08:38 AM
      9 responses
      42 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by techgetgame, Yesterday, 11:42 PM
      0 responses
      14 views
      0 likes
      Last Post techgetgame  
      Started by sephichapdson, Yesterday, 11:36 PM
      0 responses
      2 views
      0 likes
      Last Post sephichapdson  
      Working...
      X