Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing asian session range lines

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

    #16
    Thank you!!!!
    Yes, it is the problem.

    Is possible to take only the Instrumen name, without the contract date?
    For example: MCL, MES, MNQ, etc.
    Like the next picture:
    "Anclaje Sesiones" (MES (15 Minute))

    Click image for larger version

Name:	fetch?id=1184335&d=1641327610.png
Views:	549
Size:	8.5 KB
ID:	1184359

    Like the names of the tabs. It uses @INSTRUMENT

    Click image for larger version

Name:	Instrument only.png
Views:	538
Size:	56.4 KB
ID:	1184360

    Comment


      #17
      Hello joselube001,

      Thank you for your reply.

      I don't believe there's anything documented that would return the instrument without the expiry, but you can split the string by spaces and just grab the first part (the instrument name):

      Code:
      public override string DisplayName
      {
      get
      {
      if(this.Instrument != null)
      {
      return (this.Name + " (" + Instrument.FullName.ToString().Split(' ')[0] + " (" + BarsPeriod + "))");
      }
      else
      {
      return (this.Name);
      }
      }
      }
      Please let us know if we may be of further assistance to you.

      Comment


        #18
        Wauu!!!

        That's what I was searching for!!!

        Really I appreciate your great help, Kate!

        THANK YOU VERY MUCH!

        Comment


          #19
          Hi Kate!

          Please say me if I need to create a new post for the next:

          I'm trying to draw a line from the close of the current trading day 14:00 until the close of the next trading day 14:00 without using "AddDays".
          And draw a rectangle to cover the minimum and maximum from the close of the current trading day 14:00 until the close of the next trading day 03:00 without using "AddDays" too.
          I'm using bars only.

          I'm trying to write the code using SessionIterator in the indicator but I don't know how to assign the Close to 14:00 for the line and the rectangle too.

          In the next picture, you can see white rectangles and white lines, this is what I'm using actually, but when are holidays or partial holidays these lines and rectangles aren't drawn or are incomplete.

          The gold lines are from the actual code that I'm trying to write to solve this problem.

          I don't know if I'm making several mistakes:

          Thank you in advance!

          Click image for larger version

Name:	Drawings uncomplete.png
Views:	570
Size:	45.9 KB
ID:	1184569

          Comment


            #20
            I forgot to copy the code!!:

            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 AnclajeSesiones : Indicator
            {
            DateTime AsiaSessionBeginTime;
            DateTime AsiaSessionEndTime;
            
            DateTime AsiaSessionTime = DateTime.Parse("14:00", System.Globalization.CultureInfo.InvariantCulture) ;
            DateTime EuropeSessionTime = DateTime.Parse("03:00", System.Globalization.CultureInfo.InvariantCulture) ;
            
            private SessionIterator sessionIterator;
            
            protected override void OnStateChange()
            {
            if (State == State.DataLoaded)
            {
            sessionIterator = new SessionIterator(Bars);
            }
            
            if (State == State.SetDefaults)
            {
            Description = @"Mercado distribuido por sesiones Asiática, Europea y Americana";
            Name = "Anclaje Sesiones";
            Calculate = Calculate.OnBarClose;
            DisplayInDataBox = false;
            DrawOnPricePanel = true;
            DrawHorizontalGridLines = true;
            DrawVerticalGridLines = true;
            IsOverlay = true;
            IsAutoScale = false;
            IsSuspendedWhileInactive = true;
            PaintPriceMarkers = false;
            ScaleJustification = ScaleJustification.Right;
            }
            }
            
            protected override void OnBarUpdate()
            {
            DateTime priortradingDay = sessionIterator.ActualTradingDayExchange;
            
            AsiaSessionTime = priortradingDay + AsiaSessionTime.TimeOfDay;
            AsiaSessionBeginTime = AsiaSessionTime.AddMinutes(BarsPeriod.Value);
            
            if (Bars.IsFirstBarOfSession)
            {
            sessionIterator.GetNextSession(Time[0], true);
            DateTime tradingDay = sessionIterator.ActualTradingDayExchange;
            
            DateTime NewAsiaSessionStartTime = tradingDay + AsiaSessionTime.TimeOfDay;
            AsiaSessionEndTime = NewAsiaSessionStartTime.AddMinutes(BarsPeriod.Valu e);
            }
            
            if (Time[0] >= AsiaSessionBeginTime)
            {
            Draw.Line(this, "AmericaCloseLine " + Time[0], false, AsiaSessionBeginTime, Close[0], AsiaSessionEndTime, Close[0], Brushes.Gold, DashStyleHelper.Dash, 2);
            }
            }
            }
            }

            Comment


              #21
              Hello joselube001,

              Thank you for your reply.

              Since this still seems to be in regards to Asian sessions, it's ok to respond to this post. If it was completely unrelated we would ask you make a separate post.

              I'm confused as to the issue - I'm only seeing gold lines being plotted from the code provided. I'm also unsure of the Trading Hours template you're using on the chart as well as the time zone to reproduce. Could you give more details regarding the trading hours template in use on the chart, where the white lines are originating from, and what time zone you are in so I may best try to reproduce?

              Thanks in advance; I look forward to assisting you further.

              Comment


                #22
                Nice! Thanks for your answer.

                I'm only seeing gold lines being plotted from the code provided.
                Yes, because I don't have the start point, and end point clear, since the line is plotting from the close of one different bar, not from 14:00, I was thinking of adding the rectangle after having this starting point clear.

                I'm also unsure of the Trading Hours template you're using on the chart as well as the time zone to reproduce. Could you give more details regarding the trading hours template in use on the chart, where the white lines are originating from, and what time zone you are in so I may best try to reproduce?
                I'm using the default Trading Hours Template, I'm from Colombia and it can be very useful if the time can be adjusted automatically when changing the time from winter to summer, in the summertime here is -1 hour (UTC-05:00) Bogotá, Lima, Quito... In wintertime is the same hour as New York. (For example: while in New York time is 09:30, here is 08:30 during summertime)

                The white Lines are from Close 14:00 and the line starts to be drawn from the next bar until the next day and the same hour (1 Day).

                Click image for larger version

