Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:	93
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.
      Brandon H.NinjaTrader Customer Service

      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:	26
Size:	69.9 KB
ID:	1296416

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,789 views
        0 likes
        Last Post aligator  
        Started by Jimmyk, 01-26-2018, 05:19 AM
        6 responses
        838 views
        0 likes
        Last Post emuns
        by emuns
         
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,294 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        13 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        63 views
        0 likes
        Last Post halgo_boulder  
        Working...
        X