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

How to get DrawingTool Color

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

    How to get DrawingTool Color

    Hello!

    I am trying find the best way to find the color of an object that has been plotted by an indicator.
    I've been using the example from this post: https://forum.ninjatrader.com/forum/...arty-indicator

    It works great for most indicators using 'Text'.

    However, I'm having an issue with certain 3rd party indicators that appear to also use 'Text' but the example code does not recognize them. I modified the code from the link to DrawingTools.DrawingTool instead of DrawingTools.Text and it seems to read these 3rd party objects now. But I lost the ability to display the Brush color code. (I may be missing something obvious here)

    Original Code from Link:

    Code:
    protected override void OnBarUpdate()
    {
      foreach (DrawingTool draw in DrawObjects.ToList())
      {
        if (draw is DrawingTools.Text)
        {
          if (draw.Tag == "Text1")
          {
            DrawingTools.Text temp = draw as DrawingTools.Text;
    
           Print("startTime: " + temp.Anchor.Time + " Y axis" + temp.Anchor.Price);
           Print("text: " + temp.DisplayText);
           Print("Font: " + temp.Font.Family);
           Print("Color" + temp.TextBrush);
          }
        }
      }
    }​​
    New Code:

    Code:
    protected override void OnBarUpdate()
    {
      foreach (DrawingTool draw in DrawObjects.ToList())
      {
        if (draw is DrawingTools.DrawingTool)
        {
          if (draw.Tag == "Text1")
          {
            DrawingTools.DrawingTool temp = draw as DrawingTools.DrawingTool;
    
            ///Cannot use these below
           //Print("startTime: " + temp.Anchor.Time + " Y axis" + temp.Anchor.Price);
           //Print("text: " + temp.DisplayText);
           //Print("Font: " + temp.Font.Family);
           //Print("Color" + temp.TextBrush);
          }
        }
      }
    }​​
    Basically what I'm trying to do is:

    ​if (DrawObjects["IndicatorDrawingTag"+ CurrentBar] != null && *IndicatorColor == MyColor* )
    {
    //Do Something;
    }

    Hope this makes sense. Please let me know what the best way would be to find the color from these indicators.

    Thank you in advance!

    #2
    Hello TradeSaber,

    Thank you for your post.

    You wouldn't be able to use .TextBrush unless the drawing object was a Text drawing object.

    I recommend you print out the temp.Name to check what type of drawing object the third party indicator is using. Do not check for if (draw.Tag == "Text1") unless you are sure the third party indicator has given the drawing object the tag name of "Text1".

    If you can confirm they are using text, you can use the code from the original link and use .TextBrush to get the color.

    Please let me know if I can assist further.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hi Gaby,

      Thank you for your reply!

      This is the part that gets me with these specific indicators. The original code works on any indicators I have created myself that uses the Draw.Text();
      It's just these 3rd party ones that also use Text. But this code doesn't seem to recognize them as such, even though the the temp.Display Name for this indicator is Text


      Here is what I mean:
      Original Code does not recognize this indicator as Text.


      When I use the updated code that reads DrawingTools.DrawingTool:
      Click image for larger version

Name:	Updated.jpg
Views:	53
Size:	160.5 KB
ID:	1295703

      Do you know what I could be missing? The original Text code works perfectly fine with other indicators, so I'm sure its just how this one is written, but I'm not seeing what the difference could be. It functions the same way as a regular Text and the Drawing Object properties look exactly the same as any other text.

      Thank you again for your help!

      Comment


        #4
        Hello TradeSaber,

        If you check the Drawing Objects window to the chart with the indicator applied, are the objects showing in that window?

        I'm unable to see the 'original code' image for some reason, are you casting the objects as a Text object?

        Code:
        foreach (DrawingTool draw in DrawObjects.ToList())
        {
        if (draw is DrawingTools.Text)
        {
        DrawingTools.Text myDrawText = draw as DrawingTools.Text;
        
        Print("Text object: " + myDrawText.Tag + " TextBrush: " + myDrawText.TextBrush);
        }
        }
        The 'DrawingTools.Text textObject = draw as DrawingTools.Text;' line casts the object as a Text object. This is necessary in order to detect the object as a drawing object, then be able to use .TextBrush on the object.

        Please let me know if I can assist further.​
        Last edited by NinjaTrader_Gaby; 03-14-2024, 08:35 AM.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Hi Gaby,

          Thank you again for the reply!

          Yes, it seems that part is ok for some indicators using Draw.Text. Its just with other 3rd party ones, it does not recognize it.

          ==================
          I made a quick video that explains what I'm seeing and what is not working:
          https://app.screencast.com/z7JMdgdTjhDQP

          Hope this helps explain. Please let me know if you may know why its happening.

          Thank you!

          Comment


            #6
            Hello TradeSaber,

            If the object type is not Text, you will need to cast this as type of the custom drawing object class.

            What is the drawing object class type that the custom indicator is drawing?

            (What is the draw method in the 3rd party script that is drawing this text?)
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              Thank you for the reply!

              I'm not entirely sure I'm doing this right. But if I check it with Print(temp.ToString());
              It does say this indicator uses Text.
              Click image for larger version

