Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Renko bars directional bar time

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

    Renko bars directional bar time

    I'm trying to create an indicator that measures the time it takes to complete a non-time based bar such as renko or range, but calculate up-close bars separately from down close bars so that I can then calculate the mean time of each over a certain lookback period.

    This code works fine for showing up-bar time lengths, but when I try to apply indicators to it, such as a 10 bar SMA, the SMA returns the SMA of price, not time.

    I'm sure it's something simple, but I've been unable to solve. Many thanks.


    protected override void OnBarUpdate()
    {
    if (CurrentBar<1)
    return;
    if (Close[0] < Open[0])
    return;

    DateTime eTime, pTime;
    if (Bars.FirstBarOfSession)
    Bars.Session.GetNextBeginEnd(Time[0],out pTime,out eTime);
    else
    pTime = Time[1];

    TimeSpan span = Time[0].Subtract(pTime);
    TimePast.Set(span.TotalMinutes);
    }

    #2
    Hello Sparkyboy,

    Thank you for the post.

    Have you at this point confirmed that the logic in your indicator performs the same when you apply it versus when you have supplied it to an indicator like the SMA?

    Depending on your logic and configuration, this may be a case where logic is executed differently causing an incorrect value.

    Also, do you see the correct value calculated in real-time, or is the outcome the same in both realtime and historical?

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse.

      Perhaps a more detailed description would help

      For reporting bar elapsed times on up bars only:

      Onbarclose=true

      When BAR = UP, indicator reports the bar time, correctly
      When BAR =down, indicator reports N/A, which is also correct

      Applying an SMA(1) to this, the SMA(1) correctly reports the bar time on UP, but when BAR = DOWN the indicator incorrectly reports the closing price of the instrument.

      It would appear to be an issue with returning N/A when the bar is down. The problem is that I don't want to return 0 as this would incorrectly skew the mean bar upspeed downwards.

      Comment


        #4
        Hello Sparkyboy,

        Thank you for the reply.

        Yes, this helps, in this case, you would need to supply a valid data value for each data point to prevent this. The default value used for a series data point if nothing is supplied is the close price.

        You would likely need to find values that work for that use case to avoid the N/A values, or you would need to create a custom indicator that supports using IsValidDataPoint in its calculations to logically handle the missing values. https://ninjatrader.com/support/help...ghtsub=isvalid

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X