Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't get a particular bar to compare. Please help.

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

    Can't get a particular bar to compare. Please help.

    In the attached code I can get the code to compare in BuySeqCount == 12, the 13th bar vs the 8th bar BUT in BuySeqCount == 7, I can't get the 8th bar to compare with the 5th!!! The relevant method is "ProcessBuySequential"

    Would anyone mind taking a look and tell me what I am doing wrong? Thanks!
    Attached Files

    #2
    Kay, please add Prints to the code at those relevant sections to check if those conditions actually trigger as you expect.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      Upon printing the values, the values that I thought I had stored changes. For example buycountdown8 = Close[0]; this is a private double variable.

      But after a few bars, the value of buycountdown8 changes.

      How am I able to store this value so that it doesn't change?

      Comment


        #4
        This is expected as you can have multiple occurences on the chart where the condition is true, thus storing this value again and again...so you would only see the most recent one stored. You could use a dataseries for this, thus storing the history of values. By then retrieving past values with the index you're able to access past and current values in your calcs.

        http://www.ninjatrader-support.com/H...iesObject.html
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi Bertrand,
          I am aware that I have multiple occurences of for example buycountdown8 on the chart but the 13 red counts are preceded by 9 green counts in every case. without the 9 green counts, the 13 red counts do not exist. the comparison of the 13th red count vs the 8th red count will be done on every occassion.

          the storage of the value (in this case buycountdown8) shouldn't move within each set and I didn't expect it to do so with a few bars.

          if i were to take up your suggestion to use the DataSeries Class, how would i be able to call up buycountdown8 for example?

          Comment


            #6
            You can access whichever [] index would relate to that bar.

            [0] is most recent, [1] is previous, etc. Just like how you access Close prices.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi Josh,
              Each set of 9 green counts (consecutive counts) is matched by a set of 13 red counts (not necessarily consecutive counts). And because the red counts do not occur predictably, my first thoughts were to capture the values of the 5th and the 8th count as and when they occured by storing the value as a private double. I would be capturing these 2 values for each set of red counts. I thought that by resetting those values at the completion of the red counts would suffice. Thought it would have been quite straight forward. What I did not expect was the private double values to have their values changed within a few bars. Without the consistency in the position of the red counts, I thought it would be difficult to call up the 5th and the 8th count. I've attached 2 charts to display the unpredictability of the counts and locking in the value as and when it occurs seems the best option. Appreciate any further advice/guidance.
              Attached Files

              Comment


                #8
                Kay, unfortunately we can't really debug this for you - best approach would be simplifying the codes as much as possible and then first checking into why the counting behaves as 'unpredictable' as you noted. Then work on from there after fixing / determining this, as this would also influence then how you should save those values for later reference in your code. A dataseries would have the convenience of offering access to all past values, but of course it adds resource needs as well to store those.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hi Bertrand,

                  I understand what you are trying to say. I have close to zero programming knowledge and have been picking bits and pieces from you, Josh and the guys who help out on this forum like Baruch and on another forum. I thought the code was pretty simplified as it is. The 9 green counts is the backbone while the rest are indicators that are created as a result of the 9 count completion. If I were to break it up into separate indicators, and call them up as required, would that help? Or would it be simpler to try to recode it? This is actually the last bit for the indicator (comparing the 8 v 5 count and 13 v 8 count). I have seen something similar to this indicator in the forum and have been using it as a guide. Unfortunately, it has taken me as far as it could...

                  The other issue is having the Buy indicator and Sell indicator under one code. If I were to put them under one "umbrella" as opposed to combining them in one code, would that work better?

                  I remember having an indicator which calculated 2 SMAs in one indicator. It was disastrous! I separated them and it looked great!

                  Comment


                    #10
                    Kay, I can understand - rewriting from scratch might be the best learning experience if you're ready to spent some time on it, with the code you got from the forum it sometimes needs a fair amount of time to understand 3rd party code thus my suggestion to simplify as much as possible to understand its action from the ground up, this way you can Print values and see where you hit unexpected outcomes along the way.

                    If you want this to be fixed for you so you can review and learn from the final working code, a consultant might be the most efficient way to proceed -

                    http://www.ninjatrader.com/webnew/pa...injaScript.htm
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Bertrand,

                      I'm trying to have an extra condition before an "8' is printed but the code prints both a "+" on the "7" (so where the "7" is printed, a "+" is printed on top of it) when the condition is not fulfilled and continues with an "8".

                      What I would like to do is for the code to print a "+" instead of an "8" when the condition is not fulfilled and to print an "8" when the condition is fulfilled. How would I go about doing that? Everything else in the code is working fine.

                      This is what I've done so far:-
                      Code:
                      if (Close[0]<=Low[2])
                      {
                      if (BuySeqCount < 12) 
                      {
                      BuySeqCount++;
                      this.TDBuySeqDrawText(BuySeqCount.ToString());
                      if (BuySeqCount == 5)
                      {
                      buycountdown5 = Close[0];
                      Print("buycountdown5 is" + Close[0].ToString());
                      }
                      // to qualify for the 8th count
                      if (BuySeqCount == 7)
                      {
                      if (Low[0] <= buycountdown5)
                      {
                      Print("Low of 8 is" + Low[0]);
                      Print("buycountdown5 is" + buycountdown5);
                      BuySeqCount++;
                      this.TDBuySeqDrawText(BuySeqCount.ToString());
                      }
                      else
                      {
                      this.TDBuySeqDrawText("+"); 
                      }
                      }
                      
                      
                      Last edited by kaywai; 03-08-2010, 03:02 AM.

                      Comment


                        #12
                        This code continues from the earlier part:-

                        Code:
                        if (BuySeqCount == 8)
                        {
                        buycountdown8 = Close[0];
                        Print("buycountdown8 is" + Close[0].ToString());
                        }
                        }
                        // to qualify for the 13th count
                        elseif (BuySeqCount == 12)
                        {
                        if (Low[0] <= buycountdown8)
                        {
                        Print("Low of 13 is" + Low[0]);
                        Print("buycountdown8 is" + buycountdown8);
                        BuySeqCount++;
                        this.TDBuySeqDrawText(BuySeqCount.ToString());
                        this.InitializeNewBuySeqCountdown();
                        }
                        else
                        {
                        this.TDBuySeqDrawText("+");
                        }
                        } 
                        }
                        
                        }
                        

                        Comment


                          #13
                          Kay, unfortunately I can't debug this custom code for you - if I were you I would further simplify the code and test each single value / method as noted before. The code will do exactly what you tell it to do - also for the count on each OnBarUpdate as you've implemented it, it would be advisable to run on CalculateOnBarClose = true.
                          BertrandNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by mballagan, Today, 01:02 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post mballagan  
                          Started by larkmail, Today, 12:30 PM
                          1 response
                          5 views
                          0 likes
                          Last Post NinjaTrader_Kate  
                          Started by omermirza, Today, 12:39 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post omermirza  
                          Started by Danila, Today, 11:08 AM
                          1 response
                          11 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by dbida001, Today, 10:31 AM
                          1 response
                          5 views
                          0 likes
                          Last Post NinjaTrader_ChristopherJ  
                          Working...
                          X