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

How can I draw a line which extends with

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

    How can I draw a line which extends with

    every new bar formed but stops when certain conditions are fulfilled?

    #2
    Kay, a simple example of how to achieve this can be found in the second part of this sample - http://www.ninjatrader-support2.com/...ead.php?t=3419
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      The problem with DrawLine is that I need an endbar. The line can't extend/update as and when a new bar is formed/completed.

      Some have suggested using the Plot function but I am not sure how to stop the line from extending if certain conditions are fulfilled for either function....

      Comment


        #4
        Correct, you could use Plots as well...and then don't set values for the time periods where your conditions are not evaluating to true...

        For the DrawLine, the idea is to update endBar as the condition is true and stop when false, the sample shows this technique.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          If (!Condition)
          {
          DrawLine("Line", int StartBarsAgo, int Start y, 0, int End y, Color.color);
          }

          This will always draw a line to the current bar.

          Comment


            #6
            dhunnewell, you are correct in that the line is drawn to the current bar but it does not update as new bars are formed...

            Comment


              #7
              Hi Bertrand,

              I added these 2 lines

              if ((Close[0] <= doubleY) && (doubleY >0))
              {
              AvgR.Set(doubleY);
              }

              PLUS

              public DataSeries AvgR
              {
              get { return Values[0]; }
              }

              under properties.

              The result: An orange line.
              1) How did I get an orange line? I have not selected "orange" as a color in my code.
              2) How can I change it to green?
              3) Instead of a Solid line, can I get a Dash line?
              4) Ideally I can get the line to stop printing once is greater than doubleY and recommence when a new 9 is completed...
              Attached Files
              Last edited by kaywai; 03-02-2010, 01:43 AM.

              Comment


                #8
                How do I remove the vertical lines? Same code as below.
                Attached Files

                Comment


                  #9
                  Kay, for the colors you would need to check into your Plot definitions in the Initialize method.

                  You could remove the vertical steps by changing the Plot to another style for example Dots.

                  To stop it from showing, just don't set a value anymore for the plot as your conditions change.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Bertrand,

                    1) Aside from the DataSeries, I didn't even add anything to the initialize method. Definitely nothing to do with plots. I've attached the code fyi.
                    2) How do I assign a zero value to the plot as conditions change?
                    Attached Files

                    Comment


                      #11
                      I see, this is just the default color when nothing is assigned as in your case...please add to the Initialize() as per this link to be able to control visualizations for this - http://www.ninjatrader-support.com/H...eV6/Plots.html

                      You could just call the Reset method for the underlying dataseries or don't set a value at all - http://www.ninjatrader-support.com/H...iesObject.html
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Hi Bertrand, Regarding the DataSeries.Reset(), I tried this:-

                        if ((Close[0]< doubleY) && (doubleY >0))
                        {
                        Plots[
                        0].Pen = new Pen(Color.Green, 2);
                        Plots[
                        0].Pen.DashStyle = DashStyle.Dash;
                        AvgR.Set(doubleY);
                        }
                        elseif ((Close[0]> doubleY) && (doubleY >0))
                        {
                        AvgR.Reset(doubleY); <== 2 error messages
                        }

                        I got 2 errors:-
                        1) CS1502: The best overloaded method match for "NinjaTrader.Data.DataSeries.Reset(int) has some invlaid arguments.
                        2) CS1503: Argument '1': cannot convert from 'double' to 'int'.

                        Not sure what I am doing wrong. Please help.

                        BTW. I fixed the plot line color and dashstyle. Thx!

                        Comment


                          #13
                          Your doubleY value is a double, where the compiler expects an Integer one, try casting it -

                          AvgR.Reset((int)doubleY);
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Oops! I think reset cleared out all the data! Lol!

                            Just wanted to stop plotting after condition is fulfilled i.e when close[0] > doubleY.

                            Comment


                              #15
                              Yes, this is expected as you set the value to 'null' == empty for plotting purposes - I don't follow why you need this, just use this part only, setting a value for the dataseries to plot when you condition is true -

                              if ((Close[0]< doubleY) && (doubleY >0))
                              {
                              Plots[
                              0].Pen = new Pen(Color.Green, 2
                              );
                              Plots[
                              0
                              ].Pen.DashStyle = DashStyle.Dash;
                              AvgR.Set(doubleY);
                              }
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by adeelshahzad, Today, 03:54 AM
                              5 responses
                              30 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by stafe, 04-15-2024, 08:34 PM
                              7 responses
                              31 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by merzo, 06-25-2023, 02:19 AM
                              10 responses
                              823 views
                              1 like
                              Last Post NinjaTrader_ChristopherJ  
                              Started by frankthearm, Today, 09:08 AM
                              5 responses
                              17 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              43 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X