Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding tools to Drawing Tools

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

    Adding tools to Drawing Tools

    Hi,
    I was wondering whether it is possible to add an additional Ray to drawing tools, and if so, how I could go about it.

    I just need to have 2 Rays with different colors without having to toggle and select the colors each time I draw a ray.

    Regards
    Kay Wai

    #2
    Hello Kay Wai,

    Thank you very much for your post.

    The NinjaTrader platform itself would not provide an option to add a duplicate of a drawing object to the menu itself. This means the only option I see would be to set up two different templates and either apply these templates to the Ray or change the object manually.

    However, I suspect it should be possible to use NinjaScript to make a copy of one drawing object. This should allow you to have two differently colored Ray drawing objects in the same list.

    If you would like to pursue this further, please let us know, one of our NinjaScript Technicians would be happy to take a closer look at it!
    Manfred F.NinjaTrader Customer Service

    Comment


      #3
      Hi Manfred,

      Making a copy of a drawing object works for me. Could you assist?

      Regards
      Kay Wai

      Comment


        #4
        Hi kaywai, thanks for your question. The drawing tools in the platform are completely customizable. They can get complex so we do recommend those exploring the source code be at least intermediate to advanced level in C# programming. The Ray drawing tool is actually a derivation of the base Line class. I made a new script that isolates only the Ray portion of the Line.cs script that you can use and study if you wish. It's called "Ray2".

        Kind regards,
        -ChrisL
        Attached Files
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks ChrisL. That worked very well.

          Another question I have is with Draw.Line, is it possible to have the line changed from the left side of the bar to the right side of the bar rather than from the middle of the bar to the left side of the future bar?

          Regards
          Kay Wai

          Comment


            #6
            Hi Kay, thanks for the follow up. You can right click>Go to Drawing Tools>Snap Mode>Disabled to disable the snapping mode. Other than this, you would need to customize the Rendering/Mouse UpDown method of the drawing tool you want to customize.

            Kind regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Sorry I wasn't clear Chris.

              I wanted to change the behaviour of the Draw.Line code for an indicator. Right now, it draws from the middle of the current bar to the middle of the future bar. That's the way Ninjatrader has coded it.

              I want to change it to drawing from the left side of the current bar to the right side of the current bar. Happy to have all my indicators print in the same way when the Draw.Line is used.

              Regards
              Kay Wai

              Comment


                #8
                Hi Kay, sorry but there is nothing built in that can change this behavior. You would need to use a custom drawing tool or render objects "manually" using the Indicator's OnRender method. See the SampleCustomRender script for a showcase of what OnRender can do.

                Kind regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Chris, thank you for posting the Ray2.cs, it is helping me draw my own trend line rays. I have been playing with ChatGPT to set the tag to these rays as "TrendRay" + DateTime.Now.ToString("yyyyMMddHHmmss"), but have not found code that works. Can you recommend a solution?

                  This is the first few lines of the modified Draw class code:
                  ' public partial class Draw
                  {
                  private static string GenerateDefaultTag()
                  {
                  return "TrendRay" + DateTime.Now.ToString("yyyyMMddHHmmss");
                  }

                  private static T DrawRay2TypeCore<T>(NinjaScriptBase owner, bool isAutoScale, string tag,
                  int startBarsAgo, DateTime startTime, double startY, int endBarsAgo, DateTime endTime, double endY,
                  Brush brush, DashStyleHelper dashStyle, int width, bool isGlobal, string templateName) where T : Ray2
                  {
                  if (owner == null)
                  throw new ArgumentException("owner");​'

                  I can send you the whole cs if you like,

                  Thank you,
                  Bruce K.

                  Comment


                    #10
                    Originally posted by BruceK View Post
                    Chris, thank you for posting the Ray2.cs, it is helping me draw my own trend line rays. I have been playing with ChatGPT to set the tag to these rays as "TrendRay" + DateTime.Now.ToString("yyyyMMddHHmmss"), but have not found code that works. Can you recommend a solution?

                    This is the first few lines of the modified Draw class code:
                    ' public partial class Draw
                    {
                    private static string GenerateDefaultTag()
                    {
                    return "TrendRay" + DateTime.Now.ToString("yyyyMMddHHmmss");
                    }

                    private static T DrawRay2TypeCore<T>(NinjaScriptBase owner, bool isAutoScale, string tag,
                    int startBarsAgo, DateTime startTime, double startY, int endBarsAgo, DateTime endTime, double endY,
                    Brush brush, DashStyleHelper dashStyle, int width, bool isGlobal, string templateName) where T : Ray2
                    {
                    if (owner == null)
                    throw new ArgumentException("owner");​'

                    I can send you the whole cs if you like,

                    Thank you,
                    Bruce K.
                    From our experience at this time, AI tools such as ChatGPT are not quite adequate to generate valid compilable NinjaScripts that function as the user has intended. We often find that the generated code will call non-existent properties and methods, use improper classes or inheritance, and may have incorrect logic. We highly encourage that you create a new NinjaScript yourself using the NinjaScript Editor, and use the code generated by AI tools as more of suggestions and guides when coding the script yourself, than using the actual code generated.

                    While It would not be within our support model to correct these scripts at user request, we would be happy to provide insight for any direct specific inquiries you may have if you would like to create this script yourself. Our support is able to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational services.

                    Please let us know if we may be of further assistance.​
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      Emily, thank you for your speedy response.
                      Can you provide guidance on a way to set the Tag string with an appended timestamp, rather than the Tag have a sequence number appended? Currently the Tags are "Ray2", then "Ray2 2", Ray2 3".

                      Thank you,
                      Bruce K

                      Comment


                        #12
                        About Adding tools to Drawing Tools Hi ChrisL, the Ray2 also was very helpful to me. I was wondering if you can also send a Ray3 and Ray4? I was trying to duplicate the Ray2, but I guess it doesn't work like that. I'm also interested in doing the same thing to the Fibonacci Retracement drawing tool. I hope you are able to help! Thank you.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by wzgy0920, 04-20-2024, 06:09 PM
                        2 responses
                        27 views
                        0 likes
                        Last Post wzgy0920  
                        Started by wzgy0920, 02-22-2024, 01:11 AM
                        5 responses
                        32 views
                        0 likes
                        Last Post wzgy0920  
                        Started by wzgy0920, 04-23-2024, 09:53 PM
                        2 responses
                        74 views
                        0 likes
                        Last Post wzgy0920  
                        Started by Kensonprib, 04-28-2021, 10:11 AM
                        5 responses
                        193 views
                        0 likes
                        Last Post Hasadafa  
                        Started by GussJ, 03-04-2020, 03:11 PM
                        11 responses
                        3,235 views
                        0 likes
                        Last Post xiinteractive  
                        Working...
                        X