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

NinjaScript Global Drawing Object for Indicator

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

    NinjaScript Global Drawing Object for Indicator

    Hello,

    I created a new indicator that draws a horizontal line on the chart when specific criteria have been met.

    Is there a way to change the Global Drawing Object code so that the horizontal line can also be displayed on other charts that have Global Drawing Object turned on?

    I have multiple computer monitors, and at this time I have the indicator activated on a few of my tick charts. But on another computer monitor that I use, I have minute-based charts (1 minute chart, 2 minute chart, 5 minute chart, etc.)

    In fast moving markets, while I'm analyzing my minute based charts, I would like for one of the horizontal lines that appear indicating that specific criteria on my 75 tick chart has been met, to also appear on my minute-based charts.

    Is that possible? And if so, what code would I add into the indicator NinjaScript?

    The first attached screenshot shows the current Global Drawing Object setting for the new indicator that I created. The second screenshot shows the Global Drawing Object settings for a horizontal line that I manually added to a chart.

    The third attached screenshot shows my current horizontal line code for the indicator.
    Attached Files

    #2
    Hello i2w8am9ii2,

    Thank you for the post.

    You can use this HorizontalLine overload that takes an "isGlobal" boolean and a templateName. Using this will cause the line to be drawn on all charts of the same instrument. Note that you must first draw a line manually, then enter its properties and save it as a template. You will supply that template name to the templateName string.

    Code:
    Draw.HorizontalLine(NinjaScriptBase owner, string tag, double y, bool isGlobal, string templateName)


    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      Thanks for your reply and for the info.

      I am new to NinjaScript and to C# so I'm not quite sure how to implement what you are suggesting I can do.

      The attached screenshots show three horizontal lines that I drew manually. I named them as templates with the following names:

      RSI-EMA-ParSAR-Price-Green1

      RSI-EMA-ParSAR-Price-Pink1

      RSI-EMA-ParSAR-Price-Transparent

      So my uncertainty and question at this time is, would I leave my existing Draw.HorizontalLine code and add additional Draw.HorizontalLine code, or would I edit my existing Draw.HorizontalLine code?

      If I would edit it, would the following be correct, if not, what would I change?

      if (High[0] > Open[0])
      Draw.HorizontalLine(this, "soTag002", Close[0] - numTicksBeyondCandle * TickSize, DashStyleHelper.Solid, lineThickness, double y, bool isGlobal, string RSI-EMA-ParSAR-Price-Green1);

      else if (Low[0] < Open[0])
      Draw.HorizontalLine(this, "soTag002", Close[0] - numTicksBeyondCandle * TickSize, Brushes.Transparent, DashStyleHelper.Solid, lineThickness, double y, bool isGlobal, string RSI-EMA-ParSAR-Price-Transparent);

      if (Low[0] < Open[0])
      Draw.HorizontalLine(this, "soTag002", Close[0] + numTicksBeyondCandle * TickSize, Brushes.DeepPink, DashStyleHelper.Solid, lineThickness , double y, bool isGlobal, string RSI-EMA-ParSAR-Price-Pink1);

      else if (High[0] > Open[0])
      Draw.HorizontalLine(this, "soTag002", Close[0] - numTicksBeyondCandle * TickSize, Brushes.Transparent, DashStyleHelper.Solid, lineThickness, double y, bool isGlobal, string RSI-EMA-ParSAR-Price-Transparent);
      }

      else
      Draw.HorizontalLine(this, "soTag002", Close[0] - numTicksBeyondCandle * TickSize, Brushes.Transparent, DashStyleHelper.Solid, lineThickness, double y, bool isGlobal, string RSI-EMA-ParSAR-Price-Transparent);

      I know it would seem easier to just add the indicator to my minute-based charts instead of going through the hassle of this code, but I tried adding it to my minute-based charts and the horizontal line was not being drawn correctly. I think I have conflicting indicators or too many indicators on my minute-based charts.
      Attached Files

      Comment


        #4
        Hello i2w8am9ii2,

        Thank you for the reply.

        Use the following overload, this is simply a declaration to show you the parameters:

        Code:
        Draw.HorizontalLine(NinjaScriptBase owner, string tag, double y, bool isGlobal, string templateName)
        Then input the correct parameters. You would do something to this effect:

        This line will globally draw a horizontal line on the close price to each chart. I have a template for the horizontal line named test:

        Code:
        Draw.HorizontalLine(this, "Price", Close[0], true, "test");
        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris,

          Thanks for your reply.

          I have the indicator on a 75 tick chart, a 150 tick chart, a 300 tick chart and 600 tick chart.

          I'm assuming that if I change my existing code to the code that you show which uses a template for the horizontal line, that the new code to draw the lines on my minute-based charts will not override or alter the horizontal lines that are drawn on any of my tick charts, is that correct?

          And I would keep the draw colors the same? That is very important, as the indicator only indicates what actions to take based on a LimeGreen color, a DeepPink color or a Transparent horizontal line color.

          Comment


            #6
            Hello i2w8am9ii2,

            Thanks for the reply.

            A manually drawn drawing tool will not be interacted with by your script. You can keep the line colors the same, they will be determined by the template that you save.

            Please let me know if I may be of any further assistance.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris,

              Great. Thanks for the info.

              Comment


                #8
                Hello there,
                I have a question related with this...
                How can I create a template from ninjascript, in order to avoid that the user of the indicator should create the template before use it?

                Thanks.

                Comment


                  #9
                  Hi Nutriax, thanks for your question.

                  You cant make a template through NinjaScript. You could include the template within your NinjaScript export file as described here:



                  So you would need to add a folder, templates\DrawingTool and place the drawing tool template within. Then add this folder to the decompressed .zip file, then .zip it back up.

                  Please let me know if I can assist any further.
                  Chris L.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,607 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  19 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  16 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X