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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      83 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      45 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      65 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      57 views
      0 likes
      Last Post CarlTrading  
      Working...
      X