Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

indicator: onbarupdate

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

    indicator: onbarupdate

    Hi.

    Made an indicator.

    Does not work. Apparently nothing is being calculated.

    Put in Print("HELLO?!?!?!?") statements and other obnoxious print messages inside OnBarUpdate().

    Only the Print statements above my logic get triggered but only 2-3 times, according to output window.

    Questions:
    1) Why are my print statements only being triggered 2-3 times?
    2) Why are none of my other print statements being triggered?

    Code example:

    protected override void OnBarUpdate()
    {

    Print("I will slay a goat if this fails");

    if(Close[0]<High[1])
    {
    A = Close[0];
    }
    else
    {
    A = High[1];
    }

    Print("Is the goat alive or will I need to feed it to a shark and punish a thousand generations?");

    C = (add and subtract stuffs);

    Plot.Set(C);
    Print("The land seal needs to be slayed, and its innards eaten to appease my computer's internal clock's battery");

    }


    Any idea why my output shows "I will slay a goat if this fails" a few times, then nothing, and why my indicator is blank?

    Regards,

    Dane

    #2
    Dane,

    You are likely running into the error discussed in this tip: http://www.ninjatrader-support2.com/...ead.php?t=3170
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi.

      I have been running a chart with the indicator for a few hours now, and I still only see two sets of print statements.

      I only need the current bar and the previous bar.

      If I remove the indicator, clear the log, and restart it, the same thing occurs. The curious thing is I have the following:

      Print("Close[0] : "+Close[0]);
      Print("Close[1] : "+Close[1]);
      Print("Volume[0] : "+Volume[0]);

      The only print statement that triggers is the first one, and always with an apparently outdated close price.

      I changed the second line,

      Print("Close[1] : "+Close[1]);

      to

      Print("Close[-1] : "+Close[-1]);

      thinking I might have messed up trying to get the previous bar's close.

      The output now shows all three print statements, though they are all the same:

      Close[0] : 5.3
      Close[-1] : 5.3
      Volume[0] : 1000

      I feel as if I am missing something very basic here, besides that Close[-1] is probably erroneous.

      Comment


        #4
        Danedo,

        You cannot use a negative index value. As mentioned in the tip, you cannot just call [1] until you have at least 1 bar on the chart. Please amend your code with one of the techniques shown in the tip.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi.

          Maybe I need to ask a simpler question to fill in some knowledge:

          Using a minute chart, how do I compare the previous bar's close to the current high?

          I thought it was as simple as

          protected override void OnBarUpdate()
          {
          if(High[0] > Close[1])
          {
          Print ("The high is greater than the previous close");
          }


          You keep telling me I don't have enough bars. I don't quite understand. I want to compare the current bar to a bar a minute ago. Don't I need only 1 minute of data, as well as the current bar? I have been running this thing for hours.

          I do notice that everything runs if I don't try to use a previous bar.

          I could simply just store the current open, high, close, low in a variable and compare those, but I was hoping there was a more direct way of... referencing a previous bar's open high close low.

          Thank you for your great patience.

          Comment


            #6
            Originally posted by Danedo View Post

            protected override void OnBarUpdate()
            {
            if(High[0] > Close[1])
            {
            Print ("The high is greater than the previous close");
            }


            On the very first bar of the chart, all the way to the extreme left of your screen, Close[1] DOES NOT EXIST causing an error.
            Therefore you need something like:

            if(CurrentBar < 2) return;

            Its in the docs

            Comment


              #7
              Danedo,

              You cannot do that. Please see the tip. You need to first ensure you have enough bars on the chart. Remember your indicators start processing on the very first bar of the chart. From the very first bar there are no previous bars. This is why an index of [1] throws an error. See the tip for how to address this issue.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Danedo,

                The indicator starts to calculate on the very first bar of the chart.

                If you are on the very first bar calculation, and you try to reference the previous bar that is not on the chart, you will get an error. Check the LOG tab for errors in yellow.

                Even though you have many hours of 1 minute data on the chart, the indicator starts on the very first bar, looking back to a bar that doesnt exist. If this occurs, the indicator turns off and will not continue further.

                put this in the OnBarUpdate() as the first statement

                if(CurrentBar < 20)
                return;

                your code for high > previous close is correct
                mrlogik
                NinjaTrader Ecosystem Vendor - Purelogik Trading

                Comment


                  #9
                  -.-;;;;;;;

                  OK, I FINALLY see.

                  Thought something was wrong with the logic.

                  Embarrassed.

                  Have a great weekend.
                  Last edited by Danedo; 03-13-2009, 10:52 AM.

                  Comment


                    #10
                    Danedo,

                    Remember,

                    Code:
                    if(CurrentBar < n)
                        return;
                    Where n is the furthest back you plan to look.
                    For example, if you're using moving averages, whatever the largest period of the moving averages is, you use that period.

                    hope this helps.
                    Always check the Log tab when things don't seem as they should.
                    mrlogik
                    NinjaTrader Ecosystem Vendor - Purelogik Trading

                    Comment


                      #11
                      Originally posted by mrlogik View Post
                      Danedo,

                      Remember,

                      Code:
                      if(CurrentBar < n)
                          return;
                      Where n is the furthest back you plan to look.
                      For example, if you're using moving averages, whatever the largest period of the moving averages is, you use that period.

                      hope this helps.
                      Always check the Log tab when things don't seem as they should.
                      mrlogik,

                      if you use NT built in moving averages, you don't need to check CurrentBar condition since it's already done in MA code

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Shansen, 08-30-2019, 10:18 PM
                      24 responses
                      938 views
                      0 likes
                      Last Post spwizard  
                      Started by Max238, Today, 01:28 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post Max238
                      by Max238
                       
                      Started by rocketman7, Today, 01:00 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post rocketman7  
                      Started by wzgy0920, 04-20-2024, 06:09 PM
                      2 responses
                      27 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, 02-22-2024, 01:11 AM
                      5 responses
                      32 views
                      0 likes
                      Last Post wzgy0920  
                      Working...
                      X