Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing asian session range lines

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

    #31
    I think that I still have something wrong.

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class SessionHighLowLinesExample : Indicator
    {
    private int StartBar;
    private int SessionBarsAgo;
    private int TodayEndBar;
    private double LowestLow;
    private double HighestHigh;
    private DateTime TodayStart;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "SessionHighLowLinesExample";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    SessionStart = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture) ;
    SessionEnd = DateTime.Parse("08:00", System.Globalization.CultureInfo.InvariantCulture) ;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute, 1);
    }
    }

    protected override void OnBarUpdate()
    { if (CurrentBars[0] < 1 || CureentBars[1] < 1)
    if(BarsInProgress == 1)
    {
    if(Times[1][0].TimeOfDay == SessionStart.TimeOfDay)
    {
    StartBar = CurrentBars[1];
    TodayStart = Times[1][0];
    }
    if(Times[1][0].TimeOfDay > SessionEnd.TimeOfDay && TodayStart > new DateTime())
    {
    SessionBarsAgo = CurrentBars[1] - StartBar;
    TodayEndBar = CurrentBars[1];
    HighestHigh = MAX(Highs[1], SessionBarsAgo)[0];
    LowestLow = MIN(Lows[1], SessionBarsAgo)[0];
    }
    if(Times[1][0].TimeOfDay > SessionEnd.TimeOfDay)
    {
    Draw.Line(this, TodayEndBar.ToString()+"High", false, TodayStart, HighestHigh, Times[1][0], HighestHigh, Brushes.Green, DashStyleHelper.Dash, 2);
    Draw.Line(this, TodayEndBar.ToString()+"Low", false, TodayStart, LowestLow, Times[1][0], LowestLow, Brushes.Red, DashStyleHelper.Dash, 2);
    }
    }
    }

    region Properties
    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="SessionStart", Order=1, GroupName="Parameters")]
    public DateTime SessionStart
    { get; set; }

    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="SessionEnd", Order=2, GroupName="Parameters")]
    public DateTime SessionEnd
    { get; set; }
    #endregion

    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private SessionHighLowLinesExample[] cacheSessionHighLowLinesExample;
    public SessionHighLowLinesExample SessionHighLowLinesExample(DateTime sessionStart, DateTime sessionEnd)
    {
    return SessionHighLowLinesExample(Input, sessionStart, sessionEnd);
    }

    public SessionHighLowLinesExample SessionHighLowLinesExample(ISeries<double> input, DateTime sessionStart, DateTime sessionEnd)
    {
    if (cacheSessionHighLowLinesExample != null)
    for (int idx = 0; idx < cacheSessionHighLowLinesExample.Length; idx++)
    if (cacheSessionHighLowLinesExample[idx] != null && cacheSessionHighLowLinesExample[idx].SessionStart == sessionStart && cacheSessionHighLowLinesExample[idx].SessionEnd == sessionEnd && cacheSessionHighLowLinesExample[idx].EqualsInput(input))
    return cacheSessionHighLowLinesExample[idx];
    return CacheIndicator<SessionHighLowLinesExample>(new SessionHighLowLinesExample(){ SessionStart = sessionStart, SessionEnd = sessionEnd }, input, ref cacheSessionHighLowLinesExample);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(DateTime sessionStart, DateTime sessionEnd)
    {
    return indicator.SessionHighLowLinesExample(Input, sessionStart, sessionEnd);
    }

    public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(ISeries<double> input , DateTime sessionStart, DateTime sessionEnd)
    {
    return indicator.SessionHighLowLinesExample(input, sessionStart, sessionEnd);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(DateTime sessionStart, DateTime sessionEnd)
    {
    return indicator.SessionHighLowLinesExample(Input, sessionStart, sessionEnd);
    }

    public Indicators.SessionHighLowLinesExample SessionHighLowLinesExample(ISeries<double> input , DateTime sessionStart, DateTime sessionEnd)
    {
    return indicator.SessionHighLowLinesExample(input, sessionStart, sessionEnd);
    }
    }
    }

    #endregion

    Comment


      #32
      Hello randymcampbell,

      CureentBars is not a NinjaScript property. Is this a variable you have declared yourself?

      Are you 100% certain you are posting the exact copy and pasted code that is in your script?

      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.



      How is the script not working?

      Are there run-time errors appearing on the Log tab of the Control Center?

      Are the conditions not evaluating as true?

      Is there a compile error?​
      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
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 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
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X