Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MA showing only the change of indicator value from last bar, not real value

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

    MA showing only the change of indicator value from last bar, not real value

    Hi,

    I set up the Market Analyzer grid for the first time and I'm seeing wrong values in the output of the indicator that I've added, even though the indicator works perfectly on a chart.

    On the charts, my indicator ranges from 0-1 with Plot0 and this is drawn correctly, however within the MA cell the Plot0 value returnes small values like -0.14 or 0.30 etc. Looking at the charts, I realised that it's actually taking the current bar value and subtracting the previous bar value.

    The script I am using might be at fault however, and I'd like for somebody to tell me if what I'm doing is bad. The values I'm using depend on session opening prices which I calculate within OnBarUpdate like so:

    Code:
    if (Bars.FirstBarOfSession)
                {
                    SessionOpen_Main = Open[0];
                    SessionOpen_Base = Opens[1][0];
                    
                }
    Does this mean these values will not work within the MA because it isn't loading the entire chart (ie all the bars, and thus it doesn't reach the bar which is FirstBarOfSession)??

    If so, how would I fix that? Thank you.

    #2
    I almost answered my own question. With further experimenting I find that if I enter the value which is equal to the number of bars there are since the session start within the "# of bars to look back" field, the value works ok and matches the indicator. However, as soon as a new bar is created, it starts to loose accuracy, and with many bars it goes completely wrong. Entering a very large number (or any number larger) produces 0.

    Remaining questions:

    How would I reach Bars.FirstBarOfSession within MA?
    If this is not possible, what way would you suggest for me to get the Open price of the first bar of session which would also work with MA?

    note: I am working with 1-minute charts and data.

    Thank you
    Last edited by braincell; 08-10-2011, 09:24 AM.

    Comment


      #3
      Hi braincell,

      MA and chart are run on the same data, but there are likely differences in settings between the two.

      The first two you should check are bars to load and the session template applied.

      On Market Analyzer:
      Bars to load is set for the indicator column. Make sure this # is set high enough. Default 50 may not be enough to get to the first bar of session.

      Session template: This is set from the MA's right Click > Properties screen.

      On Chart:
      Days to load / bars to load: This is set in the Right Click > Data Series screen.

      Session template: Also set in the right click > Data Series screen.
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        Hi, after an hour or two of debugging, I've found the line that breaks it. It makes it still work OK in the chart, but not in the MA, I am refreshing them both after each change. This is the line that breaks it:

        double BaseSum = SUM(Typicals[1], MovingAverageLength)[0];
        Why is that?

        Oh and Ryan, I'm afraid you didn't read my post entirely. I already tried the things you mentioned.

        Comment


          #5
          Another debugging finding.

          This returns 0 on both plots (within the MA):

          BaseSum = Typicals[1][7];
          This works in MA and returns good numbers:

          BaseSum = Typicals[1][6];
          After allowing some time to pass, the cutoff value rises from 6 to 9 etc (after waiting for 3 minutes). Both of these return good numbers in the chart however. Why is this?

          Edit: At some points, even the 0 stops working. So Typicals[1][0] breaks the script entirely. Could this be a memory issue, where the Typicals[1] data series is being cleaned by the garbage collector of .Net?

          Edit2: After using try/catch, I think I have it working, but the initial problem outlined above is still there. The catch is telling me index is out of bounds so that makes sense, but not for the low values presented.
          Last edited by braincell; 08-10-2011, 12:55 PM.

          Comment


            #6
            Oh and Ryan, I'm afraid you didn't read my post entirely. I already tried the things you mentioned.
            Sorry -- our replies crossed. You were writing a second reply at the same time I was writing my first.

            Index outside bounds of array is common and described in detail here;


            Try-Catch is a great technique for isolating. To resolve, add some lines that prevent accessing these values when they don't exist.

            if (CurrentBars[1] < 0 || CurrentBar < 0) return;

            If you index 7 bars back, then will need to account for that as well.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by geotrades1, Today, 10:02 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by ender_wiggum, Today, 09:50 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by rajendrasubedi2023, Today, 09:50 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by bmartz, Today, 09:30 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by geddyisodin, Today, 05:20 AM
            3 responses
            26 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X