i am trying to code http://www.stockspotter.com/Files/wh...difference.pdf
so far i have coded :
#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.Gui.Tools; 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 JEMEDIANAVARAGE2005TASC : Indicator { private Series<double> Price; private Series<double> Smooth; private double Value0; private double Value1; private Series<double> Value2; private double Value3; private double alpha; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "JEMEDIANAVARAGE2005TASC"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; Length = 39; Threshold = 0.002; AddPlot(Brushes.DarkKhaki, "JEFilt"); } else if (State == State.Configure) { } } protected override void OnBarUpdate() { //Add your custom indicator logic here. /* Inputs: Price((H+L)/2), Threshold(.002); Vars: Smooth(0), Length(30), alpha(0), Filt(0); Smooth = (Price + 2*Price[1] + 2*Price[2] + Price[3]) / 6; Length = 39; Value3 = .2; While Value3 > Threshold begin alpha = 2 / (Length + 1); Value1 = Median(Smooth, Length); Value2 = alpha*Smooth + (1 - alpha)*Value2[1]; If Value1 <> 0 then Value3 = AbsValue(Value1 - Value2) / Value1; Length = Length - 2; End; If Length < 3 then Length = 3; alpha = 2 / (Length + 1); Filt = alpha*Smooth + (1 - alpha)*Filt[1]; Plot1(Filt);*/ Price[0]=(High[0]+Low[0])/2; Value3 = 0.2; Smooth[0] = (Price[0] + 2*Price[1] + 2*Price[2] + Price[3]) / 6; while (Value3 > Threshold) { alpha = 2 / (Length + 1); Value1 = Median(Smooth, Length)[0]; Value2[0] = alpha*Smooth[0] + (1 - alpha)*Value2[1]; if( Value1 != 0) { Value3 = Abs(Value1 - Value2[0]) / Value1; } Length = Length - 2; } } #region Properties [NinjaScriptProperty] [Range(1, double.MaxValue)] [Display(Name="Length", Order=1, GroupName="Parameters")] public double Length { get; set; } [NinjaScriptProperty] [Range(1E-05, double.MaxValue)] [Display(Name="Threshold", Order=2, GroupName="Parameters")] public double Threshold { get; set; } [Browsable(false)] [XmlIgnore] public Series<double> JEFilt { 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 JEMEDIANAVARAGE2005TASC[] cacheJEMEDIANAVARAGE2005TASC; public JEMEDIANAVARAGE2005TASC JEMEDIANAVARAGE2005TASC(double length, double threshold) { return JEMEDIANAVARAGE2005TASC(Input, length, threshold); } public JEMEDIANAVARAGE2005TASC JEMEDIANAVARAGE2005TASC(ISeries<double> input, double length, double threshold) { if (cacheJEMEDIANAVARAGE2005TASC != null) for (int idx = 0; idx < cacheJEMEDIANAVARAGE2005TASC.Length; idx++) if (cacheJEMEDIANAVARAGE2005TASC[idx] != null && cacheJEMEDIANAVARAGE2005TASC[idx].Length == length && cacheJEMEDIANAVARAGE2005TASC[idx].Threshold == threshold && cacheJEMEDIANAVARAGE2005TASC[idx].EqualsInput(input)) return cacheJEMEDIANAVARAGE2005TASC[idx]; return CacheIndicator<JEMEDIANAVARAGE2005TASC>(new JEMEDIANAVARAGE2005TASC(){ Length = length, Threshold = threshold }, input, ref cacheJEMEDIANAVARAGE2005TASC); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.JEMEDIANAVARAGE2005TASC JEMEDIANAVARAGE2005TASC(double length, double threshold) { return indicator.JEMEDIANAVARAGE2005TASC(Input, length, threshold); } public Indicators.JEMEDIANAVARAGE2005TASC JEMEDIANAVARAGE2005TASC(ISeries<double> input , double length, double threshold) { return indicator.JEMEDIANAVARAGE2005TASC(input, length, threshold); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.JEMEDIANAVARAGE2005TASC JEMEDIANAVARAGE2005TASC(double length, double threshold) { return indicator.JEMEDIANAVARAGE2005TASC(Input, length, threshold); } public Indicators.JEMEDIANAVARAGE2005TASC JEMEDIANAVARAGE2005TASC(ISeries<double> input , double length, double threshold) { return indicator.JEMEDIANAVARAGE2005TASC(input, length, threshold); } } } #endregion
please revert us for the same so that i can calculate this median as ninja based median is calculated on price rather than that on "Smooth"
thanks for understanding me ....
thanks in advance
Comment