Announcement

Collapse
No announcement yet.

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.

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      646 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      367 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      570 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X