Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

draw vertical line

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

    draw vertical line

    I try to draw a vertical line.

    My line dont show on the chart.
    I thought it was int double problem but not sure anymore.

    barfibo is the number of bar the result come with so i thought it would draw a vertical line at bar 97 if result give 97. Am i wrong?
    Here's the code:

    double barfibo = (bar / fibo)+ bar;
    int somefib = (int)barfibo;
    int someOtherfib = Convert.ToInt32(somefib);
    Draw.VerticalLine(this, "someOtherfib", 10, Brushes.Black);

    ty

    #2
    Hello frankduc,

    From what I can see, you are trying to draw a line 10 BarsAgo on the chart.

    You are using the following overload set:
    Code:
    Draw.VerticalLine(NinjaScriptBase owner, string tag, int barsAgo, Brush brush)
    If you wanted to use the int you created, you need to replace the 10 with the variable you wanted to use.

    As far as not seeing the line, this may be due to the color. Are you using a Black background on the chart? Alternatively, right click the chart -> Drawing Tools -> Drawing Objects.., is the line listed in the collection of chart objects?


    I look forward to being of further assistance.

    Comment


      #3
      I change the script for

      double barfibo = (bar / fibo)+ bar;
      int somefib = (int)barfibo;
      int someOtherfib = Convert.ToInt32(somefib);
      Draw.VerticalLine(this, "tag1", someOtherfib, Brushes.Red);




      The indicator is flashing once in the chart and than disappear. What did you mean by overload set?

      Do i have to change this part
      (this, "tag1",



      for this one
      NinjaScriptBase owner, string tag.?

      Must i write int
      someOtherfib?
      ty
      Attached Files
      Last edited by frankduc; 06-21-2019, 08:14 AM.

      Comment


        #4
        Hello frankduc,

        The indicator is flashing once in the chart and than disappear.
        Are you seeing an error in the control center log or the output window? Generally if the item disappears, there was an error.


        What did you mean by overload set?
        The overload set is the set of parameters you used, I provided the documentation for the overload set you used to show where the BarsAgo is in that syntax. This information is in the help guide: https://ninjatrader.com/support/help...b=VerticalLine



        I look forward to being of further assistance.

        Comment


          #5
          Everything looks in order for the script part, no?
          Draw.VerticalLine(this, "tag1", someOtherfib, Brushes.Red);

          Errors:

          2019-06-21 10:28 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 3113: Object reference not set to an instance of an object.
          2019-06-21 10:27 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 3106: Object reference not set to an instance of an object.
          2019-06-21 10:26 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 10:26 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 10:21 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 3058: Object reference not set to an instance of an object.
          2019-06-21 10:21 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 10:19 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 3040: Object reference not set to an instance of an object.
          2019-06-21 10:16 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2992: Object reference not set to an instance of an object.
          2019-06-21 10:15 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2974: Object reference not set to an instance of an object.
          2019-06-21 10:14 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2971: Object reference not set to an instance of an object.
          2019-06-21 10:11 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2927: Object reference not set to an instance of an object.
          2019-06-21 10:10 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 10:05 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 10:05 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2850: Object reference not set to an instance of an object.
          2019-06-21 10:02 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2794: Object reference not set to an instance of an object.
          2019-06-21 10:02 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2791: Object reference not set to an instance of an object.
          2019-06-21 10:02 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:56 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2705: Object reference not set to an instance of an object.
          2019-06-21 09:55 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2696: Object reference not set to an instance of an object.
          2019-06-21 09:55 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2690: Object reference not set to an instance of an object.
          2019-06-21 09:55 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:55 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:45 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2494: Value was either too large or too small for an Int32.
          2019-06-21 09:40 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:37 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2343: Object reference not set to an instance of an object.
          2019-06-21 09:31 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2224: Object reference not set to an instance of an object.
          2019-06-21 09:31 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2217: Object reference not set to an instance of an object.
          2019-06-21 09:31 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:31 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:29 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:29 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:28 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:27 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2107: Object reference not set to an instance of an object.
          2019-06-21 09:27 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2103: Object reference not set to an instance of an object.
          2019-06-21 09:27 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2098: Object reference not set to an instance of an object.
          2019-06-21 09:26 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:26 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:26 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:26 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 09:17 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnRender' method on bar 2022: Value was either too large or too small for an Int32.
          2019-06-21 08:53 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 08:52 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType
          2019-06-21 08:32 NinjaScript Multiple Bartypes with the same BarsPeriodType were found. Ignoring NinjaTrader.NinjaScript.BarsTypes.MirrorBarsType

          Comment


            #6
            Hello frankduc,

            If the indicator where you are drawing the line is SampleDisplayBarsAgo, you have a problem in the indicators OnRender. Are you using OnRender in this script?

            Please let me know if I may be of further assistance.

            Comment


              #7
              Yes i am its OnRender. If i remove the vertical drawing script it works fine. You can see in the image earlier i provided that in data anchor time the date is set to 1800-01-01 could it be the problem?
              If i change the date and hour the blue line show up without the indicator in the chart.

              Dont tell me its only working OnBarUpdate.

              Comment


                #8
                Hello frankduc,

                That would not be a valid location to use BarsAgo. OnRender is intended for drawing by means of X/Y values and is not associated with the OnBarUpdate logic. If you want to draw a vertical line from OnRender, you should instead be using RenderTarget.DrawLine and supply the correct X/Y coordinates for where you want to render.

                OnRender does not work like OnBarUpdate so using syntax which takes a BarsAgo to draw will not work as expected.

                Moving this logic to OnBarUpdate should work as you expect and would be able to use the BarsAgo you calculate.


                Please let me know if I may be of further assistance.

                Comment


                  #9
                  ok code is:

                  double barfibo = (bar / fibo)+ bar;
                  int somefib = (int)barfibo;
                  int someOtherfib = Convert.ToInt32(somefib);
                  Draw.VerticalLine(this, "tag1", someOtherfib, Brushes.Red);


                  Is it possible to send double barfibo = (bar / fibo)+ bar; return's to OnBarUpdate without having to rewrite all the code?

                  Otherwise i would need to recall all variables like bar and fibo in OnBarUpdate.

                  In the case of bar:

                  int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex);

                  chartControl and cursorPointX do not exist. How do i rewrite all this in
                  OnBarUpdate? Is it only possible?

                  My indicator has not been created to work in OnBarUpdate.

                  Comment


                    #10
                    Hello frankduc,

                    You could store that variable as a class level variable instead of a local variable. Defining a class level variable could be accessed from both OnbarUpdate and OnRender. If you are doing this calculation in OnRender, keep in mind after setting a class level variable you would have to wait for the next call to OnBarUpdate for the drawing to be drawn/updated.

                    Otherwise to re write this for OnBarUpdate, the code you provided is not going to be able to be converted as that deals with the mouse position and X values. The overall solution to this question will be to avoid using the Drawing Tools and switch to using the RenderTarget if you want to use OnRender to draw. You already have the X/Y values as you are working in OnRender so you could use those values to render a line at a location if you wanted to.

                    Please let me know if I may be of further assistance.

                    Comment


                      #11
                      There is no exemple in
                      RenderTarget. Where do i get the X/Y values?
                      I suppose i must enter those coordinate in:
                      RenderTarget.DrawLine(Vector2point0,Vector2point1,Brushbrush,floatstrokeWidth,StrokeStylestrokeStyle)

                      If the value of my variable is changing like 10 bars ago to 50 barsago from one bar to another will it adapt automatically?

                      I suppose you are reporting to Vector2(
                      floatx,floaty)

                      Is the float my variable? Not as simple as OnBarUpdate.

                      Comment


                        #12
                        Hello frankduc

                        The RenderTarget area of the help guide is documented like a programming API, it only lists what you can do but does not provide specific examples. The method to draw a line is included in the help guide page and you are correct you would need to fill in the values.

                        Where do i get the X/Y values?
                        In what you provided earlier in the thread, you are working with X values already:
                        Code:
                        ChartBars.GetBarIdxByX(chartControl, [B]cursorPointX[/B])
                        cursorPointX is an X value.

                        The Y value would generally come from the method: https://ninjatrader.com/support/help...ightsub=getyby

                        These concepts are all documented in the Chart section of the help guide under the control the method belongs to. For example ChartBars has X methods and ChartScale has Y methods.

                        If the value of my variable is changing like 10 bars ago to 50 barsago from one bar to another will it adapt automatically?
                        The variable will change when you want it to. If you wanted to render that variable, you will need to also do that. OnRender is called very frequently for various render actions, if you are changing a value and also rendering it from OnRender, it would update at the frequency of OnRender.



                        I suppose you are reporting to Vector2(floatx,floaty)

                        Is the float my variable? Not as simple as OnBarUpdate.
                        The words between ( and ) are the type and what that represents for this method. In what you provided, it is asking for two float type variables which represent the X and Y value. You could pass in your variables here for X and Y.


                        Please let me know if I may be of further assistance.












                        Comment


                          #13
                          One last question not related to draw a line.

                          Does NT support LinQ or MoreLinQ?

                          Because i tried several time to use .Min and .First without success. I would like to use concat also to merge list and if i look in insert code snippet i cant find them.

                          ty

                          Comment


                            #14
                            Hello frankduc,

                            C# in general supports Linq expressions, however you would need to use the correct namespaces for what you are trying to accomplish. Linq expressions are generally held as extension methods of a type, such as First which is an extension of a IEnumerable<T>.



                            If you create a NinjaScript file, it should have the Linq namespace already:
                            Code:
                            using System.Linq;
                            The methods like First will only be available on objects which can be used with linq like a collection, this would not work with other simple types like a double.

                            You can fine one example of FirstOrDefault being used in the following page: https://ninjatrader.com/support/help...ount_class.htm

                            Code:
                             myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");


                            Please let me know if I may be of further assistance.

                            Comment


                              #15
                              So that's the explanation for the failure of:

                              List<double> list = new List<double>() { alist[a] };
                              var minDistance = list.Min(no => Math.Abs(fibo- no));
                              var closest = list.First(no => Math.Abs(fibo- no) == minDistance);
                              {
                              Print(closest);
                              }
                              It return the entire list but not the closest value in the list from fibo.

                              but alist is a collection no? The problem is that alist is the return answer of another list:


                              iv been bumping on that for a week.
                              Last edited by frankduc; 06-24-2019, 05:48 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              574 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              333 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X