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 funk10101, Today, 12:02 AM
        0 responses
        3 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Yesterday, 10:49 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by XXtrader, Yesterday, 11:30 PM
        0 responses
        4 views
        0 likes
        Last Post XXtrader  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Working...
        X