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 line from specific time

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

    Drawing line from specific time

    HI i want to be able to draw a line when bar opens at specific time, like 8:30 and it remains drawn until end of session.
    How do i insert time?

    if (Time[0].TimeOfDay == new TimeSpan(8, 30, 0))
    {
    openingPrice = Open[0];
    Draw.Line(this, "tag1"+CurrentBar, true, <time>, High[0], <until end of session>, High[0], Brushes.White, DashStyleHelper.Dash, 6);

    }​​

    #2
    Hello tkaboris,

    Thanks for your post.

    You could create user-defined time inputs called something like 'LineStartTime' set to 8:30AM by default.and 'LineEndTime' set to say 4:00PM

    Then you could create a condition that checks if Time[0] == LineStartTime and save the current Open price to your openingPrice variable.

    Create a Time Filter condition to check if the time is between LineStartTime and LineEndTime. The Draw.Line() method could be called in this condition with LineStartTime passed into the DateTime startTime argument, the openingPrice variable passed into the double startY and double endY arguments, and Time[0] could be passed into the DateTime endTime argument.

    I attached a simple example script demonstrating this. The example script draws a line at the 8:30AM High price from 8:30AM to the current bar.

    See the help guide documentation below for more information.

    Draw.Line():https://ninjatrader.com/support/help.../draw_line.htm
    Times: https://ninjatrader.com/support/help...ries_times.htm
    How to Create Time Filters: https://ninjatrader.com/support/help...der.htm​
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you thats what i need.

      I have a question. I have exisiting indicator and wanted to add this drawline there. However the strategy that uses my indicator strats companing because i added this new functionality says there are wrong number of arguments. My question is there a way just to include this into my existing indicator without have to deal with those argument issue?
      Thank you

      Comment


        #4
        Hello tkaboris,

        Thanks for your notes.

        What exactly does the error message state? Please send a screenshot of the error so we may accurately assist.
        • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
        • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.

        Is the error message being thrown by the indicator file or is it being thrown by the strategy file?​

        Note that you would have to supply a value for each argument listed in the Syntax seen on the Draw.Line() help guide page when calling this in your indicator script.

        In the syntax below from the help guide, we see a total of 10 arguments required.

        Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, DashStyleHelper dashStyle, int width)

        All 10 arguments would have to be defined when calling the Draw.Line() method in the indicator.

        See the Draw.Line() help guide page linked in post # 2 for more information.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          HI i will provide that later today. In the mean time
          I also wanted to draw line from higher timeframe low, but it doesnt draw. I basically want to have Low and higher low on each side of the Low. but it doesnt draw line

          AddDataSeries(BarsPeriodType.Minute, 60);

          if (BarsInProgress == 1)
          {
          if (CurrentBars[0] < 10 || CurrentBars[1] < 3 )
          return;
          if(Low[1] < Low[2] && Low[0] < Low[1])
          {
          Print("time for low"+Time[0]);
          Draw.Line(this, "tag1"+CurrentBar, 1, Low[0],0, Low[0],Brushes.Aqua);
          // Draw.Line(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush)
          }
          }​






          Comment


            #6
            Hello tkaboris,

            Thanks for your notes.

            To clarify, are you wanting to draw the line from the Low price of the primary series to the Low price of the added secondary series?

            Or, do you want to draw two lines on the primary series, one at the primary series Low price and one at the secondary added series Low price?

            If you want to draw one line on the primary series from the Low price of the primary series to the Low price of the added secondary series, you could call Draw.Line() outside of the BarsInProgress 1 condition and set the startY argument to use Low[0] and set the endY argument to use Lows[1][0].

            If you want to draw two lines on the primary series, one at the primary series Low price and one at the secondary added series Low price, you could call Draw.Line() twice outside of BarsInProgress 1. You would supply the primary series Low price (Low[[0]) to the startY and endY parameters of the first Draw.Line() method.

            You could specify the secondary series Low price (Lows[1][0]) to the startY and endY parameters of the second Draw.Line() method.

            See the help guide documentation below for more information.

            Low: https://ninjatrader.com/support/helpGuides/nt8/low.htm
            Lows: https://ninjatrader.com/support/helpGuides/nt8/lows.htm
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              HI i am trying to draw line on primary series, but line is fro secondary series low swing. Draw this line from its start until current bar.
              How do i select print line until current bar?

              Code:
              protected override void OnBarUpdate()
                      {
                          if (BarsInProgress == 0)
                          {
                          if (CurrentBars[0] < 3 || CurrentBars[1] < 3)
                              return;
              
                          if (Time[0] == LineStartTime)
                          {
                              High830 = High[0];
                          }
              
                          if (((Times[0][0].TimeOfDay >= LineStartTime.TimeOfDay)
                               || (Times[0][0].TimeOfDay <= LineEndTime.TimeOfDay)))
                          {
                              Draw.Line(this, "tag", false, LineStartTime, High830, LineEndTime, High830, Brushes.Blue, DashStyleHelper.Solid, 2);
                          }
                          }
                          if (BarsInProgress == 1 && CurrentBars[1] > 3)
                          {
              
                          if (Lows[1][1] < Lows[1][2] && Lows[1][1] < Lows[1][0])
                          {
                              Print(Time[0]);
                              Draw.Line(this, "tag"+CurrentBar, false, 1, Lows[1][1], -100, Lows[1][1], Brushes.Blue, DashStyleHelper.Dot, 2);
              //                Draw.Line(this, "tag1", false, 10, Close[0], -100, Close[0], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
              //                Draw.Line(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush)
                          }
                          }
              
                      }​
              
                      }​
              Last edited by tkaboris; 10-25-2023, 12:34 PM.

              Comment


                #8
                Hello tkaboris,

                Thanks for your notes.

                I am not certain I fully understand what it is you are trying to accomplish.

                Are you trying to Draw the line at a specific value calculated from the added series?

                You could consider creating a class-level variable, calculating the value you want to draw the line at in BarsInProgress 1, and assigning the value to the variable. Then call the Draw.Line() method underneath your other Draw.Line() method and pass in the variable holding the calculated value from the added series.

                I see you are passing in a -1 for the endBarsAgo argument when calling Draw.Line(). Note that this is not supported and a value of 0 or greater should be used for BarsAgo values.

                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  I used this example to extend line into the future, it was suggested by Kate and it works but you have to specify how many bars into the future, and i want until current bar

                  Hi, I will draw Line from my indicator and I want to extend the right from indicator on some condition. How to do that ?


                  Well if its not the right approach. I still dont understand how i can extend the line until current bar on primary series?
                  so I get the level from Higher time frame and draw it on primary series...

                  Comment


                    #10
                    Hello tkaboris,

                    Thanks for your notes.

                    It would be possible to pass a negative barsAgo value into the Draw method and this may work as you noted.

                    However, note that supplying a negative value for barsAgo is unsupported and would be up to your discretion to use in your script.

                    Typically, if you want to have a line drawn to the current bar, the supported way to do this would be to set the barsAgo value to 0 and use Calculate.OnPriceChange for the script.

                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      I dont understand this part
                      "and use Calculate.OnPriceChange for the script."
                      what script can I come up with to arrive to current bar?

                      if i have this line, it doesnt plot anything
                      Draw.Line(this, "tag"+CurrentBar, false, 1, Lows[1][1], 0, Lows[1][1], Brushes.Blue, DashStyleHelper.Dot, 2);

                      Comment


                        #12
                        Hello tkaboris,

                        Thanks for your notes.

                        If using the logic from the example script in the forum thread you shared in post # 9 works for your then you could certainly go ahead and use that logic at your own discretion.

                        Otherwise, you could consider using barsAgo value of 0 for the endBarsAgo argument when calling the Draw.Line() method and set the Calculate mode in State.SetDefaults to Calculate.OnPriceChange.

                        "if i have this line, it doesnt plot anything"

                        When testing that line of code on my end by adding it into a simple if (BarsInProgress == 1) { //call draw method } condition, I do see a draw object appear on the chart. Note that Calculate is set to Calculate.OnPriceChange in State.SetDefaults so the line is drawn to the current building bar on the chart.

                        Calculate: https://ninjatrader.com/support/help.../calculate.htm

                        See the attached screenshot:

                        If an object is not drawing on the chart as expected you would have to debug your strategy by adding prints to understand how your logic is behaving. Add prints one line above each condition that prints out each value in the condition logic to see how they are evaluating. Also, note the Log tab of the Control Center for any errors that may appear.

                        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
                        https://ninjatrader.com/support/foru...121#post791121
                        Attached Files
                        Last edited by NinjaTrader_BrandonH; 10-25-2023, 02:07 PM.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you i am not drawing line too.
                          However how can i make sure to draw line starting from the this point.
                          This is my script

                          if (BarsInProgress == 1 && CurrentBars[1] > 3)
                          {

                          if (Lows[1][1] < Lows[1][2] && Lows[1][1] < Lows[1][0])
                          {
                          Print(Time[0]);
                          Draw.Line(this, "tagLiquidityLow"+CurrentBar, false, 1, Lows[1][1], -100, Lows[1][1], Brushes.Green, DashStyleHelper.Dot, 3);

                          }​​

                          Click image for larger version

Name:	image.png
Views:	144
Size:	80.5 KB
ID:	1274726

                          Comment


                            #14
                            Hello tkaboris,

                            Thanks for your notes.

                            Something you could consider is saving the CurrentBar index for where you want to draw the line to an int variable called something like 'DrawStartBar'.

                            Then, you could subtract the variable from CurrentBar to get the barsAgo value of that bar and pass that into the startBarsAgo argument when calling Draw.Line().

                            For example:

                            //class-level variable
                            private int DrawStartBar;

                            //OnBarUpdate()
                            //condition to detect the bar
                            if (condition)
                            {
                            DrawStartBar = CurrentBar;
                            }

                            Draw.Line(this, "tag", false, CurrentBar - DrawStartBars, Low[0], 0, Low[0], Brushes.Blue, DashStyleHelper.Solid, 2);


                            Note that it would ultimately be up to you to come up with the specific logic to detect those bars on the chart and accomplish your overall goal.

                            Draw.Line(): https://ninjatrader.com/support/help.../draw_line.htm
                            CurrentBar: https://ninjatrader.com/support/help...currentbar.htm
                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #15
                              thank you
                              I did that and placed this code in secondary series but still it starts later not from where low actually starts. Maybe i should move this logic to primary series?
                              if (BarsInProgress == 1 && CurrentBars[1] > 3)
                              {

                              if (Lows[1][1] < Lows[1][2] && Lows[1][1] < Lows[1][0])
                              {
                              DrawStartBar = CurrentBar;
                              }​

                              if (Lows[1][1] < Lows[1][2] && Lows[1][1] < Lows[1][0])
                              {

                              Draw.Line(this, "tagLiquidityLow"+CurrentBar, false, CurrentBar - DrawStartBar, Lows[1][1], -100, Lows[1][1], Brushes.Green, DashStyleHelper.Dot, 3);

                              }​

                              Click image for larger version

Name:	image.png
Views:	145
Size:	15.6 KB
ID:	1274745

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by lightsun47, Today, 03:51 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post lightsun47  
                              Started by 00nevest, Today, 02:27 PM
                              1 response
                              8 views
                              0 likes
                              Last Post 00nevest  
                              Started by futtrader, 04-21-2024, 01:50 AM
                              4 responses
                              42 views
                              0 likes
                              Last Post futtrader  
                              Started by Option Whisperer, Today, 09:55 AM
                              1 response
                              13 views
                              0 likes
                              Last Post bltdavid  
                              Started by port119, Today, 02:43 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post port119
                              by port119
                               
                              Working...
                              X