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

Custom Drawing Tool Line

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

    Custom Drawing Tool Line

    Hello all!

    I am wondering if anyone has a horizontal line drawing tool template that I could use, The NT8 lines script contains ALL of the lines and I am not sure how to separate the horizontal line tool from all of the other line types. I am looking to make 2 custom horizontal lines (Support and Resistance colors) that I can put in a Drawing Tool Tile.

    I have looked for a template like this for a while now, and I feel a basic line template would help a lot of people figure out how to create their own custom drawing tools. Since switching colors is a pain and the feature request has not happened yet, This would be a fantastic work around.

    Thanks in advance and happy trading!

    BeachTrader

    #2
    Hello BeachTrader11807,

    Thank you for your post.

    Sorry for the delay, took a bit to strip the Lines.cs code down to just the Horizontal Line bits. I'm attaching an example of a custom horizontal line drawing tool script. If you want to duplicate this, I would right click on the script > Save As, give it a new name, and then renaming classes and enums that are duplicated.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you so much Kate! This is exactly what I wanted.

      Cheers!

      Comment


        #4
        I have made the Support Resistance Horizontal Line Tools, and I have uploaded them to the Ecosystem if anyone is interested in using them. I will upload them to this thread as well.

        Happy trading!

        BeachTrader
        Attached Files

        Comment


          #5
          Hey Kate!

          If you have time can you extract the "Highlight Region Y" from the lines.cs. I tried to accomplish what you did with the Horizontal Line and man, its too intense for me, lol.

          Anyways, if you can get this done, I will build a Support and Resistance Highlight area for the community.

          Thanks in advance,

          BeachTrader

          Comment


            #6
            Hello BeachTrader11807,

            Thank you for your reply.

            Region Highlight Y would be in RegionHighlight.cs - I've extracted the attached code from there.

            Please let us know if we may be of further assistance to you.
            Attached Files
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Thank you NinjaTrader_Kate!

              Comment


                #8
                I have compiled the Support/Resistance Zone Drawing Tools and will attach to this thread. They will also be uploaded to the ecosystem.

                Cheers!
                Attached Files

                Comment


                  #9
                  Quick question related to this thread. How do we change the name that shows in the "Drawing Tool" list when you click on the Pencil on the chart. The Ruler, Line, Ray, etc... are there and when you make a custom tool it shows in its own section toward the bottom, but the name is still Ruler, Line, Ray.
                  Example:
                  Name = Custom.Resource.NinjaScriptDrawingToolArrowLine;
                  Shows up in the list as "Arrow Line"

                  Can I make a copy of this and change the name so it shows up as "My Arrow Line"?

                  Comment


                    #10
                    Hello robertcooney,

                    Thank you for your reply.

                    If you make a custom drawing tool, simply set its Name to a string of your choosing rather than Custom.Resource.NinjaScriptDrawingToolArrowLine:

                    Name = @"My Arrow Line";

                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Kate View Post
                      Hello robertcooney,

                      Thank you for your reply.

                      If you make a custom drawing tool, simply set its Name to a string of your choosing rather than Custom.Resource.NinjaScriptDrawingToolArrowLine:

                      Name = @"My Arrow Line";

                      Please let us know if we may be of further assistance to you.
                      Worked perfectly! Thank you!!

                      Comment


                        #12
                        NinjaTrader_Kate in post#6.


                        I would like to draw 2 RegionHighlightY custom or built in on the chart name them RegionA and RegionB. I would then want to be able to move them and read the new values.

                        The iteration code below is close but I cannot find the right intellisense objects.



                        Per docs price can be retrieved from a custom tool
                        Note: PriceLevels is only used with the following pre-built Drawing Tools, but it can be used with custom Drawing Tools, as well:


                        Code:
                        protected override void OnBarUpdate()
                        {
                        
                        
                        foreach (DrawingTool draw in DrawObjects.ToList())
                        {
                        // Finds line objects that are attached globally to all charts of the same instrument
                        if (draw.IsGlobalDrawingTool && draw is DrawingTools.Line)
                        {
                        DrawingTools.Line globalLine = draw as DrawingTools.Line;
                        // Changes the line color and prints its starting and end points
                        globalLine.Stroke.Brush = Brushes.Black;
                        Print("Start: " + globalLine.StartAnchor.SlotIndex + " End: " + globalLine.EndAnchor.SlotIndex);
                        }
                        // Finds non-global line objects
                        else if (draw is DrawingTools.Line)
                        {
                        // Indicates if this is a manually drawn or script generated line
                        Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.IsUserDrawn+ " Linename="+draw.Name);
                        }
                        //else if (draw is DrawingTool.RegionHighlightMode.
                        
                        
                        
                        if (draw.IsGlobalDrawingTool && draw is DrawingTools.RegionHighlightY) {
                        
                        }
                        
                        if (draw is DrawingTools.RegionHighlightY) {
                        Print ("Found1 userdrawn RegionHighlightY");
                        Print("Displayname="+ draw.DisplayName + " drawtostring=" + draw.ToString()+ " named"+draw.Name+ " GetType"+ draw.GetType().ToString() );
                        }
                        
                        if (draw is DrawingTools.RegionHighlightY2) {
                        Print ("Found1 userdrawn RegionHighlightY2");
                        Print("Displayname="+ draw.DisplayName + " drawtostring=" + draw.ToString()+ " named"+draw.Name+ " GetType"+ draw.GetType().ToString() );
                        //mydouble=draw.MaxValue.IsFractionalPrice();
                        Print("StartAnchorMaxValue="+ draw.MaxValue+" Min="+draw.MinValue+" draw.GetExtendedDataPoint="+draw.ChartPanel.Y +" draw.Anchors.Max"+draw.Anchors.ToString() + "Pdraw.MaxValue.IsFractionalPrice=" ); //+draw.MaxValue.IsFractionalPrice );
                        //draw.GetExtendedDataPoint
                        //draw.IsAttachedToNinjaScript
                        //draw.isx
                        //draw.Anchors.Max
                        // Pdraw.MaxValue.IsFractionalPrice
                        }
                        //else Print("Something named"+draw.Name+ " GetType"+ draw.GetType().ToString());
                        }
                        }
                        }
                        }
                        Last edited by BartMan; 07-01-2022, 06:52 AM.

                        Comment


                          #13
                          Custom Region Highlight Y, I can select the upper or lower Y then I can drag or type into the properties window a new value for each Y. Is there a way to make the values public.

                          it is exposed to alerts but not to indicators.


                          public override bool IsAlertConditionTrue(AlertConditionItem conditionItem, Condition condition, ChartAlertValue[] values,
                          ChartControl chartControl, ChartScale chartScale)
                          {
                          double minPrice = Anchors.Min(a => a.Price);
                          double maxPrice = Anchors.Max(a => a.Price);
                          DateTime minTime = Anchors.Min(a => a.Time);
                          DateTime maxTime = Anchors.Max(a => a.Time);

                          Predicate<ChartAlertValue> predicate = v =>
                          {
                          bool isInside = v.Value >= minPrice && v.Value <= maxPrice;
                          return condition == Condition.CrossInside ? isInside : !isInside;
                          };
                          return MathHelper.DidPredicateCross(values, predicate);
                          }

                          Comment


                            #14
                            Hello BartMan,

                            Thank you for your replies.

                            I'm a little confused as to what you're wanting to do. Are these manually drawn regions, or are you drawing them from a script like an indicator and just need to update them as necesssary?

                            Thanks in advance; I look forward to assisting you further.
                            Kate W.NinjaTrader Customer Service

                            Comment


                              #15
                              I would like to draw from an indicator or manually.

                              If drawn from an indicator the name is easier to assign a tag or name and track. I would then be able to pick it up and move it.
                              But at times I want to manually draw them. I wish to enter a EnterShortStopMarket once we are in the range. I can do this with a strategy or indicator.

                              For MES I would like to say if it goes into this range sell upon price below the range. If it goes above the range I want to cancel a EnterShortStopMarket


                              I Click image for larger version

Name:	EnterRange but do not go past.png
Views:	915
Size:	6.5 KB
ID:	1207298



                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by FrancisMorro, Today, 03:24 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post FrancisMorro  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,770 views
                              0 likes
                              Last Post Leafcutter  
                              Started by Rapine Heihei, 04-23-2024, 07:51 PM
                              2 responses
                              31 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              945 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Working...
                              X