Announcement

Collapse
No announcement yet.

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?

    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?

        Comment

        Latest Posts

        Collapse

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