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 is a function of itself ... cannot make it work

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

    indicator is a function of itself ... cannot make it work

    I have two indicators.
    joeHACindicator3 is ordinary.
    joeHAOindicator is defined as the average of previous day’s joeHACindicator3 and previoud day’s joeHAOindicator [ie] joeHAOindicator is a function of itself.
    Specifically joeHAOindicator=(joeHACindicator3(1)[1]+joeHAOindicator(1)[1])/2.

    I have had the following results with debug test cases that I made up:
    //PlotHAO.Set(( (1.30000+joeHACindicator3(1)[0])/2 ) + 0.03000);//jm THIS WORKS FOR DAY0 BUT NOT FOR YESTERDAY [DAY1]
    //PlotHAO.Set(( (joeHAOindicator(1)[0]+joeHACindicator3(1)[0])/2 ) + 0.03000);//jm THIS ONE CRASHED NinjaTrader
    PlotHAO.Set(( (joeHAOindicator(1)[1]+joeHACindicator3(1)[0])/2 ) + 0.03000);//jm worked but plotted nothing for joeHAOindicator

    I realize this is probably thoroughly confusing but with help it may be a start toward a fix.
    Attached is both indicators and the strategy.
    Attached Files

    #2
    Hello joemiller,

    Thank you for your post.

    Don't access the indicator from within itself, especially when trying to access a previous value that never existed. This will cause errors or cause the indicator to fail.

    Instead use the PlotHAO and assign it a value when CurrentBar == 0 and access PlotHAO[1] instead of joeHAOindicator(1)[1]:
    Code:
    if(CurrentBar == 0)
    			{
    				PlotHAO.Set(1);
    			}
    			PlotHAO.Set((  (PlotHAO[1]+joeHACindicator3(1)[0])/2  ) + 0.03000);
    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by joemiller View Post
      I have two indicators.
      joeHACindicator3 is ordinary.
      joeHAOindicator is defined as the average of previous day’s joeHACindicator3 and previoud day’s joeHAOindicator [ie] joeHAOindicator is a function of itself.
      Specifically joeHAOindicator=(joeHACindicator3(1)[1]+joeHAOindicator(1)[1])/2.

      I have had the following results with debug test cases that I made up:
      //PlotHAO.Set(( (1.30000+joeHACindicator3(1)[0])/2 ) + 0.03000);//jm THIS WORKS FOR DAY0 BUT NOT FOR YESTERDAY [DAY1]
      //PlotHAO.Set(( (joeHAOindicator(1)[0]+joeHACindicator3(1)[0])/2 ) + 0.03000);//jm THIS ONE CRASHED NinjaTrader
      PlotHAO.Set(( (joeHAOindicator(1)[1]+joeHACindicator3(1)[0])/2 ) + 0.03000);//jm worked but plotted nothing for joeHAOindicator

      I realize this is probably thoroughly confusing but with help it may be a start toward a fix.
      Attached is both indicators and the strategy.
      What is the error in your log?

      Comment


        #4
        hi Koganam,
        I attached yesterday's log which displays the last day of errors before I applied Patrick's fixes....just in case they are not a mute point now. With Patrick's fixes there are now no execution errors but indicator joeHAOindicator is not yet displayed on the chart so I must have some other programming error somewhere. working on that now. thanks for making me aware of the log. the error descriptions appear to be in English and maybe more useful to an unsophisticated user. my debugging tool kit is expanding. you guys are the most useful tool in that kit.
        Attached Files

        Comment


          #5
          Originally posted by joemiller View Post
          hi Koganam,
          I attached yesterday's log which displays the last day of errors before I applied Patrick's fixes....just in case they are not a mute point now. With Patrick's fixes there are now no execution errors but indicator joeHAOindicator is not yet displayed on the chart so I must have some other programming error somewhere. working on that now. thanks for making me aware of the log. the error descriptions appear to be in English and maybe more useful to an unsophisticated user. my debugging tool kit is expanding. you guys are the most useful tool in that kit.
          The many iterations of "6/2/2013 8:45:00 PM|3|4|Error on calling 'OnBarUpdate' method for indicator 'joeHAOindicator' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart." is why there is nothing being drawn on the chart.

          You need to escape enough bars to ensure that you do not access non-existent values. In your case, I suspect that you would need to escape only one bar.

          There are many threads on the issue. Here is just two of them.


          Comment


            #6
            "if (CurrentBar < 1) return;" solved the problem

            as you suggested "if (CurrentBar < 1) return;" solved the problem. simple as that.
            many many thanks, much appreciated.

            Comment


              #7
              how do I get it to plot on the current bar?


              the following statement is in region OnBarUpdate

              PlotHAO.Set(((PlotHAO[1]+joeHACindicator3(1)[1])/2));

              I expected the result to be placed on the bar being updated but instead it is plotted on the bar after that. how do I get it to plot on the current bar?

              indicator joeHAOindicator is attached. displayed are the following variations I unsuccessfully experimented with.

              //PlotHAO.Set(((PlotHAO[2]+joeHACindicator3(1)[2])/2));//jm TEMP FOR DEBUG
              //PlotHAO.Set(((PlotHAO[0]+joeHACindicator3(1)[0])/2));//jm TEMP FOR DEBUG
              //PlotHAO.Set(((PlotHAO[-1]+joeHACindicator3(1)[-1])/2));//jm TEMP FOR DEBUG
              Attached Files

              Comment


                #8
                Originally posted by joemiller View Post
                the following statement is in region OnBarUpdate

                PlotHAO.Set(((PlotHAO[1]+joeHACindicator3(1)[1])/2));

                I expected the result to be placed on the bar being updated but instead it is plotted on the bar after that. how do I get it to plot on the current bar?

                indicator joeHAOindicator is attached. displayed are the following variations I unsuccessf[ATTACH]25702[/ATTACH]ully experimented with.

                //PlotHAO.Set(((PlotHAO[2]+joeHACindicator3(1)[2])/2));//jm TEMP FOR DEBUG
                //PlotHAO.Set(((PlotHAO[0]+joeHACindicator3(1)[0])/2));//jm TEMP FOR DEBUG
                //PlotHAO.Set(((PlotHAO[-1]+joeHACindicator3(1)[-1])/2));//jm TEMP FOR DEBUG
                How do you mean "the bar after that."? Plots cannot be generated in the future. It might help if you posted a picture.

                Comment


                  #9
                  thanks for the quick response.....much appreciated.
                  i'm sooooo busy just like everyone else. I will reply sometime later today soon as I get my ducks lined up, snapshot taken and question hopefully made less confusing.

                  Comment


                    #10
                    I have learned that I can ‘grab’ the chart with the cursor and drag/’scroll’ the chart to the left and that there should be a 'hollow return icon’ for a new un-started day ...which sounds like it may be what I am looking for. Please forget about my questions previous to this. I started playing around with the haiken=ashi bars just for practice and a learning experience. I anticipate no use for haiken-ashi bars but will continue this focus on them to continue to pursue the following:

                    I am hoping that indicator joeHAOindicator be extended to the next day [in the future] ‘hollow return icon’ generated by NT because the indicator is 'shifted' one day into the future for all days. [joeHAOindicator generates two indicator lines].
                    The chart image shows that the two lines for joeHAOindiator are not extended and that there is no hollow icon [whatever that is]?

                    Attached is code for joeHAOindicator, code for the Strategy and an image of the chart.


                    Attached Files

                    Comment


                      #11
                      Hello joemiller,

                      Thank you for your update on this matter.

                      There is no method to extend the plots out into the future.

                      Comment


                        #12
                        I enthusiastically strongly suggest that the feature be scheduled for inclusion in future NT versions ... I have found a display of an EOD indicator, to be used in making investment decisions for the new day, to be very useful and convenient.

                        My suspicion is that it would be a relatively trivial programming enhancement to extend the indicator line to the available shifted indicator value. Thus the benefit/cost ratio is huge.

                        Comment


                          #13
                          Hello joemiller,

                          Thank you for your response.

                          I have forwarded this request to our development team for possible implementation in a future release of NinjaTrader.

                          Comment


                            #14
                            Is there a method by which I can access last bar values?

                            When referencing Close[0] I get the close for the next to last day displayed on a Strategy Analyzer chart instead of the close for the last bar.

                            Is there a method by which I can access last bar values?

                            Comment


                              #15
                              Originally posted by joemiller View Post
                              When referencing Close[0] I get the close for the next to last day displayed on a Strategy Analyzer chart instead of the close for the last bar.

                              Is there a method by which I can access last bar values?
                              There is not.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PaulMohn, Today, 05:00 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post PaulMohn  
                              Started by ZenCortexAuCost, Today, 04:24 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ZenCortexAuCost  
                              Started by ZenCortexAuCost, Today, 04:22 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post ZenCortexAuCost  
                              Started by SantoshXX, Today, 03:09 AM
                              0 responses
                              15 views
                              0 likes
                              Last Post SantoshXX  
                              Started by DanielTynera, Today, 01:14 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post DanielTynera  
                              Working...
                              X