Name:	Parameters.png
Views:	698
Size:	40.0 KB
ID:	1184584

                This is the new code with the rectangle added but isn't working good, maybe because the start and end parameters are wrong:

                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
                
                namespace NinjaTrader.NinjaScript.Indicators
                {
                public class AnclajeSesiones : Indicator
                {
                DateTime AsiaSessionBeginTime;
                DateTime AsiaSessionEndTime;
                DateTime AsiaSessionEndTimeLine;
                
                double AsiaSessionMax;
                double AsiaSessionMin;
                
                DateTime AsiaSessionTime = DateTime.Parse("14:00", System.Globalization.CultureInfo.InvariantCulture) ;
                DateTime EuropeSessionTime = DateTime.Parse("03:00", System.Globalization.CultureInfo.InvariantCulture) ;
                
                private SessionIterator sessionIterator;
                
                protected override void OnStateChange()
                {
                if (State == State.DataLoaded)
                {
                sessionIterator = new SessionIterator(Bars);
                }
                
                if (State == State.SetDefaults)
                {
                Description = @".";
                Name = "Anclaje Sesiones";
                Calculate = Calculate.OnBarClose;
                DisplayInDataBox = false;
                DrawOnPricePanel = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines = true;
                IsOverlay = true;
                IsAutoScale = false;
                IsSuspendedWhileInactive = true;
                PaintPriceMarkers = false;
                ScaleJustification = ScaleJustification.Right;
                }
                }
                
                protected override void OnBarUpdate()
                {
                DateTime priortradingDay = sessionIterator.ActualTradingDayExchange;
                
                AsiaSessionTime = priortradingDay + AsiaSessionTime.TimeOfDay;
                AsiaSessionBeginTime = AsiaSessionTime.AddMinutes(BarsPeriod.Value);
                
                if (Bars.IsFirstBarOfSession)
                {
                sessionIterator.GetNextSession(Time[0], true);
                DateTime tradingDay = sessionIterator.ActualTradingDayExchange;
                
                DateTime NewAsiaSessionStartTime = tradingDay + AsiaSessionTime.TimeOfDay;
                AsiaSessionEndTimeLine = NewAsiaSessionStartTime.AddMinutes(BarsPeriod.Value);
                
                EuropeSessionTime = tradingDay + EuropeSessionTime.TimeOfDay;
                AsiaSessionEndTime = EuropeSessionTime.AddMinutes(BarsPeriod.Value);
                }
                
                if (Time[0] >= AsiaSessionBeginTime)
                {
                Draw.Line(this, "AmericaCloseLine " + Time[0], false, AsiaSessionBeginTime, Close[0], AsiaSessionEndTimeLine, Close[0], Brushes.Gold, DashStyleHelper.Dash, 2);
                Draw.Rectangle(this, "AsiaRange" + Time[0], false, AsiaSessionBeginTime, AsiaSessionMax, AsiaSessionEndTime, AsiaSessionMin, Brushes.Transparent, Brushes.Gray, 15);
                }
                if (High[0] > AsiaSessionMax)
                {
                AsiaSessionMax = High[0];
                }
                if (Low[0] < AsiaSessionMin)
                {
                AsiaSessionMin = Low[0];
                }
                }
                }
                }

                Comment


                  #23
                  Hi Kate!
                  Thank you in advance for your excellent willingness to help us every day!

                  Comment


                    #24
                    Hello joselube001,

                    Thank you for your replies.

                    Just so you know and don't think I'm ignoring you, I'm working through your code and just haven't quite gotten the rectangles working how I'd expect, but I had to host a webinar today and that's slowed things down a bit. I'm about at the end of my day today but I'll continue to work on it in the morning and should have an example for you tomorrow.

                    Thanks in advance for your patience, I look forward to assisting you further.

                    Comment


                      #25
                      Thank you for your reply, Kate.

                      I understand that you are busy with other responsibilities.
                      Take the time you need, I appreciate very much your valuable help!

                      Cheers!

                      Comment


                        #26
                        Hello joselube001,

                        Thank you for your patience.

                        I've worked out some issues that were occurring - you weren't plotting the rectangle on the correct dates/times. I'm attaching an example of what I've done below. This is still going to require some additional work to deal with holidays, but this should give you a jumping off point.

                        Please let us know if we may be of further assistance to you.
                        Attached Files

                        Comment


                          #27
                          Hello Kate,

                          Thank you for your reply.

                          The indicator example that you sent is working well.

                          As you said, it requires some additional work to deal with holidays.

                          I will test it with the next holiday, and I will try to create the necessary conditions for holidays.

                          I have an idea for some conditions, but I don't know how it will be traduced in code.

                          I will write the results next Tuesday or later, after the tests.

                          Thank you very much for your great help!


                          Comment


                            #28
                            Originally posted by NinjaTrader_Kate View Post
                            Hello agilek,

                            Thank you for your reply.

                            I've created a relatively simple example indicator that should work in most scenarios. Basically, I have added a 1 minute additional data series to an indicator, and we have user inputs for the Start time and End time set to 0:00 and 08:00 respectively. At 8 am, we use MIN() and MAX() to get the lowest low and highest high. After 8 am passes, a line is drawn at the highest high and lowest low prices between the start time and current time of day. This repeats on each day. The lines are drawn using times and not bars ago indexes so we don't have to deal with figuring out how many bars ago to draw on the primary series.

                            Please let us know if we may be of further assistance to you.
                            Kate, i tried loading this on NQ 1 min and nothing showed?

                            Comment


                              #29
                              I know this series of posts on Drawing Asian session range lines is old. I downloaded the SessionHighLowLinesExample.zip file but it doesn't seem to work. I like that I can create times so that it can be used for the Asian market or London market. Is there a revised script that is similar?

                              Thanks,
                              Randy​

                              Comment


                                #30
                                Hello Randy,

                                It looks like an error may be appearing on the Log tab of the Control Center due to an invalid date.

                                Try adding:

                                if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
                                return;

                                to the top of OnBarUpdate().

                                Further, if the condition to set TodayStart does not have a value, this can cause an invalid date.

                                Change:

                                if(Times[1][0].TimeOfDay > SessionEnd.TimeOfDay)

                                To

                                if(Times[1][0].TimeOfDay > SessionEnd.TimeOfDay && TodayStart > new DateTime())

                                To ensure the variable has been set a value.
                                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
                                597 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                343 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                103 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                556 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                555 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X