The Up Down bars plot perfectly, but for some reason, the EMA AvgVol plot doesn't show. I cut and pasted code from VolumeUpDown and VOLMA to come up with the sutured indicator. If anyone can take a peek at the source and thell me what I'm doing wrong, it would be greatly appreciated. I'm a trader and not a programmer, though I probably know just enough to get into trouble as is the case here. I know that I can just put the two base indicators on a chart and drag and drop to get the same result, but like I said, this is a heuristic exercise.
Thanks in advance for any pointers.
//
//
//
#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.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// This Indicator plots colored Up & Down Volume Bars and an Exponential Moving Average (EMA) of Volume.
/// </summary>
public class LynxVolUpDownAvg : Indicator
{
private EMA AvgVol;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "LynxVolUpDownAvg";
Description = @"LynxVolUpDownAvg Indicator plots colored Up & Down Volume Bars and an Exponential Moving Average (EMA) of Volume.";
Calculate = Calculate.OnBarClose;
DrawOnPricePanel = false;
IsOverlay = false;
IsSuspendedWhileInactive = true;
Period = 13;
AddPlot(new Stroke(Brushes.Lime, 5), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeUp);
AddPlot(new Stroke(Brushes.Red, 5), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeDown);
AddLine(Brushes.White, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);
AddPlot(Brushes.Cyan, "AvgVol");
// AddPlot(new Brushes.Cyan, 1, "ema");
}
else if (State == State.DataLoaded)
AvgVol = EMA(Volume, Period);
else if (State == State.Historical)
{
if (Calculate == Calculate.OnPriceChange)
{
Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScriptOnPriceChangeError, Name), TextPosition.BottomRight);
Log(string.Format(NinjaTrader.Custom.Resource.NinjaScriptOnPriceChangeError, Name), LogLevel.Error);
}
}
}
protected override void OnBarUpdate()
{
//
///Add your custom indicator logic here.
//
Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)AvgVol[0]) : AvgVol[0];
if (Close[0] >= Open[0])
{
UpVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
DownVolume.Reset();
}
else
{
UpVolume.Reset();
DownVolume[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
}
}
#region Properties
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
public int Period
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> DownVolume
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> UpVolume
{
get { return Values[0]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private LynxVolUpDownAvg[] cacheLynxVolUpDownAvg;
public LynxVolUpDownAvg LynxVolUpDownAvg(int period)
{
return LynxVolUpDownAvg(Input, period);
}
public LynxVolUpDownAvg LynxVolUpDownAvg(ISeries<double> input, int period)
{
if (cacheLynxVolUpDownAvg != null)
for (int idx = 0; idx < cacheLynxVolUpDownAvg.Length; idx++)
if (cacheLynxVolUpDownAvg[idx] != null && cacheLynxVolUpDownAvg[idx].Period == period && cacheLynxVolUpDownAvg[idx].EqualsInput(input))
return cacheLynxVolUpDownAvg[idx];
return CacheIndicator<LynxVolUpDownAvg>(new LynxVolUpDownAvg(){ Period = period }, input, ref cacheLynxVolUpDownAvg);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.LynxVolUpDownAvg LynxVolUpDownAvg(int period)
{
return indicator.LynxVolUpDownAvg(Input, period);
}
public Indicators.LynxVolUpDownAvg LynxVolUpDownAvg(ISeries<double> input , int period)
{
return indicator.LynxVolUpDownAvg(input, period);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.LynxVolUpDownAvg LynxVolUpDownAvg(int period)
{
return indicator.LynxVolUpDownAvg(Input, period);
}
public Indicators.LynxVolUpDownAvg LynxVolUpDownAvg(ISeries<double> input , int period)
{
return indicator.LynxVolUpDownAvg(input, period);
}
}
}
#endregion

Comment