First of all I'm not a coder, though lately I've been playing with ChatGPT with some major successes. Now I'm trying to to fill with a color an area close to the EMA. Those area is determined with ATR. This time I can not handle this one error that keeps popping which says: "Argument 6: cannot convert from 'NinjaTrader.NinjaScript.Series<double> to 'double'.
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript;
using NinjaTrader.Data;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript.DrawingTools;
using System;
using System.Windows.Media;
namespace NinjaTrader.NinjaScript.Indicators
{
public class EMAWithATR : Indicator
{
private Series<double> upperBandSeries;
private Series<double> lowerBandSeries;
[NinjaScriptProperty]
public int EMAPeriod { get; set; } = 14;
[NinjaScriptProperty]
public int ATRLength { get; set; } = 14;
[NinjaScriptProperty]
public double ATRMultiplier { get; set; } = 2.5;
[NinjaScriptProperty]
public Color RegionFillColor { get; set; } = Colors.LightGray;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "EMA with ATR Bands and Region Fill";
Name = "EMAWithATR";
IsOverlay = true;
AddPlot(new SolidColorBrush(Colors.Blue), "EMA");
}
else if (State == State.DataLoaded)
{
upperBandSeries = new Series<double>(this);
lowerBandSeries = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < Math.Max(EMAPeriod, ATRLength))
return;
double emaValue = EMA(EMAPeriod)[0];
double atrValue = ATR(ATRLength)[0];
double upperBand = emaValue + atrValue * ATRMultiplier;
double lowerBand = emaValue - atrValue * ATRMultiplier;
upperBandSeries[0] = upperBand;
lowerBandSeries[0] = lowerBand;
Values[0][0] = emaValue;
if (CurrentBar > 0)
{
Draw.Region(this, "ATRRegion" + CurrentBar, CurrentBar - 1, CurrentBar,
lowerBandSeries, upperBandSeries,
Brushes.Transparent, 50);
}
}
}
}
Is there possibility to set a gradient on this filled area? So that it would start with 100% opacity at the EMA and fade out moving away from it?

Comment