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

Drawing asian session range lines

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

    Drawing asian session range lines

    Hello guys,
    I want to make indicator that draw asian session(0:00 - 8:00) range lines. One line for highest high in session, another line for lowest low. I want the lines to continue to the end of the day. And I want them to draw for every day in loaded data, not just current day.

    So I need to loop through historical data somehow, find the price levels, somehow find last candle of day and draw line.
    I have been looking through documentation, but didnt find suitable methods or approaches.
    Can you guys give me approach how to implement this and suitable methods to use?

    Thanks

    #2
    Hello,

    Thank you for your post.

    To clarify, is this intended for forex use? Would you be calculating the lines and drawing them over just that session from 0:00 to 8:00 or over the full trading day, just calculating the highest high and lowest low of that session after 8:00?

    Are you using time based charts? What interval are you using for the chart?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      It is intended to work for forex, indexes and futures. Does it matter?

      It should draw on every timeframe you open, doesn't matter if you use 1 minute chart or daily, or hourly, you should always see the lines. (It would be nice if it worked also for tick or volume chart, but that's not really necessary.)

      What is important is also that it detects the session on every day in loaded data, so you could just move chart to left and you would see the lines in every day, not just the actual day.

      Basically after 8:00 the range for day is finished and there is no need to calculate it for that day again.

      I am new to ninjatrader indicator development, so I don't really know what approach to use and how to implement it, I have programming skills though.

      How do I loop all loaded data from the oldest bar to newest? Or should I use another approach?

      I hope I clarified it.
      Last edited by agilek; 09-13-2021, 10:21 AM.

      Comment


        #4
        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.
        Attached Files
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks it works great! This is exactly what I had in mind. But it doesn't seem to work for example on ES 09-21, why is that?

          So OnBarUpdate method is called on every loaded bar(even in past)? I thought it is only for new bars...

          Comment


            #6
            Hello agilek,

            Thank you for your reply.

            I'm seeing it work on that particular instrument:

            Click image for larger version

