Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

draw vertical line

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

    #16
    Hello frankduc,

    The syntax you have provided is general C# which you can learn about using external C# education resources. This is not likely something our support can dive into great detail with you. Linq, using Linq and general C# syntax are topics which you can research online if you plan to manually code C# in NinjaScript. If what you are doing is returning a list, you would need to locate the correct way to do what you are trying to achieve in C#. Linq is not NinjaScript topic and would not be something that I can provide in depth support for.

    One change you can make to what you provided would be to be specific and not use var. If what you are trying to do does not compile because the return type is not what is expected, it is not the correct syntax for what you are trying to do and you will need to test other ways. For example if the problem was with the var minDistance, changing its declared type to a specific type will generate an error if the return type of the method is different.

    Code:
    [B]double minDistance = [/B]


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

    Comment


      #17
      Hello Jesse,

      I'm trying to create that vertical line on render.

      I come up with this code but i am sure i am missing something.

      double barfibo = (bar / fibo)+ bar;
      int somefib = (int)barfibo;
      int someOtherfib = Convert.ToInt32(somefib);

      int yByValue = chartScale.GetYByValue(someOtherfib);

      RenderTarget.DrawLine(Vector2(ChartBars.GetBarIdxB yX(chartControl, cursorPointX)), Vector2(yByValue), Brush brush)


      Print(yByValue);

      What do i do with brush brush?
      It also says Vector does not exist in the context?

      What about this code ?
      RenderTarget.DrawLine(Vector2point0,Vector2point1,Brushbrush,floatstrokeWidth,StrokeStylestrokeStyle)

      Is it more appropriate for what i intend to do?



      Will it create a vertical line, cause i dont see where is the vertical in that code?

      ty

      Comment


        #18
        Hello frankduc,

        What do i do with brush brush?
        What you have copied is an overload pattern, this is just an example that shows what types the methods parameters are. You would replace those with a actual value like a Brush that you wanted to use such as Brushes.Red. Vector is the same concept, you need to create a new vector and then supply it as a parameter because that is what the method is asking for.

        It also says Vector does not exist in the context?
        You need to add a using statement or use the full namespace which points to vector. basically all of the SharpDX types are held under the namespace SharpDX like SharpDX.Vector2.
        You can find examples of these concepts in the indicator SampleCustomRender.

        What about this code ?
        You can choose any of these overload sets:
        Code:
        RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush)
        RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, float strokeWidth)
        RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, float strokeWidth, StrokeStyle strokeStyle)
        it would depend on what you wanted to do when you render the line as to which you may use.

        Will it create a vertical line, cause i dont see where is the vertical in that code?
        Only if you supply points which make it a vertical line. If you supply two x points which are not parallel, it would just be a line placed between two points. You control the X and Y here so you would need to figure out the two ends of your line, making it vertical would require that the points used make a vertical line. You can reference the vertical line drawing tools code to see how that is already being done in that tool.

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

        Comment


          #19
          "
          You control the X and Y here so you would need to figure out the two ends of your line, making it vertical would require that the points used make a vertical line. You can reference the vertical line drawing tools code to see how that is already being done in that tool."

          This is getting way to complicated.

          You said earlier "You could store that variable as a class level variable instead of a local variable. "

          But if its not possible to store cursorX as a class level variable than that solution is also out of question?

          ty

          Comment


            #20
            Hello frankduc,

            This is getting way to complicated.
            Using X and Y coordinates is a fundamental part of rendering, without this understanding the remaining parts of what you are trying to do will be very difficult to proceed through further. The Mouse specifically uses X/Y coordinates, so using the mouse how you have will require that you learn to use X/Y coordinates along with the NinjaScript methods to do conversions where nessasary. If that is not something you want to do, you will need to hire outside help to complete this for you.

            You said earlier "You could store that variable as a class level variable instead of a local variable. "
            But if its not possible to store cursorX as a class level variable than that solution is also out of question?
            I am not certain what you are referring to here, I did not say it was not possible to use class level variables. This was a comment from post #10 which you did not quote the full context of. I did say:
            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.
            A class level variable will not be updated quickly in this case if the logic is being completed in OnBarUpdate and set from OnRender. you would wait 1 OnBarUpdate call to see the update in that situation.


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




            Comment


              #21
              Its because you said here :"
              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."

              I am confuse if i try to create a private variable:

              public class SampleDisplayBarsAgo : Indicator
              {
              private SharpDX.Direct2D1.Brush textBrush;
              private int cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl);

              It will return chart control dont exist in the context. For other variables its ok but i dont know what to do with chartcontrol! If Onbarupdate update every bar its fine by me.

              I try to find the easiest solution because my programming skills are limited. For outside help it is very expansive and i have doubts in the competence of most people i reach out. For exemple, i entered the formulas myself with NT tech help and it took me 3 weeks starting with zero knowledge in C#. That's 70% of the job done. The projet is on a stand still for 2 weeks because i stumble on an issue i cant resolve. Coders in Montreal and even in the ecosystem were asking for 5000 to 25000$ its a rip off! This is a business of crooks! One company ask for 3000$ for one formula, once i knew how to do it, it took me a morning for about 50 formulas.

              Sorry if i am annoying with my questions but i am going to keep on learning slowly but ill get there one day.

              Comment


                #22
                Hello frankduc,

                Code:
                private int cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl);
                This syntax is not valid, you are trying to create a variable but you also used runtime variables here which wont compile. Your local variable "chartControl" does not exist outside of OnRender where it was defined.

                To make a class level variable, you can define it in the class. Later you would assign it from within a method body like OnRender or OnBarUpdate:

                Code:
                private int cursorPointX = 0;
                
                protected override void OnBarUpdate()
                {
                    cursorPointX = someValue; // you can assign the value now that the script is running, OnRender could also be used. 
                }
                I try to find the easiest solution because my programming skills are limited.
                You are now using some of the more complex parts of NinjaScript, in this case you will need to invest some time to learn about the topics involved. This includes how rendering works in NinjaScript along with quite a few C# fundamentals. If you wanted to gain more knowledge on this topic, I would still suggest investing time with the SampleCustomRender indicator to at least go over the basic concepts of using OnRender and the types involved with that.

                For outside help it is very expansive
                This can be true as it does cost money to outsource work, it would be up to those third parties to charge what they feel their time and effort is worth. It would also be up to you to make an educated decision on what you want to do. If external help you have found is not within the range you want to invest, your options are pretty limited here. You can either invest the time needed and learn what you need to program it yourself, or pay to have it done for you.

                i entered the formulas myself with NT tech help and it took me 3 weeks starting with zero knowledge in C#. That's 70% of the job done.
                While I agree it can be easy to copy/paste samples we provide, this will really only get you so far until you are stuck again. You will still need to be able to comprehend what the syntax is doing in order to diagnose problems or expand on it. Our support cannot always make easy samples for every question or concept. We are happy to assist in your learning by providing what resources we can, however a lot of the learning will require that you to explore NinjaScript, perform tests or do other steps to learn about how NinjaScript works.



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

                Comment


                  #23
                  Sorry to insist but
                  cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl);
                  is the only variable where it bugs.
                  cursorPointX = someValue;

                  I cannot replace someValue by ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl); it wont compile!

                  Is there an equivalent in Onbarupdate? Cause i'm searching in the tutorial and i dont know where you can do that.

                  Comment


                    #24
                    Hello frankduc,

                    I cannot replace someValue by ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl); it wont compile!
                    What is the error you are getting?

                    I can see a problem here and we can return to that in the next reply, however if I just post the answer I have effectively debugged the code and it would be more difficult to make this a learning point.

                    The errors presented when you compile happen for specific reasons and often have specific solutions.

                    Is there an equivalent in Onbarupdate? Cause i'm searching in the tutorial and i dont know where you can do that.
                    Rather than trying to jump to a different override when you see an error, I would suggest first learning about the error you are seeing and addressing the problem directly. Trying to just move to a different override is not likely the solution and will dilute your question as now we would have to figure out a whole new question. We should work on the question at hand instead of deflecting to a new approach.

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

                    Comment


                      #25
                      Something like no def for charcontrol. Now ChartControl is a class and i decided to create a class level variable:

                      private int cursorPointX = 0;
                      private int chartControl = 0;
                      private int MouseDownPoint = 0;

                      I did the same for MouseDownPoint cause its also saying int dont have a def for it. Also it is saying that it wont accept it as a first argument. According to doc.msn
                      In C#, arguments can be passed to parameters either by value or by reference.
                      From that point i am not sure what i should do.

                      If its possible to simply class level variable ChartControl how come in OnRender it end up in OnRender(ChartControl chartControl, ChartScale chartScale) why not just do OnBarUpdate(
                      ChartControl chartControl, ChartScale chartScale
                      )?

                      Comment


                        #26
                        Hello frankduc,

                        When providing errors, please be specific and copy/paste what you see in the log/output window. If you are seeing that chartControl is not defined, that would be correct and the change you made is not a solution.

                        ChartControl is part of your script and is not an int. Lowercase chartControl is a instance of ChartControl which is passed into OnRender specifically.

                        OnRender references specific objects so they are passed in as parameters, your script happens to also inherit ChartControl. The syntax you have used was intended for OnRender so it used the lowercase passed in variable: chartControl.
                        If you wanted to use this syntax where that variable is not being passed in, you need to change it to use ChartControl and check for null on the ChartControl object and then execute your code when it is not null:

                        Code:
                        if(ChartControl != null)
                        {
                           // code here
                        }
                        If its possible to simply class level variable ChartControl how come in OnRender it end up in OnRender(ChartControl chartControl, ChartScale chartScale) why not just do OnBarUpdate(
                        ChartControl chartControl, ChartScale chartScale
                        )?
                        This is not how an override method works. The override methods are defined in a specific way and NinjaTrader is calling the method with specific defined parameters. OnBarUpdate has no parameters defined so you can't just arbitrarily add more parameters to it.

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

                        Comment


                          #27
                          SampleDisplayBarsAgo.cs 'int' ne contient pas une définition pour 'MouseDownPoint' et aucune méthode d'extension 'MouseDownPoint' acceptant un premier argument de type 'int' n'a été trouvée (une directive using ou une référence d'assembly est-elle manquante ?) CS1061 76 80
                          This is the error i get and sorry but its in french. I dont know if its possible to get it in English in the settings of NT.

                          Did you mean?

                          protected override void OnBarUpdate()
                          {

                          if(ChartControl != null)
                          {
                          cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl);
                          }

                          }


                          Obviously you cannot use chartControl.MouseDownPoint.X, chartControl because it is intended for OnRender but i dont see how you can replace it in OnBarUpdate. I have been reading in
                          https://docs.microsoft.com/fr-fr/dot.../keywords/null since last week about variables, objects, Types and the rest and it raise more questions in my mind than answers. I dont know if i am slow learner but i find documentation on the net redondant and badly explained. By the way i am not blaming you the info you provide is in line with what i am reading. It's just that i cant guess what i dont know.
                          The way you explaining things it seems that
                          cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl); just need to be recoded with the same words but differently.

                          ChartControl is a class and OnBarUpdate is
                          An event driven method. ChartControl should'nt be above OnBarUpdate?

                          If i remove
                          private int chartControl = 0;

                          I get :


                          SampleDisplayBarsAgo.cs Le nom 'chartControl' n'existe pas dans le contexte actuel CS0103 76 67

                          Comment


                            #28
                            Hello frankduc,

                            This is the error i get and sorry but its in french. I dont know if its possible to get it in English in the settings of NT.
                            That is fine, we can use google translate. The actual error helps in providing accurate answers.

                            'int' does not contain a definition for 'MouseDownPoint' and no extension method 'MouseDownPoint' that accepts a first argument of type 'int' has been found (is a using directive or an assembly reference missing? )
                            The error is also correct. Combining the information from your last post with the error explains why that is happening.

                            In the last post you provided the following code:

                            Code:
                            private int chartControl = 0; // not valid
                            ChartControl is a type, this is not an int and you cannot define ChartControl as an int. An int does not have the same methods ChartControl has which is the reason you see this error.

                            Because this has come up, I would suggest that you stop here and review some C# education material surrounding defining variables and Types in C#. This is what will be required for this part of the code and what you are trying to do. A good starting place is the public MSDN documentation, however there are many resources you can use to learn this subject: https://docs.microsoft.com/en-us/dot...-and-variables Our support cannot provide direct C# education, if this part of the development is holding you up, you need to look at external resources to increase your knowledge of C#.


                            Did you mean?

                            protected override void OnBarUpdate()
                            {

                            if(ChartControl != null)
                            {
                            cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(chart Control.MouseDownPoint.X, chartControl);
                            }

                            }
                            This is part of what I had mentioned, however you did not make the modifications I had noted. You are still using lowercase chartControl which would not work.

                            ChartControl is a class and OnBarUpdate is
                            An event driven method. ChartControl should'nt be above OnBarUpdate?
                            ChartControl is both a class and a property of your script, this is not the same as a method. You need to pay attention to the capitalization of the names you used.

                            If i remove
                            private int chartControl = 0;

                            I get :

                            The name 'chartControl' does not exist in the current context
                            Correct, again you need to pay attention to capitalization. In programming you can use both lowercase and capital letters, the case matters in programming.

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

                            Comment


                              #29

                              Now it works! Thank you.

                              But the thing is i have to recode everything in OnBarUpdate. Is there a magic way i can send all my variables from OnRender to OBU without having to rewrite the whole thing? Well its just mostly copy/paste not the end of the world but it makes the overall code larger and heavy.

                              I decided to move everything to OBU but i still cant see my vertical line in the chart. No compiling errors. But a log error :
                              2019-07-03 08:41:38 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
                              2019-07-03 08:41:30 Default Indicator 'SampleDisplayBarsAgo': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                              Something bother me if i ask to Print(cmaave); one of my variable it wont show up on the OW. Anything that is code in OBU is not showing.
                              Can it be link to that Null thing?

                              According to this https://stackoverflow.com/questions/...ow-do-i-fix-it
                              ChartControl if(ChartControl != null)
                              I guess all my
                              ChartControl have been nullified like this one:

                              double lowestclose = Low.GetValueAt(ChartBars.GetBarIdxByX(ChartControl , cursorPointX));

                              Did i forgot something?

                              Draw.VerticalLine(this, "tag1", someOtherfib, Brushes.Red);
                              Last edited by frankduc; 07-03-2019, 07:25 AM.

                              Comment


                                #30
                                Hello frankduc,
                                Is there a magic way i can send all my variables from OnRender to OBU without having to rewrite the whole thing?
                                No, if you decide to refactor code to another area of your script that is something for you to do. You would need to also make sure what you change is valid and works, copying and pasting generally wont directly work for items going from OnRender to OnBarUpdate as they use different ways to access data. You can convert the code and test it as you go to make sure it reaches the result you wanted.


                                Something bother me if i ask to Print(cmaave); one of my variable it wont show up on the OW. Anything that is code in OBU is not showing.
                                Can it be link to that Null thing?
                                You are getting an error so your Prints will not happen if they come after the error. I mentioned this in post #26 and provided a sample of the code you would need to use to prevent the null error. ChartControl is an object which can be null so you need to surround your code with a condition checking if it is not null.

                                You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
                                This is not likely related to your other error, this is most likely a BarsAgo you have used or potentially the values you are now passing to the syntax you moved to OnBarUpdate. To understand the error you would need to find the syntax causing it, this may include printing any indexes/BarsAgo you used to find out where the problem starts.


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

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                601 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                347 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                103 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                559 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                558 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X