Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code Help to Adjust Hourly H / L Indicator from Ecosystem

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

    Code Help to Adjust Hourly H / L Indicator from Ecosystem

    The following code is from the open source indicator on the ecosystem: https://ninjatraderecosystem.com/use...urly-high-low/

    I'm trying to gauge how easy it would be to adjust this a (4) hour timeframe. ie: capturing the high and low of each 4 hour period instead of 1 hour.

    Would this be a quick change using the code below... or much more complex than just changing a few things...?

    Any help or guidance would be great!

    CODE BLOCK:

    Code:
    /// <summary>
    /// Dynamically plots the highest and lowest of the current hour.//
    /// </summary>
    public class HourlyHL : Indicator
    {
    private int startOfHourBarIndex = -1;
    private int currentHour = -1;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Plots the highest and lowest bars for each hour.";
    Name = "Hourly High Low";
    IsAutoScale = false;
    DrawOnPricePanel = false;
    IsOverlay = true;
    IsSuspendedWhileInactive = true;
    
    // AddPlot for Hourly High
    AddPlot(new Stroke(Brushes.SpringGreen, 2), PlotStyle.Square, "Hourly High");
    // AddPlot for Hourly Low
    AddPlot(new Stroke(Brushes.OrangeRed, 2), PlotStyle.Square, "Hourly Low");
    }
    }
    
    
    protected override void OnBarUpdate()
    {
    DateTime hourBeginning = Time[0].AddMinutes(-1 * Time[0].Minute).AddSeconds(-1 * Time[0].Second);
    int hour = hourBeginning.Hour;
    
    if (hour != currentHour)
    {
    // Start of a new hour, reset startOfHourBarIndex
    currentHour = hour;
    startOfHourBarIndex = CurrentBar;
    }
    
    // Calculate how many bars ago the current hour started
    int hourBeginBarsAgo = CurrentBar - startOfHourBarIndex;
    
    if (hourBeginBarsAgo >= 0)
    {
    double highestHigh = MAX(High, hourBeginBarsAgo + 1)[0];
    double lowestLow = MIN(Low, hourBeginBarsAgo + 1)[0];
    
    for (int index = 0; index <= hourBeginBarsAgo; index++)
    {
    Values[0][index] = highestHigh;
    Values[1][index] = lowestLow;
    }
    }
    }
    }
    
    }

    #2
    Hello MattD888,

    There would need to be some changes in the logic that calculates the hourBeginning, hour, currentHour, and startOfHourBarIndex variables.

    The current logic removes the minutes and seconds from the current bars time. If the hour of this does not equal the last hour value saved to currentHour, then currentHour is updated to the start of the hour for this minute bar. (Meaning the hour of the current minute is different than the last bar that updated)

    Likely your logic would need to compare the hour to be greater than or equal to currentHour plus 4 hours.

    The level of difficulty would depend on your experience with C# development. With understanding of basic programming concepts and debugging the difficulty would be low.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

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