There is one loop in the code but i think it is correct, still the values plotted are always zero.. i cannot see what i am doing wrong
Thanks!
#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.Customs { public class LaguerrePPORank : Indicator { #region Variables private Series<double> Ls0; private Series<double> Ls1; private Series<double> Ls2; private Series<double> Ls3; private Series<double> Ll0; private Series<double> Ll1; private Series<double> Ll2; private Series<double> Ll3; private Series<double> ppoT; private Series<double> ppoB; #endregion protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "LaguerrePPORank"; Calculate = Calculate.OnBarClose; IsOverlay = false; 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; Bears = 0.4; Bulls = 0.8; Lkb = 200; Pctile = 90; Midpctile = 70; AddPlot(new Stroke(Brushes.Gray, 2), PlotStyle.Bar, "PctRankT"); AddPlot(new Stroke(Brushes.Gray, 2), PlotStyle.Bar, "PctRankB"); AddLine(Brushes.SeaShell, 0, "Zero line"); AddLine(Brushes.Red, Pctile/100, "Top Percentile Threshold"); AddLine(Brushes.Green, (Pctile * -1)/100, "Bottom Percentile Threshold"); AddLine(Brushes.DarkOrange, Midpctile/100, "Warning Top Percentile Threshold"); AddLine(Brushes.Lime, (Midpctile*-1)/100, "Warning Bottom Percentile Threshold"); } else if (State == State.Configure) { Ls0 = new Series<double>(this); Ls1 = new Series<double>(this); Ls2 = new Series<double>(this); Ls3 = new Series<double>(this); Ll0 = new Series<double>(this); Ll1 = new Series<double>(this); Ll2 = new Series<double>(this); Ll3 = new Series<double>(this); ppoT = new Series<double>(this); ppoB = new Series<double>(this); } } protected override void OnBarUpdate() { double hl2; double lmas, lmal ; int topvalueMinus,topvaluePlus,bottomvalueMinus,bottom valuePlus; int TopColor, BottomColor; double pctileB,midpctileB; if(CurrentBar < Lkb) return; hl2 = (High[0] + Low[0])/2; //laguerre short Ls0[0] = (1 - Bears)*hl2+Bears*(Ls0[1]); Ls1[0] = -Bears*Ls0[0]+(Ls0[1])+Bears*(Ls1[1]); Ls2[0] = -Bears*Ls1[0]+(Ls1[1])+Bears*(Ls2[1]); Ls3[0] = -Bears*Ls2[0]+(Ls2[1])+Bears*(Ls3[1]); lmas = (Ls0[0] + 2*Ls1[0]+ 2*Ls2[0] + Ls3[0])/6; //laguerre long Ll0[0] = (1 - Bulls)*hl2+Bulls*(Ll0[1]); Ll1[0] = -Bulls*Ll0[0]+(Ll0[1])+Bulls*(Ll1[1]); Ll2[0] = -Bulls*Ll1[0]+(Ll1[1])+Bulls*(Ll2[1]); Ll3[0] = -Bulls*Ll2[0]+(Ll2[1])+Bulls*(Ll3[1]); lmal = (Ll0[0] + 2*Ll1[0]+ 2*Ll2[0] + Ll3[0])/6; pctileB = Pctile * -1; midpctileB = Midpctile * -1; //PPO Plot ppoT[0] = (lmas-lmal)/lmal*100; ppoB[0] = (lmal-lmas)/lmal*100; //PercentRank of PPO // percent rank = nb of value less than our value / (nb of values less than our value + nb of values greater than our value) topvalueMinus = 0; topvaluePlus = 0; bottomvalueMinus = 0; bottomvaluePlus = 0; for (int i = 0; i <= Lkb; i++) { if (ppoT[i] < ppoT[0]) topvalueMinus = topvalueMinus + 1; else topvaluePlus = topvaluePlus+1; if (ppoB[i] < ppoB[0]) bottomvalueMinus = bottomvalueMinus + 1; else bottomvaluePlus = bottomvaluePlus+1; } PctRankT[0] = topvalueMinus / (topvalueMinus+topvaluePlus); PctRankB[0] = (bottomvalueMinus / (bottomvalueMinus+bottomvaluePlus)) *-1; // Print("PctRankT[0]= " +PctRankT[0]); //coloring histogram TOP RED if (PctRankT[0] >= Pctile/100) TopColor = 1; else TopColor = -1; //coloring histogram MID TOP ORANGE if (PctRankT[0] >= Midpctile/100 && PctRankT[0] < Pctile/100) TopColor = 2; if (TopColor ==1) PlotBrushes[0][0] = Brushes.Red; else if (TopColor < 0) PlotBrushes[0][0] = Brushes.Gray; if (TopColor ==2) PlotBrushes[0][0] = Brushes.DarkOrange; else if (TopColor < 0) PlotBrushes[0][0] = Brushes.Gray; //coloring histogram BOTTOM LIME if(PctRankB[0] <= pctileB/100) BottomColor = 1; else BottomColor = -1; //coloring histogram MID BOTTOM GREEN if (PctRankB[0] <= midpctileB/100 && PctRankB[0] > pctileB/100) BottomColor = 3; if (BottomColor == 1) PlotBrushes[1][0] = Brushes.Magenta; else if (BottomColor < 0) PlotBrushes[1][0] = Brushes.Silver; if (BottomColor == 3) PlotBrushes[1][0] = Brushes.Green; else if (BottomColor > 0) PlotBrushes[1][0] = Brushes.Lime; } #region Properties [NinjaScriptProperty] [Range(0.1, double.MaxValue)] [Display(Name="Bears", Order=1, GroupName="Parameters")] public double Bears { get; set; } [NinjaScriptProperty] [Range(0.1, double.MaxValue)] [Display(Name="Bulls", Order=2, GroupName="Parameters")] public double Bulls { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Lkb", Description="Look back period", Order=3, GroupName="Parameters")] public int Lkb { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Pctile", Description="Extreme threshold lines", Order=4, GroupName="Parameters")] public int Pctile { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Midpctile", Description="Warning threshold lines", Order=5, GroupName="Parameters")] public int Midpctile { get; set; } [Browsable(false)] [XmlIgnore] public Series<double> PctRankT { get { return Values[0]; } } [Browsable(false)] [XmlIgnore] public Series<double> PctRankB { 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 Customs.LaguerrePPORank[] cacheLaguerrePPORank; public Customs.LaguerrePPORank LaguerrePPORank(double bears, double bulls, int lkb, int pctile, int midpctile) { return LaguerrePPORank(Input, bears, bulls, lkb, pctile, midpctile); } public Customs.LaguerrePPORank LaguerrePPORank(ISeries<double> input, double bears, double bulls, int lkb, int pctile, int midpctile) { if (cacheLaguerrePPORank != null) for (int idx = 0; idx < cacheLaguerrePPORank.Length; idx++) if (cacheLaguerrePPORank[idx] != null && cacheLaguerrePPORank[idx].Bears == bears && cacheLaguerrePPORank[idx].Bulls == bulls && cacheLaguerrePPORank[idx].Lkb == lkb && cacheLaguerrePPORank[idx].Pctile == pctile && cacheLaguerrePPORank[idx].Midpctile == midpctile && cacheLaguerrePPORank[idx].EqualsInput(input)) return cacheLaguerrePPORank[idx]; return CacheIndicator<Customs.LaguerrePPORank>(new Customs.LaguerrePPORank(){ Bears = bears, Bulls = bulls, Lkb = lkb, Pctile = pctile, Midpctile = midpctile }, input, ref cacheLaguerrePPORank); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.Customs.LaguerrePPORank LaguerrePPORank(double bears, double bulls, int lkb, int pctile, int midpctile) { return indicator.LaguerrePPORank(Input, bears, bulls, lkb, pctile, midpctile); } public Indicators.Customs.LaguerrePPORank LaguerrePPORank(ISeries<double> input , double bears, double bulls, int lkb, int pctile, int midpctile) { return indicator.LaguerrePPORank(input, bears, bulls, lkb, pctile, midpctile); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.Customs.LaguerrePPORank LaguerrePPORank(double bears, double bulls, int lkb, int pctile, int midpctile) { return indicator.LaguerrePPORank(Input, bears, bulls, lkb, pctile, midpctile); } public Indicators.Customs.LaguerrePPORank LaguerrePPORank(ISeries<double> input , double bears, double bulls, int lkb, int pctile, int midpctile) { return indicator.LaguerrePPORank(input, bears, bulls, lkb, pctile, midpctile); } } } #endregion
Comment