Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help debug this indi..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help debug this indi..

    Can someone help me debug this indicator? i cannot understand why the plot value is always zero.. i tried to print values but they are inconsistent..
    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!
    Code:
    #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

    #2
    Hello AtApi,

    Thank you for your post.

    While we in the support department cannot debug your code for you, I would advise adding some prints to your code to see why your script isn't plotting your expected values.

    This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.

    https://ninjatrader.com/support/foru...ns-not-working

    If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess what is different between the two. If you're unsure about what your prints are showing you, please provide a code sample with the prints you're using and an example of the output.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Ok Thank you, just one more question: when i print and check the output window i see an empty row at the bottom..does it means that the last value is empty? (perhaps the loop make an extra cycle)or is normal behavior.. Also if you don`t mind, i still have not figured if when i use a series the index[0] point at the last bar (far right) or is the first bar(far left)..
      Thanks
      Last edited by AtApi; 10-08-2020, 03:48 PM.

      Comment


        #4
        Hello AtApi,

        Thank you for your reply.

        Please provide a sample of what you're seeing in the output window.

        The [0] bar will be the most recently forming bar, unless you are running OnBarClose, when it would refer to the most recently closed bar. So, for example, to get the close of the most recently forming bar, we would use Close[0]. You can find out more about referencing the correct bar here:



        Thanks in advance, I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wuannetraam, Today, 02:40 AM
        0 responses
        7 views
        0 likes
        Last Post wuannetraam  
        Started by cyberpete76, 03-27-2023, 12:29 AM
        7 responses
        269 views
        1 like
        Last Post slightly  
        Started by renewsaltwater, Today, 01:15 AM
        0 responses
        2 views
        0 likes
        Last Post renewsaltwater  
        Started by slightly, Today, 12:49 AM
        0 responses
        4 views
        0 likes
        Last Post slightly  
        Started by sdauteuil, 09-23-2021, 10:16 AM
        4 responses
        1,211 views
        0 likes
        Last Post jacobpescaia44  
        Working...
        X