Thera are two sma's, high and low. I want the space between thems to be filled with color.
Unfortunatelly this functionality doesn't work.
I am not a programmer, I would be gratefull if someone could fix this code.

#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
namespace NinjaTrader.NinjaScript.Indicators
{
public class TwoSmaHighLowIndicator : Indicator
{
private SMA smaHigh;
private SMA smaLow;
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="SMA Period for High", Order=1, GroupName="Parameters")]
public int PeriodHigh { get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="SMA Period for Low", Order=2, GroupName="Parameters")]
public int PeriodLow { get; set; }
[XmlIgnore]
[Display(Name="Fill Color", Order=3, GroupName="Parameters")]
public Brush FillColor { get; set; }
[Browsable(false)]
public string FillColorSerializable
{
get { return Serialize.BrushToString(FillColor); }
set { FillColor = Serialize.StringToBrush(value); }
}
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Indicator drawing two SMA moving averages based on High and Low prices and filling the area between them with a color.";
Name = "TwoSmaHighLowIndicator";
Calculate = Calculate.OnEachTick; // Ensure the indicator works on each tick
IsOverlay = true;
// Default periods for SMA
PeriodHigh = 14;
PeriodLow = 14;
// Default fill color
FillColor = Brushes.LightBlue;
// Adding plot lines
AddPlot(Brushes.Blue, "SMA High");
AddPlot(Brushes.Red, "SMA Low");
}
else if (State == State.DataLoaded)
{
smaHigh = SMA(High, PeriodHigh);
smaLow = SMA(Low, PeriodLow);
}
}
protected override void OnBarUpdate()
{
// Ensure there are enough bars for calculations
if (CurrentBar < Math.Max(PeriodHigh, PeriodLow))
return;
// Setting values for SMA
Values[0][0] = smaHigh[0];
Values[1][0] = smaLow[0];
// Filling the area between SMAs
// Drawing the area from the previous bar to the current one
Draw.Region(this, "Region" + CurrentBar, CurrentBar - 1, CurrentBar, smaHigh, smaLow, FillColor, FillColor, 0);
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> SmaHigh
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> SmaLow
{
get { return Values[1]; }
}
#endregion
}
}

Comment