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 with Global Drawing Objects

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

    Drawing line with Global Drawing Objects

    Hello, i need to drawing a line with color, DashStyle, and width, in global mode and in all charts.

    I am using this code
    Draw.Line(this, @"PreMercado Line_1 " + Convert.ToString(Times[0][1].Date), true, 1, Open1, Convert.ToInt32(Longitud_Linea), Open1, ColorBarraRoja, DashStyleHelper.Dash, Convert.ToInt32(Grosor_Linea),true); where can i select the color, the type of line, but it only draws me in one chart.

    I need to draw the line in ALL CHARTS.

    The solution is this code

    Draw.Line(this, @"PreMercado Line_1 " + Convert.ToString(Times[0][1].Date), true, 1, Open1, -50, Open1, true, null); to draw in mode global, but I can not put color and other options of the line.

    Can you help me, what is the solution

    Thanks for yur answer.


    #2
    Hi Faroka, thanks for writing in. Setting bool isGlobal = true will show the line on all charts of the same instrument, not all charts in the workspace. You would need to run this script on each chart with a different instrument to get this line to draw on every chart in your workspace.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your answer, my question is, how to do so that when drawing a line in global mode, it allows me to set the color, size and class of the line simultaneously

      Comment


        #4
        Hi faroka, thanks for the follow up. The script that is calling Draw.Line() needs to call Draw.Line() again with the new parameters to change the color across all charts. The Tag should also be the same so the old draw object is removed.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Chris L., Thanks for your answer.

          The first line of code I use

          Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, bool isGlobal, string templateName), where isGlobal is True.

          The Secod line of code I use

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

          in my script the code is:

          Draw.Line(this, @"PreMercado Line_1 " + Convert.ToString(Times[0][1].Date), false, 1, Open1, Convert.ToInt32(Longitud_Linea), Open1, true,null); Global
          Draw.Line(this, @"PreMercado Line_1 " + Convert.ToString(Times[0][1].Date), false, 1, Open1, Convert.ToInt32(Longitud_Linea), Open1, ColorBarraRoja, DashStyleHelper.Solid, Convert.ToInt32(Grosor_Linea),true); doesn't work on all charts​

          Comment


            #6
            Hi faroka, thanks for your reply. Can you please make a reduced test script and post it here and provide steps to reproduce this?

            Chris L.NinjaTrader Customer Service

            Comment


              #7
              I am making an indicator, so that it draws some lines in all charts,
              My indicator draws the line in global mode, that is, in all charts, but it does not let me set the color or size that the user has selected.



              Comment


                #8
                My script reduce is

                if (LineaSolida == true)
                {
                Draw.Line(this, "PreMercado Line_2 " + Convert.ToString(Times[0][1].Date), false, 1, Open1, Convert.ToInt32(Longitud_Linea), Open1, true,null);
                Draw.Line(this, "PreMercado Line_2 " + Convert.ToString(Times[0][1].Date), false, 1, Open1, Convert.ToInt32(Longitud_Linea), Open1, ColorBarraVerde, DashStyleHelper.Solid, Convert.ToInt32(Grosor_Linea));
                }
                else
                {
                Draw.Line(this, "PreMercado Line_2 " + Convert.ToString(Times[0][1].Date), false, 1, Open1, Convert.ToInt32(Longitud_Linea), Open1, true,null);
                Draw.Line(this, "PreMercado Line_2 " + Convert.ToString(Times[0][1].Date), false, 1, Open1, Convert.ToInt32(Longitud_Linea), Open1, ColorBarraVerde, DashStyleHelper.Dash, Convert.ToInt32(Grosor_Linea));
                }

                My question is, how can I draw a global line in all charts, and make it the desired color and size simultaneously?​

                Comment


                  #9
                  Chris L., Thanksssssssss


                  I was able to do it and it works very well.

                  "The script that is calling Draw.Line() needs to call Draw.Line() again with the new parameters to change the color across all charts."

                  First it is drawn with the desired colors and size and then it is redraw but globally, with the same tag name

                  Comment


                    #10
                    Hi faroka, thanks for your reply. There is no overload that takes a DashStyleHelper and IsGlobal parameter. The only overloads that take IsGlobal are here:

                    Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, bool isGlobal, string templateName)
                    Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, bool isGlobal, string templateName)

                    All of the documentation for Draw.Line can be found here:


                    To use these overloads, create the line you want to see manually, then double click it to edit its properties. After that, click Template>Save as on the bottom right of the window and give it a name. This is the name you will use in the templateName.

                    Kind regards,
                    -ChrisL
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Based on: https://ninjatrader.com/support/help....html?line.htm

                      Try this example:

                      Code:
                      protected override void OnBarUpdate()
                      {
                      if (State != State.Realtime) return;
                      
                      if (doitonce)
                      {
                      NinjaTrader.NinjaScript.DrawingTools.Line myLine = Draw.Line(this, "tag1", false, 10, High[10], 0, Low[0], true, "");
                      myLine.Stroke = new Stroke(Brushes.Green, DashStyleHelper.Dash, 5);
                      doitonce = false;  // just once for this example
                      }
                      
                      }
                      Note that doitonce is a private bool created as = true;​

                      in the initial Draw.Line the template name is "" meaning it will use your default line drawing color and characteristics, As you can see in the code example you can change just about any characteristic after the initial call. This example will apply a Green 5 width dash line on all charts of the same instrument once the first real time bar closes.
                      Last edited by Tasker-182; 11-17-2022, 01:07 PM.

                      Comment


                        #12

                        Thank you all so much for your help

                        I was able to solve the problem with my script

                        Thanks Chris L.
                        Thanks Tasker-182;​

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by bill2023, Yesterday, 08:21 AM
                        2 responses
                        14 views
                        0 likes
                        Last Post bill2023  
                        Started by ynoldsany, Today, 01:00 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post ynoldsany  
                        Started by Carolscogginsi, Yesterday, 10:45 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post Carolscogginsi  
                        Started by RaddiFX, Yesterday, 10:15 AM
                        2 responses
                        15 views
                        0 likes
                        Last Post RaddiFX
                        by RaddiFX
                         
                        Started by patrickmlee007, Yesterday, 09:33 AM
                        2 responses
                        19 views
                        0 likes
                        Last Post patrickmlee007  
                        Working...
                        X