Name:	2021-09-13_11-59-26.png
Views:	1016
Size:	102.9 KB
ID:	1171012

            I'm in the Mountain Time Zone and am wondering if a time zone issue may be why you're not seeing it on these - what is your time zone so I may test to see if that makes a difference?

            And yes, OnBarUpdate will be called once for each historical bar before the script reaches real time data.

            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              I am in Europe, so I have Central European Summer Time(UTC+2) right now, in winter it is UTC+1.

              Comment


                #8
                Hello agilek,

                Thank you for your reply.

                The break between each session for the ES 09-21 would occur between 23:01 and 0:00 - the first bar of the new session would be the bar closing at 0:01. Try changing the start time to 12:01 AM and you should see it work on futures.

                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  12:01 works incorrectly, but 0:01 seems to work, thanks

                  Comment


                    #10
                    May I have another question?
                    I am trying to draw a text at the end of the line.

                    this is the code:

                    Code:
                    if(Times[1][0].TimeOfDay > _endDateTime.TimeOfDay)
                    {
                    Draw.Line(this, TodayEndBar.ToString()+"High", false, TodayStart, HighestHigh, Times[1][0], HighestHigh, L100.Brush, L100.DashStyleHelper, (int)L100.Width);
                    
                    int barsAgo = CurrentBar - Bars.GetBar(Times[1][0]);
                    Draw.Text(this, TodayEndBar.ToString()+"High"+"Label", "High", barsAgo, HighestHigh);
                    
                    Draw.Line(this, TodayEndBar.ToString()+"Low", false, TodayStart, LowestLow, Times[1][0], LowestLow, L0.Brush, L0.DashStyleHelper, (int)L0.Width);
                    }
                    But when I add the Draw.Text method, it stops drawing the lines. The indicator just shows Calculating..
                    Thanks
                    Last edited by agilek; 09-13-2021, 02:08 PM.

                    Comment


                      #11
                      Hello agilek,

                      Thank you for your reply.

                      The following works pretty well for me, though you might want to increase the bars ago it draws at so it's not overrunning the line:

                      Draw.Line(this, TodayEndBar.ToString()+"High", false, TodayStart, HighestHigh, Times[1][0], HighestHigh, Brushes.Green, DashStyleHelper.Dash, 2);
                      Draw.Text(this, TodayEndBar.ToString()+"HighLabel", "High: " + HighestHigh, 0, HighestHigh + (2 * TickSize), Brushes.Green);
                      Draw.Line(this, TodayEndBar.ToString()+"Low", false, TodayStart, LowestLow, Times[1][0], LowestLow, Brushes.Red, DashStyleHelper.Dash, 2);
                      Draw.Text(this, TodayEndBar.ToString()+"LowLabel", "Low: " + LowestLow, 0, LowestLow + (2 * TickSize), Brushes.Red);

                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks a lot.
                        I have another problem. I have Stroke as a user input property that user can configure, so user can configure color, width etc.
                        But In the chart on top the text shows all the Strokes that I have-I have actually multiple lines. How to disable this, can I hide them in this text?
                        Attached Files

                        Comment


                          #13
                          Hello agilek,

                          Thank you for your reply.

                          You can try the following to remove the whole script name from up there or just the parameters:

                          Add this before OnBarUpdate.

                          Remove both name & parameters:

                          Code:
                          public override string DisplayName { get { return "";} }
                          Remove parameters only:

                          Code:
                          public override string DisplayName { get { return this.Name;} }
                          Please let us know if we may be of further assistance to you.
                          Kate W.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Kate!

                            Continuing with this thread, I have an error customizing "DisplayName" when I use "Instrument.FullName" inside the name:
                            Code:
                            public override string DisplayName { get { return (this.Name + " (" + [B][COLOR=#c0392b]Instrument.FullName[/COLOR][/B] + " (" + BarsPeriod + "))"); }
                            Click image for larger version

Name:	Like it shows customized but with error.png
Views:	948
Size:	13.3 KB
ID:	1184332

                            If I use "Instrument" only, instead "Instrument.FullName", the error disappears, but the name adds "Globex" and I don't want that word in the indicator name:
                            Code:
                            public override string DisplayName { get { return (this.Name + " (" + [COLOR=#27ae60][B]Instrument[/B][/COLOR] + " (" + BarsPeriod + "))"); }
                            Click image for larger version

Name:	No error but Globex.png
Views:	929
Size:	11.0 KB
ID:	1184333


                            This need is because I want the indicator name to look like the original name, but without the configuration texts that appear after the name in the charts and indicators windows:
                            Click image for larger version

Name:	Like it shows normally.png
Views:	908
Size:	10.3 KB
ID:	1184334

                            How you can replicate this error:
                            1. Edit the name of any indicator and add the code that shows the error.
                            2. Compile the indicator.
                            3. Open a chart
                            4. Add the indicator modified and click "OK"
                            5. Open the indicators window with "HotKey", (I have assigned "Ctrl+I), and no matter if I change the hotkey, it continues showing an error.
                            If you open it from the indicators icon doesn't show an error.
                            6. The error appears.

                            If it is possible I would like to see the name in this way for any instrument:
                            Click image for larger version

Name:	The ideal name.png
Views:	905
Size:	8.5 KB
ID:	1184335
                            ​​​
                            Any help is welcome!
                            Thank you!

                            Comment


                              #15
                              Hello joselube001,

                              Thank you for your note.

                              The error is occurring because NinjaTrader has to load the display name for the indicator into the indicators dialog, and at that point no Instrument is associated with the strategy, so you get an error. You'd want to check if the instrument is null and if so, then just display the indicator name in the list, if there's an associated instrument because it's been added to a chart, then print the whole name on the chart display:

                              Code:
                              public override string DisplayName
                              {
                              get
                              {
                              if(this.Instrument != null)
                              {
                              return (this.Name + " (" + Instrument.FullName.ToString() + " (" + BarsPeriod + "))");
                              }
                              else
                              {
                              return (this.Name);
                              }
                              }
                              }
                              Please let us know if we may be of further assistance to you.
                              Kate W.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by lorem, Yesterday, 09:18 AM
                              4 responses
                              14 views
                              0 likes
                              Last Post lorem
                              by lorem
                               
                              Started by Spiderbird, Today, 12:15 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Spiderbird  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              12 responses
                              42 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by FrazMann, Today, 11:21 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post FrazMann  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X