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

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.
    JesseNinjaTrader Customer Service

    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 RubenCazorla, Today, 09:07 AM
      2 responses
      13 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by i019945nj, 12-14-2023, 06:41 AM
      7 responses
      82 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by timmbbo, 07-05-2023, 10:21 PM
      4 responses
      158 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by tkaboris, Today, 08:01 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Lumbeezl, 01-11-2022, 06:50 PM
      31 responses
      820 views
      1 like
      Last Post NinjaTrader_Adrian  
      Working...
      X