Name:	DrawingToolType.jpg
Views:	44
Size:	152.3 KB
ID:	1295741

              Or is there another way to check this without having access to the code?

              Thank you

              Comment


                #8
                Hello TradeSaber,

                It does appear to be a Text object.

                If you cast this object as a Text is the variable null?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I'm not sure if this is what you mean. I reverted back to the original code with DrawingTools.Text

                  draw is not null.
                  But I cannot check after -> if (draw is DrawingTools.Text):
                  Click image for larger version

Name:	image.png
Views:	39
Size:	320.7 KB
ID:	1295758

                  Hope this is what you meant. Please let me know if I'm not checking what you needed properly.

                  Thank you!​
                  Attached Files

                  Comment


                    #10
                    Hello TradeSaber,

                    I am not directing you to go back to the other code block.

                    In the code block you were previously working on where the issue exists, cast the draw variable as a Text object.

                    DrawingTools.Text textObject = draw as DrawingTools.Text;

                    Is the variable null after the cast?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Ah ok thank you.

                      It appears that changing it to DrawingTools.Text textObject = draw as DrawingTools.Text; does go null.

                      Leaving it as it was before, printed not null

                      Comment


                        #12
                        Hello TradeSaber,

                        That does suggest the type is different.

                        Above that can you print

                        Print(draw.GetType().Name);

                        Does this also print as Text?

                        Are you able to ask the vendor if they are using Draw.Text() calls in their code?
                        (I'm wondering if it might be TextFixed or some custom class that inherits from Text)
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Chelsea,

                          I typed in Print(draw.GetType().Name);

                          It still prints as Text.
                          Click image for larger version

Name:	Print Text.jpg
Views:	41
Size:	124.3 KB
ID:	1295804

                          I've tried TextFixed as well with all of the steps from before but no luck there either.

                          I will reach out to them and hope they are willing to share that info. Will update if I find anything else.

                          Appreciate the help and please let me know if you think it is possible to get the color or drawn text any other way.

                          Thank you.

                          Comment


                            #14
                            Hello TradeSaber,

                            Thank you for following up.

                            I hope they will be able to offer you some useful information. If you'd like, we could provide a snippet that would read information from draw objects generated manually or from a different indicator if that would be helpful to see a working example and compare. Please let us know if this interests you and we can make a simple example for you.

                            Thank you for using NinjaTrader.
                            Emily C.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Emily,

                              Thank you for your reply!
                              Yes please, any additional code is always helpful!

                              ========
                              I got a response from the vendor:
                              "After consulting with our technical team, they confirmed that all indicators with makers are used for a Draw Test."

                              ========
                              I was also able to do a bit of a work around by utilizing Strategy Builder.
                              Luckily, they use a plot of +1 Buy or -1 Sell to mark when the text is created. So I made a simple strategy that creates a new text at according to the Buy and Sell Signals.

                              The original code snippet reads this newly created text without issues:



                              Not sure if reading objects created by a strategy like this will have any negative impacts. It seems to be working fine this way. Just a little more annoying to set up is all. Would still like to read it directly from the indicator itself though.

                              Again, really appreciate the help with this. You guys are amazing!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by carnitron, Today, 08:42 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Today, 07:51 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,969 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Today, 06:48 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post rbeckmann05  
                              Started by rhyminkevin, Today, 04:58 PM
                              4 responses
                              58 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Working...
                              X