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

Indicator zeroing out

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

    Indicator zeroing out

    I put in a couple of different MA types into an indicator I wrote recently and find that they sometimes 'zero out' on the current bar. If I hit F5, they usually, but not always, redraw properly. It is always the same two, and they don't do this when loaded on their own, only when embedded in my indicator. Several others that are embedded work fine so I am baffled.

    It's quite simple:

    if (IndyMethod ==1)
    { lr.Set (LinReg(Period)[0]); ltlr.Set(LinReg(ltperiod)[0]); }
    if (IndyMethod ==2)
    { lr.Set(ZeroLagEMA(period)[0]); ltlr.Set(ZeroLagEMA(ltperiod)[0]);}
    if (IndyMethod ==3)
    { lr.Set(EMA(period)[0]); ltlr.Set(EMA(ltperiod)[0]); }
    if (IndyMethod ==4)
    { lr.Set(HMA(period)[0]); ltlr.Set(HMA(ltperiod)[0]); }
    if (IndyMethod ==5)
    { lr.Set(ZeroLagHATEMA(period)[0]); ltlr.Set(ZeroLagHATEMA(ltperiod)[0]); }
    if (IndyMethod ==6)
    { lr.Set(ZeroLagTEMAGauss(period)[0]); ltlr.Set(ZeroLagHATEMA(ltperiod)[0]); }

    4,5 & 6 keep zeroing out, the others work fine all the time so I don't think it is the coding per se.

    I understand I am not giving out the whole code - which has far too much in it with other things - but off hand: does anyone have any experience with a similar error and if so what is the fix? Perhaps I need some sort of starting condition and that is the problem, but it only happens on the current (last) bar, both in live and historical charts.

    Here is a truncated pic (to keep within paltry forum limitations)
    Attached Files
    Last edited by cclsys; 11-13-2009, 05:44 PM.

    #2
    cclsys, since you aren't able to post the full code, can you please try posting the minimum (yet complete) bit of code that still reproduces this behavior?

    Anyways, what do you mean by the indicator "zeroes out"? Is the plot zero, blank, or something else all together?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      cclsys, since you aren't able to post the full code, can you please try posting the minimum (yet complete) bit of code that still reproduces this behavior?

      Anyways, what do you mean by the indicator "zeroes out"? Is the plot zero, blank, or something else all together?
      The picture shows what it does.

      Here is the full code up to the plotting parts. The rest have to do with stops and profit targets etc. but do not - at least they should not - have anything to do with the plotting section:

      #region Variables
      private int period = 21;
      //private int periodLT = 31;
      private double fct = 10; // will be divided by 1000 so that each whole number = .001;
      private int slope = 2;
      private Color colorup = Color.Goldenrod;
      private Color colordown = Color.SteelBlue;
      private Color color2up = Color.Gold;
      private Color color2down = Color.DodgerBlue;
      private Color colorside = Color.Lime;
      private bool lRBars = true;
      private int backcoloron = 1; // 0 off; 1 white chart 2 black chart
      public int linewidth = 5;
      private bool stops = false;
      private int snr = 1; // stop tick offset
      private int dsl = 3; // Donchian Channel Stop length
      private double ratio = 1.5;
      private bool gauss = false; // Gaussian smoothing on-off
      private double stopx = 8;
      private int mode = 1; // Modes: 1 = basic; 2 = ATR option. 3. Stopx
      private double aTRmulti = 1;
      private int indyMethod =1;
      private bool showline =true;
      private TextPosition tPosition = TextPosition.BottomLeft;
      private bool textwarnings = true;
      private double entryp = 0;
      private System.Drawing.Font textFont1;
      private int srDotSize = 3;

      private int opacityValue = 155; // controls opacity of main LinReg line, divided by 6 for BackColor
      private bool upsig = true;
      private bool downsig = true;
      private bool settargetlong = false;
      private bool settargetshort = false;
      private double stopxx = 0;
      private bool ltstoption =true;
      private double stopxx2 = 0;
      private double tgt1 = 0,tgt2 =0,tgt3 = 0,tgt4 = 0;
      private bool upsigdraw =true,downsigdraw =true,drawtgtup =true,drawtgtdn =true;
      private bool newtrend =false;




      private DataSeries lr;
      private DataSeries targ;
      private DataSeries ltlr; // Longer term LinReg line for trend backcolor

      #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.FromArgb(opacityValue, colorup),linewidth), PlotStyle.Line, "Rising"));
      Add(new Plot(new Pen(Color.FromArgb(opacityValue, color2up),linewidth), PlotStyle.Line, "Rising2"));
      Add(new Plot(new Pen(Color.FromArgb(opacityValue, colordown),linewidth), PlotStyle.Line, "Falling"));
      Add(new Plot(new Pen(Color.FromArgb(opacityValue, color2down),linewidth), PlotStyle.Line, "Falling2"));
      Add(new Plot(new Pen(Color.FromArgb(opacityValue, colorside),linewidth), PlotStyle.Line, "Neutral"));
      Add(new Plot(new Pen(Color.DodgerBlue,1), PlotStyle.Square, "Longstop"));
      Add(new Plot(new Pen(Color.Chocolate,1), PlotStyle.Square, "Shortstop"));
      Add(new Plot(new Pen(Color.Green,2), PlotStyle.Hash, "Target"));
      Add(new Plot(new Pen(Color.LimeGreen,2), PlotStyle.Hash, "Target2"));
      Add(new Plot(new Pen(Color.Lime,2), PlotStyle.Hash, "Target3"));
      Add(new Plot(new Pen(Color.OrangeRed,2), PlotStyle.Hash, "Target4"));

      lr = new DataSeries(this);
      targ = new DataSeries(this);
      ltlr = new DataSeries(this);

      PaintPriceMarkers = false;
      CalculateOnBarClose = false;
      Overlay = true;
      AutoScale = false;

      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Checks to make sure we have at least 1 bar before continuing
      if (CurrentBar < period+1)
      return;
      int ltperiod = 34;


      /* textFont1 = new Font("Wingdings",srDotSize );
      DrawText("Low Line1" + CurrentBar, true, "l", 0 , Low[0], colorUT,
      textFont1, StringAlignment.Center, Color.Empty, Color.Empty, 5);
      */
      //Print(ltperiod);

      if (IndyMethod ==1)
      { lr.Set (LinReg(Period)[0]); ltlr.Set(LinReg(ltperiod)[0]); }
      if (IndyMethod ==2)
      { lr.Set(ZeroLagEMA(period)[0]); ltlr.Set(ZeroLagEMA(ltperiod)[0]);}
      if (IndyMethod ==3)
      { lr.Set(EMA(period)[0]); ltlr.Set(EMA(ltperiod)[0]); }
      if (IndyMethod ==4)
      { lr.Set(HMA(period)[0]); ltlr.Set(HMA(ltperiod)[0]); }
      if (IndyMethod ==4)
      { lr.Set(ZeroLagHATEMA(period)[0]); ltlr.Set(ZeroLagHATEMA(ltperiod)[0]); }
      if (IndyMethod ==6)
      { lr.Set(ZeroLagTEMAGauss(period)[0]); ltlr.Set(ZeroLagHATEMA(ltperiod)[0]); }

      // Gaussian Smoothing option.

      if (Gauss)
      { lr.Set(RGaussianFilter(lr,Period/3,1)[0]); ltlr.Set(RGaussianFilter(ltlr,Period/3,1)[0]); }

      // Bands for possible entry filter
      double std =0,upperband =0,lowerband=0;

      std = .618 * StdDev(Period)[0];
      upperband = (ltlr[0] + ATR(period)[0]) ;
      lowerband = (ltlr[0] - ATR(period)[0]);

      // Indicator Plotting Section
      if (Showline)
      {
      if ( Slope(lr,slope,0) > (fct/1000) && Slope(lr,slope,0) < ((fct*2)/1000) )
      { RisingPlot.Set(1, lr[1]);
      RisingPlot.Set(lr[0]);
      }
      else if (Slope(lr,slope,0) >= ((fct*2)/1000))
      { Rising2Plot.Set(1, lr[1]);
      Rising2Plot.Set(lr[0]);
      }
      else if (Slope(lr,slope,0) < (-fct/1000) && Slope(lr,slope,0) > (-(fct*2)/1000))
      { FallingPlot.Set(1, lr[1]);
      FallingPlot.Set(lr[0]);
      }
      else if (Slope(lr,slope,0) <= (-(fct*2)/1000))
      { Falling2Plot.Set(1, lr[1]);
      Falling2Plot.Set(lr[0]);
      }
      else
      { NeutralPlot.Set(1, lr[1]);
      NeutralPlot.Set(lr[0]);
      }
      }

      +++++++++++

      Now I have tried this without having things like Period/3 in Gaussian section in case there is a problem with dividing integers, but the problem remained, so that wasn't it. Indeed, that is why there is an int ltperiod =34 up there, because before it was Period*15/10 (1.5 times the period). It still zeros out.
      Last edited by cclsys; 11-14-2009, 02:34 PM.

      Comment


        #4
        Originally posted by cclsys View Post
        The picture shows what it does.

        Here is the full code up to the plotting parts.
        cclsys, I don't know what I'm looking for so I'm still not quite sure what the picture shows. Could you please fully explain what you mean by the indicator "zeros out"?

        If you feel this is a bug could you please strip down the code to make it as small as possible while still "zeroing out" then posting that code?

        Thank you cclsys.
        AustinNinjaTrader Customer Service

        Comment


          #5
          The picture shows the indicator line making a vertical descent on the last bar down to 0. It is not supposed to do that!

          Since the zeroing out only happens occasionally, but regularly, I am not sure how to strip it down.

          I was hoping that somebody had encountered a problem like this elsewhere and would have some idea why this would happen. I guess not, and I just won't use those indicators in the code. Someone PM'd me with msg about it having to do with Calc on Bar Close versus Open but I get it on both. And again, not always, but sometimes.

          There's also nothing in the log when it happens, presumably because the indicator thinks it is plotting correctly.

          Maybe that's why they call them 'ZeroLag' indicators, because they like going down to zero?

          Mystery Ninja sneak attack!

          Comment


            #6
            hi cclsys,
            i remember that we had several discusions about ZeroLag-stuff + ploting-issues in summer. please try this in your ZeroLagEMA indicator- script :

            //CalculateOnBarClose = true;

            try to check out if the behavior changes.
            maybe try out also with the other ZeroLag-indies.

            i know that the problems dont went away with setting - Calc-on-BarClose to "true "
            but it was gone when doing this " // CalculateOnBarClose = true; "
            in the code

            its worth to try i think.

            Comment


              #7
              Worth a shot Max, thanks - cclsys, please check into all methods you call in this indicator and remove the CalculateOnBarClose references in the Initialize() of those, then recheck.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Originally posted by max-td View Post
                hi cclsys,
                i remember that we had several discusions about ZeroLag-stuff + ploting-issues in summer. please try this in your ZeroLagEMA indicator- script :

                //CalculateOnBarClose = true;

                try to check out if the behavior changes.
                maybe try out also with the other ZeroLag-indies.

                i know that the problems dont went away with setting - Calc-on-BarClose to "true "
                but it was gone when doing this " // CalculateOnBarClose = true; "
                in the code

                its worth to try i think.
                Thanks, Max. Have done. Will run tomorrow on a live chart and see if that fixed it. Sounds like it will.

                I had a feeling someone would have an idea about this. Certainly not obvious but very simple - assuming that is it.

                I note that the ZeroLagEMA already had that line commented out but the ones that were having the problems still had them, so probably that is it. Because if you are embedding them in another indicator and the two are in conflict, perhaps it doesn't like it, although again, I had the problem in both modes, although I didn't pay attention to exactly which indicator was in exactly which mode so probably one zeroed out if I was in CoClose mode, and the other if I was not.

                Thanks.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by arvidvanstaey, Today, 02:19 PM
                4 responses
                11 views
                0 likes
                Last Post arvidvanstaey  
                Started by samish18, 04-17-2024, 08:57 AM
                16 responses
                60 views
                0 likes
                Last Post samish18  
                Started by jordanq2, Today, 03:10 PM
                2 responses
                9 views
                0 likes
                Last Post jordanq2  
                Started by traderqz, Today, 12:06 AM
                10 responses
                18 views
                0 likes
                Last Post traderqz  
                Started by algospoke, 04-17-2024, 06:40 PM
                5 responses
                48 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X