//Vers. 0.1 translated by Gumphrie //dots added by RB of TTT #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 { /// /// Trigger Lines /// [Description("Trigger Lines.")] [Gui.Design.DisplayName("Trigger Lines")] public class TriggerLines : Indicator { #region Variables private int length = 20; //80; //20; private int trigAvg = 8; //5; //8; private DataSeries value1; private DataSeries value2; private bool bTrigWasRising = false; #endregion /// /// This method is used to configure the indicator and is called once before any bar data is loaded. /// protected override void Initialize() { Add(new Plot(Color.Cyan, "Plot1_Up")); Add(new Plot(Color.Magenta, "Plot1_Dn")); Add(new Plot(Color.Cyan, "Plot2_Up")); Add(new Plot(Color.Magenta, "Plot2_Dn")); Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Dot, "CloseUp")); Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Dot, "CloseDn")); value1 = new DataSeries(this); value2 = new DataSeries(this); Overlay = true; PriceTypeSupported = true; BarsRequired = length+trigAvg; } /// /// Calculates the indicator value(s) at the current index. /// protected override void OnBarUpdate() { value1.Set(LinReg(base.Input,length)[0]); value2.Set(EMA(value1,trigAvg)[0]); if (value2[0]>=value1[0]) { if (bTrigWasRising) { Plot1_Up.Set(value1[0]); Plot2_Up.Set(value2[0]); } Plot1_Dn.Set(value1[0]); Plot2_Dn.Set(value2[0]); bTrigWasRising = false; } else { if (!bTrigWasRising) { Plot1_Dn.Set(value1[0]); Plot2_Dn.Set(value2[0]); } Plot1_Up.Set(value1[0]); Plot2_Up.Set(value2[0]); bTrigWasRising = true; } if (Close[0] > value1[0] && Close[0] > value2[0]) CloseUp.Set(Close[0]); if ( Close[0] < value1[0] && Close[0] > value2[0]) CloseUp.Set(Close[0]); if (Close[0] < value1[0] && Close[0] < value2[0]) CloseDn.Set(Close[0]); if ( Close[0] > value1[0] && Close[0] < value2[0]) CloseDn.Set(Close[0]); } #region Properties /// /// [Browsable(false)] [XmlIgnore()] public DataSeries Plot1_Up { get { return Values[0]; } } /// /// [Browsable(false)] [XmlIgnore()] public DataSeries Plot1_Dn { get { return Values[1]; } } /// /// [Browsable(false)] [XmlIgnore()] public DataSeries Plot2_Up { get { return Values[2]; } } /// /// [Browsable(false)] [XmlIgnore()] public DataSeries Plot2_Dn { get { return Values[3]; } } /// /// [Browsable(false)] [XmlIgnore()] public DataSeries CloseUp { get { return Values[4]; } } /// /// [Browsable(false)] [XmlIgnore()] public DataSeries CloseDn { get { return Values[5]; } } /// /// [Description("Period")] [Category("Parameters")] public int Period { get { return length; } set { length = Math.Max(1, value); } } /// /// [Description("Trigger Average")] [Category("Parameters")] public int TrigAvg { get { return trigAvg; } set { trigAvg = 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 TriggerLines[] cacheTriggerLines = null; private static TriggerLines checkTriggerLines = new TriggerLines(); /// /// Trigger Lines. /// /// public TriggerLines TriggerLines(int period, int trigAvg) { return TriggerLines(Input, period, trigAvg); } /// /// Trigger Lines. /// /// public TriggerLines TriggerLines(Data.IDataSeries input, int period, int trigAvg) { if (cacheTriggerLines != null) for (int idx = 0; idx < cacheTriggerLines.Length; idx++) if (cacheTriggerLines[idx].Period == period && cacheTriggerLines[idx].TrigAvg == trigAvg && cacheTriggerLines[idx].EqualsInput(input)) return cacheTriggerLines[idx]; lock (checkTriggerLines) { checkTriggerLines.Period = period; period = checkTriggerLines.Period; checkTriggerLines.TrigAvg = trigAvg; trigAvg = checkTriggerLines.TrigAvg; if (cacheTriggerLines != null) for (int idx = 0; idx < cacheTriggerLines.Length; idx++) if (cacheTriggerLines[idx].Period == period && cacheTriggerLines[idx].TrigAvg == trigAvg && cacheTriggerLines[idx].EqualsInput(input)) return cacheTriggerLines[idx]; TriggerLines indicator = new TriggerLines(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; indicator.TrigAvg = trigAvg; Indicators.Add(indicator); indicator.SetUp(); TriggerLines[] tmp = new TriggerLines[cacheTriggerLines == null ? 1 : cacheTriggerLines.Length + 1]; if (cacheTriggerLines != null) cacheTriggerLines.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheTriggerLines = tmp; 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 { /// /// Trigger Lines. /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.TriggerLines TriggerLines(int period, int trigAvg) { return _indicator.TriggerLines(Input, period, trigAvg); } /// /// Trigger Lines. /// /// public Indicator.TriggerLines TriggerLines(Data.IDataSeries input, int period, int trigAvg) { return _indicator.TriggerLines(input, period, trigAvg); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// /// Trigger Lines. /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.TriggerLines TriggerLines(int period, int trigAvg) { return _indicator.TriggerLines(Input, period, trigAvg); } /// /// Trigger Lines. /// /// public Indicator.TriggerLines TriggerLines(Data.IDataSeries input, int period, int trigAvg) { 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.TriggerLines(input, period, trigAvg); } } } #endregion