Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help with Hourly Open Script

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

    Need help with Hourly Open Script

    Hello everyone,
    I am trying to create a script that plots (each) Hourly Open horizontal lines on the chart. I am no expert in coding and looking at various scripts I put together this script. From original 55 errors now, down to 1 and I don't understand what else to do. Can someone help me fixing this error? Thank you so much!!

    Error:
    HourlyOpen.cs The name 'DashStyleHelper' does not exist in the current context CS0103 56 120

    Script:

    region Using declarations
    using System;
    using System.Windows.Media; // Required for Brush and color definitions
    using NinjaTrader.NinjaScript; // Base namespace for indicators
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript.Strategies; // Required for strategies
    using NinjaTrader.NinjaScript.StrategyGenerator; // Required for StrategyGenerator
    using System.Xml.Serialization; // Required for XmlIgnoreAttribute
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class HourlyOpen : Indicator
    {
    private double hourlyOpenPrice = 0;
    private DateTime lastHourOpenTime;
    private Series<double> hourlyOpenSeries;
    private Brush lineColor; // Line color
    private int lineWidth; // Line width

    // Initialize and configure the indicator
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Hourly Open Line Indicator";
    Name = "HourlyOpen";
    Calculate = Calculate.OnEachTick;
    IsOverlay = true;

    // User Inputs
    lineColor = Brushes.Yellow; // Default line color
    lineWidth = 1; // Default line width
    }
    else if (State == State.DataLoaded)
    {
    hourlyOpenSeries = new Series<double>(this);
    }
    }

    // Calculate and draw the hourly open line
    protected override void OnBarUpdate()
    {
    // Get current bar time
    DateTime currentBarTime = Times[0][0];
    DateTime currentBarHourOpen = new DateTime(currentBarTime.Year, currentBarTime.Month, currentBarTime.Day, currentBarTime.Hour, 0, 0);

    // Check if a new hour has started
    if (lastHourOpenTime != currentBarHourOpen && Time[0].Minute == 0 && Time[0].Second == 0)
    {
    hourlyOpenPrice = Opens[0][0]; // Capture the open price for the hour
    lastHourOpenTime = currentBarHourOpen;

    // Draw the hourly open line
    Draw.Line(this, "HourlyOpen" + CurrentBar, false, 0, hourlyOpenPrice, -60, hourlyOpenPrice, lineColor, DashStyleHelper.Solid, lineWidth);
    }
    }

    region Properties

    // Line Color property
    [NinjaScriptProperty]
    [XmlIgnore] // Corrected reference to XmlIgnore
    public Brush LineColor
    {
    get { return lineColor; }
    set { lineColor = value; }
    }

    // Line Width property
    [NinjaScriptProperty]
    public int LineWidth
    {
    get { return lineWidth; }
    set { lineWidth = value; }
    }

    #endregion
    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private HourlyOpen[] cacheHourlyOpen;
    public HourlyOpen HourlyOpen(Brush lineColor, int lineWidth)
    {
    return HourlyOpen(Input, lineColor, lineWidth);
    }

    public HourlyOpen HourlyOpen(ISeries<double> input, Brush lineColor, int lineWidth)
    {
    if (cacheHourlyOpen != null)
    for (int idx = 0; idx < cacheHourlyOpen.Length; idx++)
    if (cacheHourlyOpen[idx] != null && cacheHourlyOpen[idx].LineColor == lineColor && cacheHourlyOpen[idx].LineWidth == lineWidth && cacheHourlyOpen[idx].EqualsInput(input))
    return cacheHourlyOpen[idx];
    return CacheIndicator<HourlyOpen>(new HourlyOpen(){ LineColor = lineColor, LineWidth = lineWidth }, input, ref cacheHourlyOpen);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.HourlyOpen HourlyOpen(Brush lineColor, int lineWidth)
    {
    return indicator.HourlyOpen(Input, lineColor, lineWidth);
    }

    public Indicators.HourlyOpen HourlyOpen(ISeries<double> input , Brush lineColor, int lineWidth)
    {
    return indicator.HourlyOpen(input, lineColor, lineWidth);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.HourlyOpen HourlyOpen(Brush lineColor, int lineWidth)
    {
    return indicator.HourlyOpen(Input, lineColor, lineWidth);
    }

    public Indicators.HourlyOpen HourlyOpen(ISeries<double> input , Brush lineColor, int lineWidth)
    {
    return indicator.HourlyOpen(input, lineColor, lineWidth);
    }
    }
    }

    #endregion

    #2
    Hello AceHorse,

    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript Add-on...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter the script name in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.



    It looks like you have modified the default using statements. We recommend that you create scripts using the NinjaScript Editor so the default using statements and structure is correct.

    Please try copying over the default using statements.

    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion​​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      @NinjaTrader_ChelseaB​ Thank you!

      By copying over the default using statements the issue is fixed and no compile errors!

      Comment

      Latest Posts

      Collapse

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