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 Hwop38, 05-04-2026, 07:02 PM
        0 responses
        164 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        317 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        245 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        350 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        179 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Working...
        X