Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting errors trying to compile using MAX and MIN

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

    Getting errors trying to compile using MAX and MIN

    So I get the following errors when trying to compile this indicator I am trying to build. At the core of it, I just want this indicator to draw a line across the top and bottom of the prices in a specified period creating a range. Once I get the bones of this worked out I would like to refine it further, but this is the first step. Can you help me understand how to fix this?

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class RangeDefiner : Indicator
    {
    private Series<double> highPrice;
    private Series<double> lowPrice;
    private double rangeHigh = 0.0;
    private double rangeLow = 0.0;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"An indicator to find and define price ranges on a chart.";
    Name = "RangeDefiner";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    RangePeriod = 10;
    AddPlot(Brushes.Green, "RangeHigh");
    AddPlot(Brushes.Red, "RangeLow");
    }
    else if (State == State.DataLoaded)
    {
    // Initialize the high and low price data series
    highPrice = new Series<double>(this, MaximumBarsLookBack.Infinite);
    lowPrice = new Series<double>(this, MaximumBarsLookBack.Infinite);
    }
    }

    protected override void OnBarUpdate()
    {

    // Get the highest and lowest prices for the specified period
    double rangeHigh = MAX(RangePeriod)[0];
    double rangeLow = MIN(RangePeriod)[0];

    // RangeHigh = rangeHigh;
    // RangeLow = rangeLow;

    }

    region Properties

    [NinjaScriptProperty]
    [Range(0, double.MaxValue)]
    [Display(Name="RangePeriod", Order=0, GroupName="Parameters")]
    public double RangePeriod
    { get; set; }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> RangeHigh
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> RangeLow
    {
    get { return Values[1]; }
    }
    #endregion

    }
    }


    #2
    Hello RaygunWIzzle,

    Thank you for your post.

    MAX and MIN both take an int value for the period, though it looks like RangePeriod that you are using from the input is a double:

    [NinjaScriptProperty]
    [Range(0, double.MaxValue)]
    [Display(Name="RangePeriod", Order=0, GroupName="Parameters")]
    public double RangePeriod
    { get; set; }

    If you plan to use RangePeriod as the period value in the MAX and MIN indicator methods, you will need to change it to be of type int rather than double. This should resolve the error.

    Please let us know if we may be of further assistance.​

    Comment

    Latest Posts

    Collapse

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