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

namespace question

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

    namespace question

    Hello, I have a question on namespaces and custom drawing tools

    I have a custom drawing tool I created

    namespace NinjaTrader.NinjaScript.DrawingTools
    {
    /// <summary>
    /// Base class for my drawing tool
    /// </summary>
    public abstract class MyDrawingToolbase : DrawingTool
    {
    #region Private Members
    etc
    }

    namespace NinjaTrader.NinjaScript.DrawingTools
    {
    [EditorBrowsable(EditorBrowsableState.Always)]
    public class MyDrawingTool : MyDrawingToolBase
    {
    #region Private Members

    etc
    }

    This all works fine

    In my visual studio solution i have 2 main projects
    Solution 'My Tools Solution'

    - NinjaTrader.Custom

    - My Tools

    in the project My Tools i have subdirectory DrawingTools to place my custom drawing tool files.

    Now everything builds and runs fine except now that i want to access the

    NinjaTrader.NinjaScript.DrawingTools.Line or Horizontal line

    to use those tools - but it is not resolving Line in the above

    and i do have the above in the using namespace section at the top.

    Perhaps due to the structure in visual studio i only see MyDrawingTool in the
    NinjaTrader.NinjaScript.DrawingTools .. explicit path

    any guidance thoughts ? do i need to rename the DrawingTools in My Tools project to something else like MyDrawingTools?

    thanks and let me know if need more info

    #2
    Hello,

    Thank you for the post.

    I wanted to clarify the setup you have. Are you currently using the standard custom project which is opened by clicking the Visual Studio button in the toolbar of the NinjaScript editor, or is this a completely separate project?

    If this is a separate project where you are building a DLL, you need to use the Dynamic type as noted here: https://ninjatrader.com/support/help...ghtsub=dynamic

    If this is the NinjaTrader custom project launched from the toolbar, this may be a namespace issue. I would likely need to see a complete sample of where the tool is being called from where it is not working.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks,

      This is a separate project building a DLL.

      I am already using dynamic for my custom drawing tool in the code so aware of that help page section.

      However i didnt think i needed for Standard ninja drawing.

      so if i want to Draw.Line or Draw.Horizontal line how do i do this?

      dynamic myline = Draw.Line(....);

      or

      dynamic myline = NinjaTrader.NinjaScript.DrawingTools.Draw.Line(..)

      it accepts the dynamic but it doesnt like the Draw.Line part in either of the above?
      Last edited by soulfx; 11-22-2017, 11:40 AM.

      Comment


        #4
        Hello,

        To further clarify, are you trying to draw the line from your custom tool or an indicator/strategy?

        The Draw. commands are specifically meant for other types and not the DrawingObjects themselves. This could be the problem if you are trying to use a Draw. method from the tool. Can you provide more detail on where the Line tool is being drawn from?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Yes i am trying to draw the line from within OnbarUpdate of my indicator not in OnRender.

          The custom drawing tool is invoked with the Draw method override i added to the custom drawing tool and this occurs within the indicator in a separate section as a result of handling mouse button on the chart panel - that all works fine.

          The reason i wanted to use the Draw.Line .. is that i want to be able to handle the selection and track any movement of this line with the mouse selection.
          I already am drawing the lines in OnRender using sharpDX - but i dont think there is a way to track or get events on those objects in onrender hence trying to use Draw.Line within onbarupdate.

          does that help give more context?

          thanks

          Comment


            #6
            Hello,

            Thank you for the additional details.

            I am unsure in this case as you are using a custom structure for your custom project. As you noted you have two projects in your solution which includes NinjaTrader.Custom. I couldn't really advise in that case as the NinjaTrader.Custom project is a separate project for the compiled NinjaScript source code in the platform. This generally is not meant to be directly added to another solution.

            I was able to see that drawing a line from a visual studio produced DLL which just references the NinjaTrader.Custom project does work, so this is likely to do with the structure you are using in your current project.

            In my test I had used the visual studio example we provide in the help guide here: https://ninjatrader.com/support/help...t_overview.htm

            The steps I had used were as follows:
            • Open the project in Visual Studio and remove the addon.
            • Reference the NinjaTrader.Custom.dll or Remove and then re-reference the NinjaTrader.Custom.dll if using the provided sample
            • Create a dummy indicator for testing in NinjaTrader that simply draws a line and then copy the .cs file into the visual studio solution.
            • Modify the parts of the NinjaScript generated code that do not compile, mainly the declaration for market analyzer and strategy.
            • After doing this, press F6 to build the project and then restart NinjaTrader which will load the assembly and process the indicator.



            If you are able to create your own simple test like the one attached using the structure you have and then upload the whole project, I could take a look at that. Without the whole solution and seeing how everything is declared and placed, it would be difficult to say what specifically is wrong with the way you are trying right now.




            I look forward to being of further assistance.
            Attached Files
            Last edited by NinjaTrader_Jesse; 11-28-2017, 08:42 AM.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello, thanks for update :

              So i see what you are saying and looking into that on my solution.

              I tried loading your solution and see that there is 1 project and references is set to include NinjaTrader.Custom.

              However i dont see in the .csproj for the project which lists the build and build events and reference paths that you havent set this? As the Draw Line was showing as error in visual studio. Once i added reference path it resolved.

              Thanks for sending this solution project and i have now removed the project Ninjatrader.Custom project and included a reference in my own project. In setting this up all worked fine and hadnt considered this aspect and isnt needed.

              Also i need to change my custom draw method as this is a DLL to
              a custom non partial Draw. method for my custom NinjaScript drawing tool
              I was using the Draw method and this wasnt an issue as up until this point i wasnt trying to reference other DrawingTools - in using a partial static it was somehow preventing me accessing other standard drawing tools.

              So this all looks good now as far as referencing the Draw.Line in onbarupdate.

              Regarding events for these lines - is it the case that it is not possible to track mouse events or moving the SharpDX lines in onrender so i must use the standard Draw.Line in onbarupdate?

              thanks for help

              Comment


                #8
                Hello,

                Thank you for the reply.

                To answer the question about the .csproj, it should be in the zip. I see it is stored in the subfolder NinjaTraderAddOnProject\NinjaTraderAddOnProject\Ni njaTraderAddOnProject.csproj
                I can also see the post build events listed, this is simply a copy of the help guide addon, so whatever the sample has in it should be in this zip as well.

                The reference you would need to correct to your local path, I have updated my prior reply to avoid confusion to include that step.

                Regarding OnRender, using a drawing object will almost always be easier than implementing your own mouse handling logic to track x/y and mouse events. You can track items you draw with OnRender, but you would need to make the structure for that to happen and figure out the mouse events for what is needed.

                OnRender is simply a rendering outlet for the script, it lacks any structure and just gives you simple tools to draw shapes and other items to the screen. To do any tracking, you would need to implement a way to do that that corresponds to your custom rendered data or also known as an object. You could then subscribe to the various mouse event handlers on the ChartControl object for example, and then use those events to update your object. The object would be used in OnRender to delegate the drawing.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello, sure i understand the OnRender and use it extensively.

                  If i used ...

                  NinjaTrader.NinjaScript.DrawingTools.Line myline = Draw.Line(this, "My Line1",.......)

                  then i can then override the OnMouseUp OnMouseMove etc within the indicator in order for these lines drawn in onbarupdate to be tracked?

                  Using onRender i already draw many other lines and objects - and there is no tag associated so after checking the object type this would not be enough granualrity to identify the specific lines i want to be moved. Also in OnRender is there a way to lock or unlock a line which i need.

                  So why i was asking is easier to use the Draw.Line method and provide the overrides from the base drawingTool already provided?

                  and OR I am already handling the following for my indicator in reference to another part of indicator

                  ChartPanel.MouseLeftButtonDown -= ChartPanel_MouseLeftButtonDown;
                  ChartPanel.MouseMove -= ChartPanel_MouseMove;
                  ChartPanel.MouseLeftButtonDown += ChartPanel_MouseLeftButtonDown;
                  ChartPanel.MouseMove += ChartPanel_MouseMove;

                  So could those handlers be used to identify my Draw.Line mouse moves or do i need to specifically override the one i see in the help pages ... eg N8 help page reference ..

                  public override void OnMouseUp(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
                  {
                  //when the user releases the mouse, ensure the drawing state is set to normal
                  if (DrawingState == DrawingState.Editing || DrawingState == DrawingState.Moving)
                  DrawingState = DrawingState.Normal;
                  }

                  just exploring the options here and which would be best in order to clearly identify
                  my lines which i want to move and track .. as NONE of the lines drawn in onRender already do i want to or need to move or track,

                  thanks

                  Comment


                    #10
                    Hello, following on from prior - i was trying to compile another indicator in the ninjascript editor earlier and i get the following compile error ? For standard indicator?

                    What is this referring to ? the Ninjatrader.Vendor.dll is in the references and if i try to add Ninjtrader.Custom.dll it says cannot.

                    Also note in the bin/Custom directory NinjaTrader.Custom CSPROJ file appeared with recent modified time .. where does this come from ?

                    I didnt do a build since 13:40 of my own DLL and all is good.

                    see enclosed image

                    thanks
                    Attached Files

                    Comment


                      #11
                      Hello,

                      Thank you for the reply.

                      Regarding your first question:
                      NinjaTrader.NinjaScript.DrawingTools.Line myline = Draw.Line(this, "My Line1",.......)

                      then I can then override the OnMouseUp OnMouseMove etc within the indicator in order for these lines drawn in onbarupdate to be tracked?
                      I am not sure I understand what you are asking here, a Drawing object has its overrides because of what the drawing objects class Inherits. Using a DrawingObject in an indicator would not change what the indicator inherits. You cannot use the Drawing Object overrides in an indicator, they can only be used in a Drawing Object.

                      An indicator its self does not have mouse overrides but you can use event handlers like you have provided the syntax for. To track the Draw.Line you have shown, you would store its Tag name or the variable myline that you are creating. Because the Draw. method creates an Object and is not just a Rendered value, you can store its Object to a variable to keep track of it. DrawingTools also use a Tagging system, you can store a Tag name if you want to later update that specific object.

                      To update a drawing tool based on a mouse event, you would just call the Draw. method with new values using the existing tag. OnBarUpdate may initially draw the object, but anywhere you call the Draw. syntax with a tag that has already been used, it would just update the existing object.

                      Regarding your next question:
                      So why i was asking is easier to use the Draw.Line method and provide the overrides from the base drawingTool already provided?
                      I am also not certain what you are asking here, I had noted it was likely easiest to use Draw.Line opposed to creating your own logic and using OnRender previously, is this what you are commenting on?

                      Regarding your question on the handlers:
                      So could those handlers be used to identify my Draw.Line mouse moves or do i need to specifically override the one i see in the help pages ... eg N8 help page reference ..
                      The mouse handlers are simply event handlers relating to the mouse, there are no event handlers that are meant for identifying objects. You would instead use a Tag name or store a variable to the object you want to change for example the myLine variable you have shown. Using the tag name you can use the mouse x/y values to calculate a bar and price and then call the Draw. method with the objects tag name to update it. Using the variable, you can access the objects Tag property and then call the appropriate Draw method to update that object.

                      Regarding the error you are seeing,

                      You should not need to add a direct reference to NinjaTrader.Custom in the NinjaScript editor. Can you provide details on the indicator you were compiling when this happened? If you exclude that indicator does the error resolve?

                      Code:
                      Also note in the bin/Custom directory NinjaTrader.Custom CSPROJ file appeared with recent modified time .. where does this come from ?
                      The NinjaTrader.Custom.csproj file is auto-generated on every compile. This file should exist and you should not make changes to it.

                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Hello, yes apologies if i confused you but the key is in that : i will use the event handlers i already have in place. The reason i raised this is that lines in onrender dont have any tag or return value from RenderTarget.DrawLine .... unlike the Draw.Line used in onbarupdate

                        What i want to do is : draw several lines and leave them locked and on certain conditions unlock them so the user can move them around but not delete/remove them. When unlocked the user can move them if they choose - i want to track where they move to ie the x,y - as they will be horizontal lines it will just be a y - price change and so can retrieve the values via my reference. But i also want to know when they are moved in the code and to track this. Can i do this with the event handlers i already have and check if the mouse has selected one of my draw object lines and not just on a random area on the chart? Does that make sense in what i am trying to achieve.
                        I already track the mouse events in those handlers but that is for something different and not related to lines.

                        The indicator you will see in the error message picture i included is ADL.cs - which is a standard one - and i cant exclude it - i note you wrote the tip sheet page on compilation errors and went through this

                        Is it possible since i had NinjaTrader.Custom in my visual studio solution ... and is now removed that it is corrupted - i guess inadvertently i was regenerating it ? So a reinstall may be required?

                        thanks for confirming on the .csproj file i was just curious as noticed it had updated and hadnt noticed that before.

                        Update to above ...

                        reinstalled 8.0.10 ... tried to launch N8 said unable to compile custom assembly - so launched ninja editor and tried to compile .. same 1 line error for ADL.cs line 28 column 11 code CS0012 as per image i attached in prior ....
                        I tried moving ADL.cs out of indicators directory as cannot be excluded and it moves onto the next one ADX.cs same error - i even renamed the section Indicators in my project to MyIndicators where my custom one is for the DLL being built in visual studio - no change ..

                        What is going on now any ideas?

                        thanks
                        Last edited by soulfx; 11-29-2017, 07:24 AM.

                        Comment


                          #13
                          Hello,

                          Thank you for the reply.

                          The reason i raised this is that lines in onrender dont have any tag or return value from RenderTarget.DrawLine .... unlike the Draw.Line used in onbarupdate
                          Correct, as we have been discussing OnRender is used to render data you provide using the RenderTarget draw methods. There is no object or anything like a DrawingObject in this context. Any Tag or other property used in OnRender would be a result of the variables and data you are using in the script.

                          Drawing objects override a base which has OnRender. At their core, they also use OnRender but a drawing object is an object that wraps around that on render to give access to items like a Tag property or other related methods.

                          Can i do this with the event handlers i already have and check if the mouse has selected one of my draw object lines and not just on a random area on the chart?
                          Yes you can do this, I would suggest looking at the following example which shows how to check what is the Selected chart object:


                          If you modify the sample to have a Print instead of checking for specific objects, you can see that it would work for Drawing objects as well. This uses the Context menu opening event, but in your case you could translate this concept into the mouse event handlers where needed.

                          Code:
                          Type selected = s.ChartObjects.First(t => t.IsSelected).GetType();
                          Print(selected.Name);

                          The indicator you will see in the error message picture i included is ADL.cs
                          Yes, sometimes system indicators can be listed in errors, This does not necessarily mean that indicator is the problem though. It would not be advised to remove any of the items starting with @, if you have please complete a re install again to replace these items.



                          In regard to the overall problem, I would suggest removing your custom assemblies at this point to find what is causing the problem. Please try the following process to work through what you have imported and have compiled in.
                          • Open the NinjaScript editor
                          • Open the Strategies folder and Exclude all custom strategies from compilation
                          • Open the Indicators folder and Exclude all custom indicators from compilation.
                          • At this point check if it compiles, if not you will need to address the custom assemblies.
                          • In the NinjaScript editor, right click and select References and remove the references you have for any custom items you developed, not specifically third party items at this point.
                          • Now Exit NinjaTrader and open the Documents\NinjaTrader 8\bin\Custom folder, locate the .cs files and .dll files for any assemblies you had removed from References and finally move them to your desktop.


                          Once this process is done, check that the platform compiles.
                          If so, you can re-enable indicators and strategies, and then you could work through the removed assemblies to find the problem.

                          I look forward to being of further assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Hello, followed steps ... excluding custom files and removed custom DLL reference and recompiled - restarted and renabled key indicators and recompiled.

                            All is fine again - need to check another custom indicator i did which i needed to build in ninja and references custom DLL - but that should be fine.

                            Any sense how it can get to this state ? there were no errors in custom files but somehow the reference to indicators seem to throw up issue?

                            Will check over the line tag rendering .. the select component i already use this check for other things so will likely be similar - they key being having a way to select and identify the lines hence Draw.Line will be a better fit for what i am doing

                            thanks
                            Last edited by soulfx; 11-30-2017, 09:51 AM.

                            Comment


                              #15
                              Hello,

                              Thank you for the reply.

                              Any sense how it can get to this state ? there were no errors in custom files but somehow the reference to indicators seem to through up issue?
                              Without going through what you have imported and referenced it would be difficult to say what the problem may have been. Based on your description of removing the @ADL.cs and having the error move to the next indicator, that would make me believe the problem resided in one of the assemblies. This would be a situation where you need to review what specific item is causing the problem to gather more details.

                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Aviram Y, Today, 05:29 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Aviram Y  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              3 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              7 responses
                              34 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cls71, Today, 04:45 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post cls71
                              by cls71
                               
                              Started by mjairg, 07-20-2023, 11:57 PM
                              3 responses
                              218 views
                              1 like
                              Last Post PaulMohn  
                              Working...
                              X