![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Aug 2009
Posts: 289
Thanks: 0
Thanked 2 times in 2 posts
|
I just tried to save a workspace that included a version of DM I had written to include a third line instead of just the 2 drawn lines it supplied.
It compiles and charts OK, but trying to save the workspace gives the error The Indicator DMmine could not be serialized and to look at Help, but I cant find serialized in any search. What does it mean? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
Go back into any indicator and try to compile it. Do you get any errors? Are you on a network server?
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Aug 2009
Posts: 289
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
I do use a router, but why this one indicator? HTML Code:
// // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>. // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release. // #region Using declarations using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; using System.Xml.Serialization; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// Directional Movement (DMmine). This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside. /// </summary> [Description("This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside.")] public class DMmine : Indicator { #region Variables private int period = 14; private DataSeries dmPlus; private DataSeries dmMinus; private DataSeries sumDmPlus; private DataSeries sumDmMinus; private DataSeries sumTr; private DataSeries tr; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(new Pen(Color.Black, 3), "ADX")); Add(new Plot(Color.Green, "+DI")); Add(new Plot(Color.Red, "-DI")); Add(new Line(Color.Black, 20, "20")); Add(new Line(Color.Blue, 25, "25")); Add(new Line(Color.Crimson, 30, "30")); dmPlus = new DataSeries(this); dmMinus = new DataSeries(this); sumDmPlus = new DataSeries(this); sumDmMinus = new DataSeries(this); sumTr = new DataSeries(this); tr = new DataSeries(this); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double trueRange = High[0] - Low[0]; if (CurrentBar == 0) { tr.Set(trueRange); dmPlus.Set(0); dmMinus.Set(0); sumTr.Set(tr[0]); sumDmPlus.Set(dmPlus[0]); sumDmMinus.Set(dmMinus[0]); Value.Set(50); } else { tr.Set(Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])))); dmPlus.Set(High[0] - High[1] > Low[1] - Low[0] ? Math.Max(High[0] - High[1], 0) : 0); dmMinus.Set(Low[1] - Low[0] > High[0] - High[1] ? Math.Max(Low[1] - Low[0], 0) : 0); if (CurrentBar < Period) { sumTr.Set(sumTr[1] + tr[0]); sumDmPlus.Set(sumDmPlus[1] + dmPlus[0]); sumDmMinus.Set(sumDmMinus[1] + dmMinus[0]); } else { sumTr.Set(sumTr[1] - sumTr[1] / Period + tr[0]); sumDmPlus.Set(sumDmPlus[1] - sumDmPlus[1] / Period + dmPlus[0]); sumDmMinus.Set(sumDmMinus[1] - sumDmMinus[1] / Period + dmMinus[0]); } double diPlus = 100 * (sumTr[0] == 0 ? 0 : sumDmPlus[0] / sumTr[0]); double diMinus = 100 * (sumTr[0] == 0 ? 0 : sumDmMinus[0] / sumTr[0]); double diff = Math.Abs(diPlus - diMinus); double sum = diPlus + diMinus; Value.Set(sum == 0 ? 50 : ((Period - 1) * Value[1] + 100 * diff / sum) / Period); DiPlus.Set(diPlus); DiMinus.Set(diMinus); } } #region Properties /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries DiPlus { get { return Values[1]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries DiMinus { get { return Values[2]; } } /// <summary> /// </summary> [Description("Numbers of bars used for calculations")] [Category("Parameters")] public int Period { get { return period; } set { period = Math.Max(1, value); } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private DMmine[] cacheDMmine = null; private static DMmine checkDMmine = new DMmine(); /// <summary> /// This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside. /// </summary> /// <returns></returns> public DMmine DMmine(int period) { return DMmine(Input, period); } /// <summary> /// This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside. /// </summary> /// <returns></returns> public DMmine DMmine(Data.IDataSeries input, int period) { checkDMmine.Period = period; period = checkDMmine.Period; if (cacheDMmine != null) for (int idx = 0; idx < cacheDMmine.Length; idx++) if (cacheDMmine[idx].Period == period && cacheDMmine[idx].EqualsInput(input)) return cacheDMmine[idx]; DMmine indicator = new DMmine(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; indicator.Input = input; indicator.Period = period; indicator.SetUp(); DMmine[] tmp = new DMmine[cacheDMmine == null ? 1 : cacheDMmine.Length + 1]; if (cacheDMmine != null) cacheDMmine.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheDMmine = tmp; Indicators.Add(indicator); return indicator; } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// <summary> /// This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside. /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.DMmine DMmine(int period) { return _indicator.DMmine(Input, period); } /// <summary> /// This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside. /// </summary> /// <returns></returns> public Indicator.DMmine DMmine(Data.IDataSeries input, int period) { return _indicator.DMmine(input, period); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside. /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.DMmine DMmine(int period) { return _indicator.DMmine(Input, period); } /// <summary> /// This is the same indicator as the ADX, with the addition of the two directional movement indicators +DI and -DI. +DI and -DI measure upward and downward momentum. A buy signal is generated when +DI crosses -DI to the upside. A sell signal is generated when -DI crosses +DI to the downside. /// </summary> /// <returns></returns> public Indicator.DMmine DMmine(Data.IDataSeries input, int period) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.DMmine(input, period); } } } #endregion |
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Have you tried changing both dataseries properties to Values[0] / Values[1]?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Aug 2009
Posts: 289
Thanks: 0
Thanked 2 times in 2 posts
|
It saved OK when i did shut down. The onlything I did in between was pull up a minimized FESX chart with the indicator on it also (the other chart was ES). The FESX indicator hadnt been set to calculate on bar close so I reset it that way, and later when I shut down i was ok. Maybe that was it.
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
simpletrades, since you have two plots only, you would have Values[0] and Values[1] being used -
Code:
[Browsable(false)]
[XmlIgnore()]
public DataSeries DiPlus
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries DiMinus
{
get { return Values[1]; }
}
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| we need indicators !!! | Elmi | Indicator Development | 77 | 07-25-2012 10:15 AM |
| Custom Indicators calling other Custom Indicators | DancesWithBears | Indicator Development | 6 | 08-21-2009 12:19 PM |
| Help with indicators | muna580 | Charting | 5 | 04-22-2009 10:50 AM |
| Charting indicators using other indicators as the input | Elliott Wave | Charting | 3 | 04-04-2008 03:54 PM |
| Indicators | michaeldavidmiller@comcas | ATM Strategies (Discretionary Trading) | 1 | 01-13-2008 01:52 AM |