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

Renko bars reporting incorrect BarIndex when looping through them.

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

    Renko bars reporting incorrect BarIndex when looping through them.

    Hello,

    I am trying to perform a simple task of looping between two bars and finding the "Highest High" bar between those two bars (on a Renko chart).

    Something like this:

    PHP Code:

    int C
    =0;
    int CBarIndex 0;
    for (
    int x ABarIndex+1BBarIndexx++)
    {
        if (
    High[x] > C)
        {
            
    High[x];
            
    CBarIndex x;
        }

    I am expecting this type of result:
    GC ##-## (8 Renko): http://i.imgur.com/SATyRcg.png

    Instead, I get the correct price, but the wrong bar index:
    GC ##-## (8 Renko): http://i.imgur.com/32XsFPk.png

    Is there a NinjaTrader built-in method that I should use instead that handles Renko bar reporting in this situation? Or, something different I should do to get the correct bar index? (I've tried looping from A to B or from B to A with the same result.)

    I've looked at HighestBar(), but it doesn't look like I can correctly specify the range of bars to look at (but, perhaps I am using it wrong?).

    EDIT: Another way to find the price is to do something like this, but it still won't give me the BarIndex, which is the problem.
    PHP Code:
    MAX(High,ABarIndex)[BBarIndex]; 

    Thank you!
    Daniel
    Last edited by neoikon; 01-24-2014, 10:12 AM.

    #2
    Hello Daniel,

    Thank you for your note.

    Can you attach your whole script so that I can test this out on my end?

    You can find the script in (My) Documents -> NinjaTrader 7 -> bin -> Custom -> Indicator
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the quick reply. Unfortunately, it's a very large indicator (literally >16K lines long).

      That bit of code I gave was actually a little wrong, it should've been:

      PHP Code:
      MAX(High,BBarIndex-1)[ABarIndex+1]; 
      That will find the right price between the two bar indexes. Then, of course, you could do a loop to find the bar index of that price:

      PHP Code:
      int tempIndex ABarIndex+1;
      while (
      High[tempIndex] != && tempIndex BBarIndex-1)
      {
          
      tempIndex++;
      }
      CBarIndex tempIndex-1
      But that will find the same, incorrect BarIndex, as my original code does.

      I feel the problem has to do with a spike in price causing many Renko bars to be drawn at once, but NinjaTrader isn't reporting them as individual bars when looking at the Renko chart, since they all have the same timestamp.

      The spike on a minute-based chart illustrating the movement:
      GC ##-## (2 Min): http://i.imgur.com/lDUJRQk.png

      What NinjaTrader is reporting, many bars all happening within the same second:
      GC ##-## (4 Renko): http://i.imgur.com/NFen4tv.png

      Does that make sense?

      EDIT: I am still digging and trying to identify precisely what is going on.
      Last edited by neoikon; 01-24-2014, 11:02 AM.

      Comment


        #4
        Daniel,

        This is expected behavior due to the bar timestamp. When you call your code the correct price does get returned, however, since that grouping has the same timestamp it will return the first bar id of that series.

        These are individual bars however, since they have the same timestamp only the first bar of the series is returned.

        However, I want to look at the logic more thoroughly. Can you give me a simplified script of the logic?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thank you for the offer! However, I've done some more digging...

          I have a special function that allows me to draw lines and other objects into the future (to the right of the current bar), since these don't behave so well natively in NT.

          Long story short, my function is using Time[BarIndex] in this particular scenario instead of the actual BarIndex directly. Thus, since all those bars had the exact same time stamp, the top left of that rectangle was the "correct" point based on my code calling Time[BarIndex]. D'Oh!

          This was a good exercise and I think this will fix a couple other issues in my code as well.

          Thank you for your time!

          Daniel

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ScottW, Today, 06:09 PM
          0 responses
          2 views
          0 likes
          Last Post ScottW
          by ScottW
           
          Started by Board game geek, 10-29-2023, 12:00 PM
          14 responses
          244 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Waxavi, 04-19-2024, 02:10 AM
          4 responses
          56 views
          0 likes
          Last Post sonia0101  
          Started by cmtjoancolmenero, Today, 03:58 PM
          0 responses
          9 views
          0 likes
          Last Post cmtjoancolmenero  
          Started by Segwin, 05-07-2018, 02:15 PM
          11 responses
          1,779 views
          0 likes
          Last Post aligator  
          Working...
          X