Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ninjascript noob question

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

    ninjascript noob question

    So I was following the tutorial on writing an indicator. The first one is a bar chart that shows a '1' if the open is equal to the close otherwise it plots a '0'. The code is:

    Plot0.Set(Open[0] == Close[0] ? 1 : 0);

    Well, I used data from AAPL downloaded from yahoo and couldn't see a single bar. Well, I thought, maybe there never is an open equal to the close. How about an open greater than a close? So I used this formula

    Plot0.Set(Open[0] > Close[0] ? 1 : 0);

    Well this works. It basically shows all the red candles (the days where you close lower than the open). This works too
    Plot0.Set(Open[0] < Close[0] ? 1 : 0);
    It shows all the green candles (except the most recent one for some reason? At that datapoint, it fails to draw a bar even though the candle is green.)

    So now I want to find those days where you open higher than yesterday's close. I use this:

    Plot0.Set(Open[0] > Close[1] ? 1 : 0);
    This shows nothing, even though there are clearly days with gaps-where you open higher than yesterday's close evident.
    This also fails:
    Plot0.Set(Close[1] < Open[0] ? 1 : 0); (just flipped the equation to make sure the program wasn't sufferring from a bug)

    but this works:
    Plot0.Set(Open[-1]> Close[0] ? 1 : 0); and it asks the same thing
    And this also works
    Plot0.Set(Close[0] < Open[-1] ? 1 : 0);
    So it seems that asking for open[0] is giving ninjatrader a problem.

    Then for fun I try
    Plot0.Set(Open[0] > Close[-1] ? 1 : 0);
    Where today's open is higher than tomorrow's close. This works fine. so open[0] is not a troublemaker.
    However, this equation
    Plot0.Set(Open[0] > Open[1] ? 1 : 0); shows nothing.
    If I am correct, it asks for days where today's open is higher than yesterday's open. There are plenty of those but none are marked on the barpattern plot.
    But this works fine
    Plot0.Set(Open[0] > Open[-1] ? 1 : 0);

    What is wrong? Help?!

    #2
    there is definitely a bug in the graphing component.
    This formula works
    Plot0.Set(Open[-20]> Close[0] ? 1 : 0);

    but only if the dates that are showing are less than the third week of may. THAT IS WEIRD. As long as the chart is displaying any date range less than the third week of May, I get the bar chart indicator as the equation above predicts. If i scroll the chart to show more recent date ranges, everything disappears when I reach the third week of May. Scrolling back in time does not restore the bar chart. I have to remove it and reload it.
    The same behavior is demonstrated by flipping the equation
    Plot0.Set(Open[-20]< Close[0] ? 1 : 0);

    However, this equation fails:
    Plot0.Set(Open[20]< Close[0] ? 1 : 0);

    Not single bar, regardless of the date range or zoom, that I look at.

    Has anyone else seen this weirdness?

    Comment


      #3
      bwana,

      You cannot use negative index values. [0] means the last bar. There is no bar to the right of it and using [-20] will throw errors.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Well, negative index values work, but that's not my issue. Have you been able to reproduce the other problem-where the screen does not draw the plot when a 0 index is used (as I described below?)

        Comment


          #5
          bwana,

          It does not work with the usage model of NinjaTrader and you should never pass in negative indexes. Please fix this in your code and then see what other issues you have afterwards.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            bwana,

            It does not work with the usage model of NinjaTrader and you should never pass in negative indexes. Please fix this in your code and then see what other issues you have afterwards.
            I just posted that to show you the problem. These are examples that each fail individually even when used as the ONLY LINE OF CODE (as in the tutorial).

            Plot0.Set(Open[20]< Close[0] ? 1 : 0);
            Plot0.Set(Open[0] == Close[0] ? 1 : 0);
            Plot0.Set(Open[0] > Close[1] ? 1 : 0);
            Plot0.Set(Close[1] < Open[0] ? 1 : 0);
            Plot0.Set(Open[0] > Open[1] ? 1 : 0);

            Can you see what's up?
            Last edited by bwana; 09-29-2009, 01:41 PM.

            Comment


              #7
              You cannot access bars that do not exist yet. Please see this tip: http://www.ninjatrader-support2.com/...ead.php?t=3170
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                ok, tnx. but something is still amiss. using this code if (CurrentBar < 1) return; Plot0.Set(Open[0] > Open[1] ? 1 : 0); works except the beginning of the series (about the first 20 candlesticks) there are no corresponding bars except there should be. It would help me if i could see the values of the variables while i stepped through the code. is there a debugger available?

                Comment


                  #9
                  Debugging is done by you adding Print() to the code and looking in the Output Window.

                  All indicators do not show the first 20 bars by default. If you wish to show this you need to turn on the "plot unstable period" for the indicators. Double click on the chart and it is one of the Chart Properties.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  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  
                  Started by wzgy0920, 04-23-2024, 09:53 PM
                  2 responses
                  49 views
                  0 likes
                  Last Post wzgy0920  
                  Started by Kensonprib, 04-28-2021, 10:11 AM
                  5 responses
                  193 views
                  0 likes
                  Last Post Hasadafa  
                  Started by GussJ, 03-04-2020, 03:11 PM
                  11 responses
                  3,235 views
                  0 likes
                  Last Post xiinteractive  
                  Working...
                  X