Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy wants to draw Horizontal Price Line on Chart

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

    Strategy wants to draw Horizontal Price Line on Chart

    Hi. I poked around and can't readily see how to Draw a HorizontalLine
    on the chart from my Unmanaged Strategy.

    C# doesn't have Multiple Inheritance, so my Strategy class can't also
    inherit from Indicator.

    Thanks to earlier support; I've hooked the LeftMouseDown event, and that
    delivers a correct Price from the Chart, as follows, but
    how to draw the HorizontalLine at that Price?

    Code:
    private Brush myColor = Brushes.Red;
    private DashStyleHelper myLineStyle = DashStyleHelper.Solid;
    private int myLineThickness = 2;
    private string myLineKey = "HLinePrice";
    
    protected void LeftMouseDown(object sender, MouseButtonEventArgs e) {
    int Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartControl as IInputElement).Y,
    ChartControl.PresentationSource);
    double priceClicked = MyChartScale.GetValueByY(Y);
    // price is correct
    // try to draw a horizontal line on chart at priceClicked
    //if this were an Indicator, which is is not, then I think I could draw like this, or similar
    Draw.HorizontalLine(this, myLineKey, false, priceClicked, myColor, myLineStyle, myLineThickness); // pseudocode
    }
    Thanks in advance for your help !
    hyperscalper

    #2
    Hello Hyper, thanks for writing in.

    Do you get any errors in the log tab of the Control Center after running the script? If you do not get anything there, I recommend using the Print method to print every element of data that is used to draw the line for debugging. We also have an example here that shows how to draw when a line is clicked, this can be a good reference to use:



    I look forward to hearing from you.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks, but this is a Compile problem; the Draw... line in the code shown
      was marked with a //comment that says "pseudocode" (way off to the right side)
      as I think it would be with an Indicator; but this is a Strategy subclass.
      And it's being done in Visual Studio.

      Perhaps I am missing a using... or a Strategy must use a different mechanism
      to Draw on its Chart...

      So, with a Strategy; what is the method of Draw-ing a Horizontal line, please?

      hyperscalper

      Comment


        #4
        Hello Hyper, thanks for your reply.

        What is the compile error you are getting? Drawing methods work for unmanaged/managed strategies.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          I may be using the wrong fully qualified Draw.
          NinjaTrader.NinjaScript.DrawingTools.Draw does not have a static
          method HorizontalLine(...).

          Either I have the wrong Draw version; or I am just misunderstanding
          how it is supposed to work from a Strategy; not from an Indicator.
          I guess it's the Object model which I may be misunderstanding.

          Do you have a Strategy which draws a HorizontalLine on its
          host Chart?

          hyperscalper

          Comment


            #6
            I think I have it wrong, of course
            Draw.HorizontalLine from the documentation appears to be a "line factory"
            so that HorizontalLine myLine = Draw.HorizontalLine(...);
            from ninjatrader.com/support/helpGuide/nt8/horizontalline.htm

            So now if I have a HorizontalLine object, then I have to figure out how
            to show it on the chart.

            [edit] Well, that's not true either; perhaps it's NT7 documentation or
            I am using the wrong fully qualified class NinjaTrader.NinjaScript.DrawingTools.Draw
            which does not have a field or method HorizontalLine, so far as I can see...?

            Apologies for my lack of understanding here; but I'm sure you'll set me straight.

            hyperscalper
            Last edited by Hyper; 10-08-2020, 11:23 AM.

            Comment


              #7
              Hello Hyper, thanks for your reply.

              I attached my test script here. This should be sufficient to get on the right track here. If you are still seeing the issue I will need a reduced test script of exactly how you have this set up in your strategy.

              Kind regards.
              Attached Files
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                THANKS very much for that. I don't use the NinjaScript editor much; but it
                was super easy to recreate a Strategy as you did, and magically, Draw.HorizontalLine
                is defined correctly.

                So I used the NinjaScript Editor nice function of converting things to a
                Visual Studio project (I use Community 2017) and things were created
                just fine, but then my error was revealed !!! No definition for
                NinjaTrader.NinjaScript.DrawingTools.Draw.Horizont alLine !!

                It appears that
                a file in namespace NinjaTrader.NinjaScript.DrawingTools contained
                a Partial Class definition for Draw inline with an unrelated class definition,
                seems to have effectively over-ridden the Draw which was intended !

                Once I remove that Development Environment class override, then I
                am sure I'll see the correct definition for Draw.HorizontalLine.

                I really learned something here; "the hard way" lol
                MANY THANKS FOR THE HELP !
                hyperscalper
                Last edited by Hyper; 10-08-2020, 04:46 PM.

                Comment


                  #9
                  Hi. Although my questions may fall into the "this is not supported" category; I
                  feel confident you can help me.

                  So the issue with Draw.HorizontalLine is that in the NinjaScript Editor, the
                  definition is found in the Custom/DrawingTools/@Lines.cs file.

                  Now, what I was hoping for, in Visual Studio; was that the definition would
                  be found in one of the installed Assembly DLL's, so my first question is:

                  1) is Draw.HorizontalLine in one of the Assemblies?

                  If not, then how do I need to set things up so that the Visual Studio C#
                  environment as the same access to that @Lines.cs file
                  mentionned above? [edit] Just Add it to my Project? maybe

                  I'm sure there's a way to set things up; and point VS to these files,
                  if the definitions cannot be found in any NinjaTrader installed Assembly.

                  Sympathy for me, please; since I've spent 10 years using Eclipse with
                  Java development; and only a few months with VS 2017 ... ha ha

                  hyperscalper
                  Last edited by Hyper; 10-09-2020, 10:49 AM.

                  Comment


                    #10
                    Hello Hyper, thanks for the follow up.

                    I just attempted to build the custom project located in Documents\NinjaTrader 8\bin\Custom and I am not able to compile the project, so we are looking into this problem now. I would recommend using the NinjaScript Editor for the time being. I typically do not use Visual Studio unless I'm making an Addon that requires XAML files and other resources. Strategies and Indicators are viable to work with through the NinjaScript editor, and you do not have to restart NinjaTrader every time you compile.

                    I will follow up once I have more information on the custom project.

                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Hyper, thanks for your patience.

                      I was able to get the custom project to compile in Visual Studio. The Vendor.dll will have these references, but this should only cause a warning and not a compile error. Could you please share the specific compile errors you are seeing from the custom project? (Note, the custom project can be found in Documents\NinjaTrader 8\bin\Custom, titled NinjaTrader.Custom.csproj)

                      I look forward to hearing from you.

                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi. Thanks so much for looking into this. I realize that Visual Studio and
                        Assembly DLL implementations have their issues.

                        But I have at least 50 class in this Unmanaged Strategy; with everything
                        from soup to nuts inside ( Task queues, Threads, Winforms user interface,
                        and the list goes on and on... ) so it's pretty complex.

                        Because of that, I'm stuck in Visual Studio; but the NinjaScript Editor
                        environment is useful to understand some things.

                        I'll try to get into what you've suggested above; and I'm familiar with
                        Java Jars, sometimes overriding definitions; and maybe something
                        similar is going on with C#. For me, a C# namespace is more or less
                        the same as a Java Package, and Jar file ordering; where a Jar package
                        earlier in the classpath can override one later on in the classpath, etc.....

                        Intellisense just doesn't see a HorizontalLine field or method in the
                        NinjaTrader.NinjaScript.DrawingTools.Draw namespace; so I wonder
                        if something has "short circuited" the Draw definition path, so to speak...

                        Using Object Browser I couldn't find Draw.HorizontalLine either !...

                        hyperscalper
                        Last edited by Hyper; 10-10-2020, 05:42 PM.

                        Comment


                          #13
                          Hi again. So I conclude that certain parts of the API apply to NinjaScript Editor based coding only.

                          I know that Visual Studio multi-class coding is really not supported; and that's OK.

                          With regard to Draw.HorizontalLine and other Drawing functions from a Strategy; I am starting
                          to think I'll just need to pull in selected code from NinjaScript environment into my VS project; in
                          order to make this work.

                          What would you advise? Is there, or is there going to be an Assembly DLL that supports the
                          Draw.HorizontalLine and lots of other drawing functions outside of NinjaScript?

                          Am I just "on my own" on this? It just came as a surprise to me that I ran into this little roadblock.

                          hyperscalper

                          Comment


                            #14
                            Hello Hyper,

                            Outside of NinjaScript and in just C# there would be no way to use NinjaScript objects or functions, you would need to be working within a context that you can use those namespaces or classes. If you need to use something from the custom project in an external solution you would generally need to include all necessary code in your export to support that. The visual studio solution is generally only intended for more advanced cases where you want to custom code something rather than use the existing frameworks or that you needed a specific visual studio feature that the NS editor does not support. We generally suggest to build projects from within the NinjaTrader.Custom project so you have access to the normal NinjaScript documented items. NinjaTrader would handle all the compiling in that case and visual studio would not be used to build and would just be used as an editor.

                            Please let us know if we may be of further assistance.



                            JesseNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by ghoul, Today, 06:02 PM
                            3 responses
                            14 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by jeronymite, 04-12-2024, 04:26 PM
                            3 responses
                            44 views
                            0 likes
                            Last Post jeronymite  
                            Started by Barry Milan, Yesterday, 10:35 PM
                            7 responses
                            20 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by AttiM, 02-14-2024, 05:20 PM
                            10 responses
                            180 views
                            0 likes
                            Last Post jeronymite  
                            Started by DanielSanMartin, Yesterday, 02:37 PM
                            2 responses
                            13 views
                            0 likes
                            Last Post DanielSanMartin  
                            Working...
                            X