#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
{
public class DMExp : Indicator
{
private Series<double> dmPlus;
private Series<double> dmMinus;
private Series<double> tr;
private Series<double> avgTR;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "DMExp";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
Period = 14;
AddPlot(Brushes.Green, "DIPlus");
AddPlot(Brushes.Red, "DIMinus");
}
else if (State == State.Configure)
{
dmPlus = new Series<double>(this);
dmMinus = new Series<double>(this);
tr = new Series<double>(this);
avgTR = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
double trueRange = Math.Max(Math.Max(High[0] - Low[0], High[0] - Close[1]), Close[1] - Low[0]);
if (CurrentBar == 0)
{
tr[0] = 0;
dmPlus[0] = 0;
dmMinus[0] = 0;
DIPlus[0] = 0;
DIMinus[0] = 0;
avgTR[0] = 0;
}
else
{
tr[0] = trueRange;
dmPlus[0] = High[0] - High[1] > Low[1] - Low[0] ? Math.Max(High[0] - High[1], 0) : 0;
dmMinus[0] = Low[1] - Low[0] > High[0] - High[1] ? Math.Max(Low[1] - Low[0], 0) : 0;
if (CurrentBar < Period)
{
DIPlus[0] = DIPlus[1] + dmPlus[0];
DIMinus[0] = DIMinus[1] + dmMinus[0];
avgTR[0] = 0.5 * (avgTR[1] + tr[0]);
}
else
{
avgTR[0] = (double) EMA(tr,Period)[0];
DIPlus[0] = 100 * (double) EMA(dmPlus,Period)[0] / avgTR[0];
DIMinus[0] = 100 * (double) EMA(dmMinus,Period)[0] / avgTR[0];
}
}
}
#region Properties
[Range(1, int.MaxValue)]
[NinjaScriptProperty]
[Display(Name="Period", Order=1, GroupName="Parameters")]
public int Period
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> DIPlus
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> DIMinus
{
get { return Values[1]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private DMExp[] cacheDMExp;
public DMExp DMExp(int period)
{
return DMExp(Input, period);
}
public DMExp DMExp(ISeries<double> input, int period)
{
if (cacheDMExp != null)
for (int idx = 0; idx < cacheDMExp.Length; idx++)
if (cacheDMExp[idx] != null && cacheDMExp[idx].Period == period && cacheDMExp[idx].EqualsInput(input))
return cacheDMExp[idx];
return CacheIndicator<DMExp>(new DMExp(){ Period = period }, input, ref cacheDMExp);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.DMExp DMExp(int period)
{
return indicator.DMExp(Input, period);
}
public Indicators.DMExp DMExp(ISeries<double> input , int period)
{
return indicator.DMExp(input, period);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.DMExp DMExp(int period)
{
return indicator.DMExp(Input, period);
}
public Indicators.DMExp DMExp(ISeries<double> input , int period)
{
return indicator.DMExp(input, period);
}
}
}
#endregion
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Custom Indicator Not Using Price Data (NT8)
Collapse
X
-
Custom Indicator Not Using Price Data (NT8)
I have created a custom indicator to calculate DI+ and DI- using an EMA instead of a SMA and when I apply the indicator to my chart nothing shows up and where it would otherwise say "DMExp(ES 06-16 (15 Minute), 14)", for example, the screen just shows "DMExp(14)". I am attaching a screenshot of the chart as well as pasting the code below. Can someone please tell me what I'm doing wrong?
Code:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
574 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
333 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment