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

Draw line

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

    Draw line

    I have a problem on drawing a line up to the price I want. I have attached an image on it. Thanks in advance.
    Attached Files

    #2
    You need to be more specific - for example - how are you selecting the end point of the line? If you just want to end it an arbitrary number of bars in the future use a negative number for the end bar.

    From the help guide

    // Draws a dotted lime green line from 10 bars back to 10 bars in the future with a width of 2 pixels
    DrawLine("tag1", false, 10, 1000, -10, 1001, Color.LimeGreen, DashStyle.Dot, 2);

    Comment


      #3
      stocktraderbmp would be correct - it would be important to know first how this line is drawn. Further you would need to set the datetime or bars into the future tied to your target end point, so you cannot extend simply to a price because that's just one coordinate needed.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thank you for that example.

        Comment


          #5
          drawing lines within a strategy

          I don't know whether this is the right place to post my question, but I'd like to print or to draw something (a line, a square, "Buy", the current price, ....) on the chart - if possible just above/below the current bar - whenever the conditions of my preferred strategy or indicator are triggered.
          Can someone please show to me in the praxis how this may be done either on the Strategy Wizard or with NinjaScript C++ (something similar to DrawText("My text "+Close[0], CurrentBar, 0, 0, Color.Red), in order to have a visual display (and control) of my signals and my entry points ?
          Thank you
          Last edited by fliesen; 01-20-2014, 12:42 PM.

          Comment


            #6
            Fliesen,

            Thank you for your post.

            You will need to decide with draw object you would want to use and where on the chart you would want to place it.
            If you are looking to do a box with text then you would want to use DrawRectangle and DrawText to place those above or below the CurrentBar.

            DrawRectangle
            DrawText
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              So why does the following code not work (= not draw), and how must I change it ?


              #region Using declarations
              using System;
              using System.ComponentModel;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Data;
              using NinjaTrader.Indicator;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Strategy;
              #endregion

              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
              /// <summary>
              /// Stoch+Fastoch+ Macd; and Ichimoku
              /// </summary>
              [Description("Stoch+Fastoch+ Macd; and Ichimoku")]
              public class AllWIZARD : Strategy
              {
              #region Variables
              // Wizard generated variables
              // User defined variables (add any user defined variables below)
              #endregion

              /// <summary>
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              /// </summary>
              protected override void Initialize()
              {

              CalculateOnBarClose = true;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              // Condition set 1
              if (Close[0] > 1) // condition always TRUE, should always draw something
              {
              BackColor = Color.Black;
              DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Blue); // just draws a dot
              DrawRectangle("My rectangle" + CurrentBar, 0, 0, 0, 0, Color.Blue); // just a rectangle above the current bar ?
              DrawText("My text" + CurrentBar, "Do something", 0, 0, Color.Red); // a text within the rectangle ?
              Alert(...........);
              }

              Comment


                #8
                fliesen, would be expected since you are literally drawing those objects at a price value of 0

                DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Blue); // just draws a dot
                DrawRectangle("My rectangle" + CurrentBar, 0, 0, 0, 0, Color.Blue); // just a rectangle above the current bar ?
                DrawText("My text" + CurrentBar, "Do something", 0, 0, Color.Red); // a text within the rectangle ?

                So those would then not be visualized - please try passing in a more meaningful price based value (i.e. Close[0] +/- an offset).
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Drawing on charts

                  Thanks for your answer, however there is something I don't understand:

                  - if not the correct price, at least a "0" should be anyway displayed, shouldn't it ?
                  - similarly, I suppose the "DrawDot" script had to print a dot in any case, and not a price;
                  - will the following lines solve the problem ?

                  DrawDot("My dot" + CurrentBar, false, 0, Close[0], Color.Blue);
                  DrawRectangle("My rectangle" + CurrentBar, 0, Close[1], 0, Close[0], Color.Blue);
                  DrawText("My text" + CurrentBar, "Do something", 0, Close[0], Color.Red);

                  - which chart will be affected by these lines, or in other words, which chart will display the price on the CurrentBar ?
                  - finally, how must I thank in order to avoid that "Thanks: 0" in my profile ?
                  Last edited by fliesen; 01-25-2014, 02:20 AM. Reason: help...

                  Comment


                    #10
                    Hello,

                    if not the correct price, at least a "0" should be anyway displayed, shouldn't it ?
                    Yes and no. The DrawDot as the property of Autoscale to allow you to choose if the dot gets scaled into the chart with the price bars. This was set to false and therefore not scaled in.

                    will the following lines solve the problem ?
                    Yes, however, I recommend that you set start and end bars ago values for the DrawRectangle, or you could end up with a line on the current bar (0) and not a rectangle.

                    which chart will be affected by these lines, or in other words, which chart will display the price on the CurrentBar ?
                    The only chart that will be affected will be the chart that you apply this indicator to.

                    finally, how must I thank in order to avoid that "Thanks: 0" in my profile ?
                    To 'Thank' a post there is a Thanks with a smiley face in the lower right hand corner of each post that you can click to thank the user for that post.

                    Let me know if I can be of further assistance.
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Also with the new code, I'm still not able to print anything on my charts.
                      Could you kindly give me a short, real example of a "DrawText" script printing whatever on the current bar of an opened chart ?
                      No rectangle is needed. Please, also consider that I'm not applying an indicator on a chart, but simply editing a normal strategy code or strategy wizard.

                      Comment


                        #12
                        DrawText("MyTag" + CurrentBar, "String to be displayed", 0, High[0], Color.Black);

                        This snippet will print "String to be displayed at each current bar at the High price value.
                        If you only just want one text being displayed and not every bar, then drop the + CurrentBar
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          I opened a brand new strategy, only with your snippet + a visual alert "DrawText", timeframe 1 minute, but when I click on the alert and open a chart with the same timeframe, I see nothing.
                          Where is the string going to be printed ???
                          Please see the chart: https://www.dropbox.com/s/lxawez690c...%20drawing.JPG
                          and the code: https://www.dropbox.com/s/n66mjarskm6exk2/Strategy.cs

                          Comment


                            #14
                            Fliesen,

                            I can't tell from the screenshot, but is the Strategy enabled?
                            Right click on the chart and select Strategies
                            Select the strategy in the lower left list and ensure the property "Enabled" is set to true
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #15
                              Yes, it's enabled.
                              I'm sure the code is ok. I think the problem is the (wrong) link between code and chart.
                              Or does this code work only for strategies embedded in the chart, and perhaeps not in the strategy wizard ?
                              Last edited by fliesen; 01-28-2014, 01:28 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by George21, Today, 10:07 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post George21  
                              Started by Stanfillirenfro, Today, 07:23 AM
                              8 responses
                              23 views
                              0 likes
                              Last Post Stanfillirenfro  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by navyguy06, Today, 09:28 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              8 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X