Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing a line from a certain time to current

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

    #16
    Thanks JC for answer.
    I´m not too familiar with the Ninja script... but I wrote close where open was writen and it is working. But I need the line only for the last bar. And is it possible the line would be from that bar to the right not to the left?
    Thanks

    Comment


      #17
      Hello enums,

      Glad to hear that it is working for you.

      You may view the following thread that has many helpful link when getting starting programming an Indicator using NinjaTrader.


      It is drawing a line (DrawLine) from a specific time to a specific time (9:30AM to 4:15PM based on your Local PC clock). If you would like to the line to be drawn farther you can change the time that it is being drawn at. For example:

      Code:
      this.DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 7, 30, 0),
      					Close[open], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 17, 15, 0), Close[open], Color.Blue, DashStyle.Dash, 2);
      This will draw the lien from 7:30AM to 5:15PM.
      JCNinjaTrader Customer Service

      Comment


        #18
        Hello,

        I have a different timezone on my computer (same as broker) and therefore I need to draw the line from one day into the other. This means from 22:00 to 14:00.

        How can I do this please? What do I have to change in this example.

        Thanks
        Tony

        Comment


          #19
          Hello tonynt,

          Thank you for your post.

          You can use the following:
          Code:
          			int open = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 22, 0, 0)); if (CurrentBar > open)
          			
          			this.DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 1, 22, 0, 0), Close[open], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 14, 0, 0), Close[open], Color.Blue, DashStyle.Dash, 2);
          Please let me know if you have any questions.

          Comment


            #20
            Patrick,

            thank you for your reply. I have done exactly as indicated but in the attached screenshot you can see that

            * the drawline (with blue, dashed) is not plotted every day. Why?

            * its only correct on 4/30 with starting at the correct time AND PRICE (it matches with an other indicator in cyan color there, so you can see)

            * what need to be changed so that it starts every day WITH HTE PRICE AT THAT TIME 22:00

            Thank you for your support
            Tony

            Originally posted by NinjaTrader_PatrickH View Post
            Hello tonynt,

            Thank you for your post.

            You can use the following:
            Code:
                        int open = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 22, 0, 0)); if (CurrentBar > open)
                        
                        this.DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 1, 22, 0, 0), Close[open], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 14, 0, 0), Close[open], Color.Blue, DashStyle.Dash, 2);
            Please let me know if you have any questions.
            Last edited by tonynt; 05-13-2013, 11:24 AM. Reason: clearify

            Comment


              #21
              Hello tonynt,

              Thank you for your response.

              I am able to see the line on each day. Please attach a screenshot of your chart to your response so I may investigate this matter further.

              Comment


                #22
                Hello,

                verry sorry, I forgot the attachment.

                In the meantime I did some changes. Could it be that in your "int open....= Day -1...." would be correct? Sorry, just an idea.

                And I also did change to get on Mondays the correct beginning on Friday (I found in the forum to start 3 days back).

                BUT from May I have no lines! Only in the month of April they are plotted. Maybe this is somehow the month? But I dont know how to add this to
                if (Bars.FirstBarOfSession && FirstTickOfBar)
                {
                /* If the day is Monday, and we want the value from Friday, we must subtract 3 days from the current date. If the day is Tuesday-Friday, just subtract one day. */
                if (Time[0].DayOfWeek == DayOfWeek.Monday)
                timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 3, 22, 00, 0);
                else
                timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day - 1, 22, 00, 0);
                }

                Please see my attached Drawline_NEW.jpg.

                Thanks
                Tony

                Originally posted by NinjaTrader_PatrickH View Post
                Hello tonynt,

                Thank you for your response.

                I am able to see the line on each day. Please attach a screenshot of your chart to your response so I may investigate this matter further.
                Attached Files
                Last edited by tonynt; 05-13-2013, 02:22 PM. Reason: clearify

                Comment


                  #23
                  Hello tony.nt,

                  Thank you for your response.

                  That is it, the -1 was causing a day of 0 on the first day of the month. This would be outside the bounds of the array for the day of the month. I had to create a check to not run this if the day returned as 0.
                  Code:
                  int numberDay = Time[0].Day - 1;
                  if(numberDay == 0)
                  return;
                  
                  DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, numberDay, 22, 0, 0), Close[0], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 14, 0, 0), Close[0], Color.Blue, DashStyle.Dash, 2);
                  Please let me know if I may be of further assistance.

                  Comment


                    #24
                    Hello Patrick,

                    thank you for your reply. This works within actual month only. But in charts with more days the lines are plotted only the first month.

                    Referring to my question how to start the line at the price at that time the day before, how would you do this please (using range bars, so close[xy] would not work because close of range bar will not be at 22:00)


                    Thanks
                    Tony






                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello tony.nt,

                    Thank you for your response.

                    That is it, the -1 was causing a day of 0 on the first day of the month. This would be outside the bounds of the array for the day of the month. I had to create a check to not run this if the day returned as 0.
                    Code:
                    int numberDay = Time[0].Day - 1;
                    if(numberDay == 0)
                    return;
                    
                    DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, Time[0].Month, numberDay, 22, 0, 0), Close[0], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 14, 0, 0), Close[0], Color.Blue, DashStyle.Dash, 2);
                    Please let me know if I may be of further assistance.

                    Comment


                      #25
                      Hello Tony,

                      Thank you for your response.

                      I am seeing the lines on all months, please provide a screenshot of the first month only being plotted.

                      I look forward to your response.
                      Attached Files

                      Comment


                        #26
                        Hello Patrick,

                        thank you for your reply.

                        I have removed my changes - I did to find the bug with -1 - and I now have exactly your solution.

                        But please see that after weekends there is something wrong as one day the line is missing and the other day there are 2 lines. And what if on Friday or Monday there is holiday?

                        And how would you do to start the lines the day before at 22:00 when using in range bars (where close of bar is not at 22:00). However with close[0] the line starts not at 22:00 minute bars the day before.

                        Please see the forex-chart.

                        Thanks
                        Tony


                        Originally posted by NinjaTrader_PatrickH View Post
                        Hello Tony,

                        Thank you for your response.

                        I am seeing the lines on all months, please provide a screenshot of the first month only being plotted.

                        I look forward to your response.
                        Attached Files
                        Last edited by tonynt; 05-14-2013, 01:28 PM. Reason: clearify

                        Comment


                          #27
                          Hello Tony,

                          Thank you for your response.

                          I see the same behavior on my end, I am looking into this further to try and resolve this.

                          Comment


                            #28
                            Hello Tony,

                            Thank you for your patience.

                            I had to create two IntSeries here for the Time[0].Day and Time[0].Month, this was needed to be able to change the month and day when there were missing days (days not traded) or a transition from one day to the next. My code is below:
                            Code:
                                    #region Variables
                            		private IntSeries numberDay;
                            		private IntSeries numberMonth;
                                    #endregion
                            
                                    protected override void Initialize()
                            		{
                            			numberDay = new IntSeries(this);
                            			numberMonth = new IntSeries(this);
                            		}
                            
                                   
                                    protected override void OnBarUpdate()
                                    {
                            			if(CurrentBar == 0)
                            			{
                            				numberDay.Set(1);
                            				numberMonth.Set(1);
                            			}
                            			
                            			else
                            			{
                            				numberDay.Set(Time[0].AddDays(-1).Day);
                            				numberMonth.Set(Time[0].Month);
                            				
                            				if(numberDay[0] > numberDay[1] + 1)
                            				{
                            					numberDay.Set(Time[0].AddDays(-2).Day);
                            				}
                            				
                            				if(Time[0].AddDays(-1).Day > Time[0].Day)
                            				{
                            					numberMonth.Set(Time[0].AddMonths(- 1).Month);
                            				}
                            				
                            				DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, numberMonth[0], numberDay[0], 22, 0, 0), Close[0], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 14, 0, 0), Close[0], Color.Blue, DashStyle.Dash, 2);
                            			}
                            		}
                            Please let me know if I may be of further assistance.

                            Comment


                              #29
                              Hello Patrick,

                              please see the attached screenshot of EURUSD.

                              There is no line some days.

                              And the lines do not start at the price at the beginning of the line.

                              Best
                              Tony


                              Originally posted by NinjaTrader_PatrickH View Post
                              Hello Tony,

                              Thank you for your patience.

                              I had to create two IntSeries here for the Time[0].Day and Time[0].Month, this was needed to be able to change the month and day when there were missing days (days not traded) or a transition from one day to the next. My code is below:
                              Code:
                                      #region Variables
                                      private IntSeries numberDay;
                                      private IntSeries numberMonth;
                                      #endregion
                              
                                      protected override void Initialize()
                                      {
                                          numberDay = new IntSeries(this);
                                          numberMonth = new IntSeries(this);
                                      }
                              
                                     
                                      protected override void OnBarUpdate()
                                      {
                                          if(CurrentBar == 0)
                                          {
                                              numberDay.Set(1);
                                              numberMonth.Set(1);
                                          }
                                          
                                          else
                                          {
                                              numberDay.Set(Time[0].AddDays(-1).Day);
                                              numberMonth.Set(Time[0].Month);
                                              
                                              if(numberDay[0] > numberDay[1] + 1)
                                              {
                                                  numberDay.Set(Time[0].AddDays(-2).Day);
                                              }
                                              
                                              if(Time[0].AddDays(-1).Day > Time[0].Day)
                                              {
                                                  numberMonth.Set(Time[0].AddMonths(- 1).Month);
                                              }
                                              
                                              DrawLine("tag" + Time[0].Date.ToString("yyyyMMdd"), false, new DateTime(Time[0].Year, numberMonth[0], numberDay[0], 22, 0, 0), Close[0], new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 14, 0, 0), Close[0], Color.Blue, DashStyle.Dash, 2);
                                          }
                                      }
                              Please let me know if I may be of further assistance.
                              Attached Files

                              Comment


                                #30
                                Hello Tony,

                                Thank you for your response.

                                I do not see the same behavior on my end.

                                What time zone is your PC set to? And what region?

                                I look forward to your response.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Today, 05:17 AM
                                0 responses
                                39 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                124 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                64 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                41 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                46 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X