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

finding high low over interval error in Sample code

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

    finding high low over interval error in Sample code

    Attached is a code snippet below from the 6.5 SampleGetHighLowByTimeRange.cs file shipped with 6.5.
    It finds different values when run in real time or Replay versus using F5 key.
    The F5 behavior is the "correct" behavior. I believe.
    The real time/replay does not include the last bar of the range properly.
    What am I missing to correct this?
    Thanks


    ==============
    / Check to make sure the end time is not earlier than the start time
    if (EndHour < StartHour)
    return;

    //Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed
    if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0]))
    return;

    // If the stored date time date is not the same date as the bar time date, create a new DateTime object
    if (startDateTime.Date != Time[0].Date)
    {
    startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0);
    endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0);
    }

    // Calculate the number of bars ago for the start and end bars of the specified time range
    int startBarsAgo = GetBar(startDateTime);
    int endBarsAgo = GetBar(endDateTime);

    // Now that we have the start end end bars ago values for the specified time range we can calculate the highest high for this range
    double highestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo];

    // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range
    double lowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo];

    // Set the plot values
    HighestHigh.Set(highestHigh);
    LowestLow.Set(lowestLow);

    #2
    Have you tried running the code with CalculateOnBarClose = false in the indicator properties?

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand:
      The indicator in which I am using the snippet already has CalculateOnBarClose = false. and still experiences the problem

      Comment


        #4
        Hi Roland, ok thanks - can you please post the indicator so I can give it a run here?
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by hurleydood, 09-12-2019, 10:45 AM
        14 responses
        1,096 views
        0 likes
        Last Post Board game geek  
        Started by cre8able, Yesterday, 04:16 PM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cre8able, Yesterday, 04:22 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by stafe, 04-15-2024, 08:34 PM
        5 responses
        28 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by StrongLikeBull, Yesterday, 04:05 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X