Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trying to convert band distance to a TickSize value

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

    trying to convert band distance to a TickSize value

    i keep getting a CS0120 error on compile - and the error mssgs were different...
    i was trying to change BandWidth from points to ticks - i can't figure out what i need to make it work....

    i tried changing [Range(1, int.MaxValue)]
    to [Range(1, double.MaxValue)]
    but that didn't work - maybe wrong syntax

    i also tried to define a private double bandWidth = 9 * TickSize;
    but i got another different compile error....
    ??
    /wes

    Code:
        public class RangeMedianTicBands : Indicator
        {
            
            private MAX max;
            private MIN min;
            
    
    
        
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "RangeMedianTicBands";
                    Calculate                                    = Calculate.OnPriceChange;
                    IsOverlay                                    = true;
                    IsAutoScale                                    = false;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    IsSuspendedWhileInactive                    = true;
                    Period                                        = 20;
                BandWidth                    = 2;       /// needs to be * TickSize; but getting implicit convert error
    
                    AddPlot(Brushes.Yellow, "TopBand");
                    AddPlot(Brushes.Yellow, "Median");                
                    AddPlot(Brushes.Yellow, "BottomBand");
                }
    
                
                else if (State == State.DataLoaded)
                {
                    max = MAX(High, Period);
                    min    = MIN(Low, Period);
                }            
            }
    
            protected override void OnBarUpdate()
            {
                double max0 = max[0];
                double min0    = min[0];
    
                Median[0]        = (max0 + min0) / 2;
                TopBand[0]        = ((max0 + min0) / 2 + BandWidth);
    
                BottomBand[0]    = ((max0 + min0) / 2 - BandWidth);                        
            }
    
            #region Properties
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="Period", Order=1, GroupName="Parameters")]
            public int Period
            { get; set; }
    
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="BandWidth", Order=2, GroupName="Parameters")]
            public int BandWidth
            { get; set; }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> TopBand
            {
                get { return Values[0]; }
            }        
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> Median
            {
                get { return Values[1]; }
            }
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> BottomBand
            {
                get { return Values[2]; }
            }

    #2
    Hello,

    Thank you for the question.

    To convert how this property is used, you would need to instead change how this is used in OnBarUpdate.

    The public property should already be configured correctly to allow for a number to be entered. How that is related to a number of Ticks would occur in OnBarUpdate:

    Here is one example of converting the Input to a number of Ticks.

    Code:
    TopBand[0]        = ((max0 + min0) / 2 + (BandWidth * TickSize));
    In this case, assuming BandWidth was set to 2 in the user interface, it would be (max0 + min0) / 2 + 2 Ticks.

    I look forward to being of further assistance.

    Comment


      #3
      thanks so much.... i had come across this with NT7 long time ago and couldn't remember - it was so straight forward... TopBand is already a declared double....

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X