I created an indicator with the following code, but when I clickSave as Default, it says there is an error generating XLM document and I can’t save the settings. Also, when I restart NinjaTrader, this indicator is the only one that doesn’t save automatically. Which part of the code could be causing this issue?
using System;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.Data;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript.Strategies;
using System.Windows.Media;
using NinjaTrader.NinjaScript.DrawingTools;
namespace NinjaTrader.NinjaScript.Indicators
{
public class _EMA : Indicator
{
private EMA fastEMA;
private EMA slowEMA;
[NinjaScriptProperty]
public int FastPeriod { get; set; } = 5;
[NinjaScriptProperty]
public int SlowPeriod { get; set; } = 10;
[NinjaScriptProperty]
public Brush BullishColor { get; set; } = Brushes.Gold;
[NinjaScriptProperty]
public Brush BearishColor { get; set; } = Brushes.White;
// New property for arrow size
[NinjaScriptProperty]
public double ArrowSize { get; set; } = 100; // Default size value
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Indicator to mark EMA crossovers with arrows";
AddPlot(Brushes.Silver, "_EMA");
}
else if (State == State.DataLoaded)
{
fastEMA = EMA(FastPeriod);
slowEMA = EMA(SlowPeriod);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < Math.Max(FastPeriod, SlowPeriod)) return;
// Use the ArrowSize property for adjustable arrow size
double arrowOffset = TickSize * ArrowSize;
if (CrossAbove(fastEMA, slowEMA, 1))
{
// Draw an up arrow for Bullish Cross
Draw.ArrowUp(this, "BullishCross" + CurrentBar, false, 0, Low[0] - arrowOffset, BullishColor);
}
else if (CrossBelow(fastEMA, slowEMA, 1))
{
// Draw a down arrow for Bearish Cross
Draw.ArrowDown(this, "BearishCross" + CurrentBar, false, 0, High[0] + arrowOffset, BearishColor);
}
}
}
}
region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private _EMA[] cache_EMA;
public _EMA _EMA(int fastPeriod, int slowPeriod, Brush bullishColor, Brush bearishColor, double arrowSize)
{
return _EMA(Input, fastPeriod, slowPeriod, bullishColor, bearishColor, arrowSize);
}
public _EMA _EMA(ISeries<double> input, int fastPeriod, int slowPeriod, Brush bullishColor, Brush bearishColor, double arrowSize)
{
if (cache_EMA != null)
for (int idx = 0; idx < cache_EMA.Length; idx++)
if (cache_EMA[idx] != null && cache_EMA[idx].FastPeriod == fastPeriod && cache_EMA[idx].SlowPeriod == slowPeriod && cache_EMA[idx].BullishColor == bullishColor && cache_EMA[idx].BearishColor == bearishColor && cache_EMA[idx].ArrowSize == arrowSize && cache_EMA[idx].EqualsInput(input))
return cache_EMA[idx];
return CacheIndicator<_EMA>(new _EMA(){ FastPeriod = fastPeriod, SlowPeriod = slowPeriod, BullishColor = bullishColor, BearishColor = bearishColor, ArrowSize = arrowSize }, input, ref cache_EMA);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators._EMA _EMA(int fastPeriod, int slowPeriod, Brush bullishColor, Brush bearishColor, double arrowSize)
{
return indicator._EMA(Input, fastPeriod, slowPeriod, bullishColor, bearishColor, arrowSize);
}
public Indicators._EMA _EMA(ISeries<double> input , int fastPeriod, int slowPeriod, Brush bullishColor, Brush bearishColor, double arrowSize)
{
return indicator._EMA(input, fastPeriod, slowPeriod, bullishColor, bearishColor, arrowSize);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators._EMA _EMA(int fastPeriod, int slowPeriod, Brush bullishColor, Brush bearishColor, double arrowSize)
{
return indicator._EMA(Input, fastPeriod, slowPeriod, bullishColor, bearishColor, arrowSize);
}
public Indicators._EMA _EMA(ISeries<double> input , int fastPeriod, int slowPeriod, Brush bullishColor, Brush bearishColor, double arrowSize)
{
return indicator._EMA(input, fastPeriod, slowPeriod, bullishColor, bearishColor, arrowSize);
}
}
}
#endregion

Comment