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 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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mestor, 03-10-2023, 01:50 AM
        16 responses
        388 views
        0 likes
        Last Post z.franck  
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        22 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        7 views
        0 likes
        Last Post funk10101  
        Working...
        X