Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Asia session HighestHigh - LowestLow help

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

    Asia session HighestHigh - LowestLow help

    Hello, I was looking for an indicator to mark the highest and lowest points of the Asian session, I found this on the forums (From https://forum.ninjatrader.com/forum/...on-range-lines​), but I have a problem, the lines of the previous sessions are displaced, how can i correct this problem?

    Click image for larger version

Name:	Chart - 5M.jpg
Views:	1455
Size:	220.8 KB
ID:	1296115


    Code:
    #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
    
    //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("19:00", System.Globalization.CultureInfo.InvariantCulture);
                    SessionEnd                        = DateTime.Parse("13:00", System.Globalization.CultureInfo.InvariantCulture);
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Minute, 1);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(BarsInProgress == 1)
                {
                    if(Times[1][0].TimeOfDay == SessionStart.TimeOfDay)
                    {
                        StartBar = CurrentBars[1];
                        TodayStart = Times[1][0];
                    }
                    if(Times[1][0].TimeOfDay == SessionEnd.TimeOfDay)
                    {
                        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.TimeEditorKey")]
            [Display(Name="SessionStart", Order=1, GroupName="Parameters")]
            public DateTime SessionStart
            { get; set; }
    
            [NinjaScriptProperty]
            [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
            [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
    ​

    #2
    I can't help with your indicator, but you can achieve the same thing by using the NT built in OHLC.
    Run the indicator and run it against the data series with only the Asian session set.

    Comment


      #3
      Hello mjairg,

      Thanks for your post.

      What times the lines are originating from, and what time zone you are in?

      If you open a Data Box window (right-click on chart > Show Data Box) and hover the mouse over the bar where the line starts and where the line ends, what is the time of the bars reported in the Data Box window?

      What is the Trading Hours template you are using for the Chart?

      We look forward to assisting further.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Thanks a lot for your help looks i solve the problem, just changing the if(Times[1][0].TimeOfDay > SessionEnd.TimeOfDay) to if(Times[1][0].TimeOfDay == SessionEnd.TimeOfDay)

        Click image for larger version

Name:	image.png
Views:	1112
Size:	69.9 KB
ID:	1296416

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        21 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        31 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        50 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Working...
        X