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

Indicator with DrawTextFixed Output

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

    Indicator with DrawTextFixed Output

    Hello

    I've developed an indicator that draws text on the price chart when certain criteria are met. Here's the code:

    DrawTextFixed("tag1", "Long", TextPosition.TopRight, Color.Green, Font.Arial, Color.Black, Color.Black,2);

    I'm getting the following error message when compiling:
    System.Drawing.Font does not contain a definition for ''Arial''.

    I'd very much appreciate if someone could help me out here.

    Thanks

    #2
    Hello laocoon,

    The line below should work for you:
    Code:
     
    DrawTextFixed("tag1", "Long", TextPosition.TopRight, Color.Green, new Font("Arial", 12), Color.Black, Color.Black,2);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      perfect, thanks a lot Ryan!

      Comment


        #4
        Hello RyanM,

        I'm using the DrawTextFixed command as you suggested and it works great, I have a problem however to remove the text at a later stage (ie if the entry signal is no longer valid).

        Here's what I did:

        DrawTextFixed("tag1", "X", TextPosition.Center, Color.Black, new Font("Arial", 30), Color.Black, Color.White,2);

        if (High[0] > High[1] || High[0] < High[1])
        {
        RemoveDrawObject("tag1" + (CurrentBar -1));
        }

        This doesn't work as planned, the text stays on the chart.
        I'm guessing that it has something to do with the fact that DrawTextFixed is not compatible with RemoveDrawObject, but I'm not sure how to code it differently.

        Thanks
        Last edited by laocoon; 01-16-2012, 02:39 AM.

        Comment


          #5
          The issue is likely the tag you attempt to using for the remove call, it would not align with the one you assign upon creating the drawing object.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thanks for your reply Bertrand.
            What do you mean by "the tag would not align"? I don't understand this as both tags are identical.

            Thanks

            Comment


              #7
              No, they would not be, for the later one you add the CurrentBar string, while for the former not.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Ah OK, I thought the tag was only the text that's between "..." quotation marks.
                The CurrentBar string is necessary, because otherwise the text is not drawn on the chart, or is there a better way to do it?

                Thanks

                Comment


                  #9
                  DrawTextFixed("tag1", "X", TextPosition.Center, Color.Black, new Font("Arial", 30), Color.Black, Color.White,2);

                  if (High[0] > High[1] || High[0] < High[1])
                  {
                  RemoveDrawObject("tag1" + (CurrentBar -1));

                  You're using 2 different names, hence you attempt to remove an object with a tag that's never been used. You would remove the object with the tag1 name.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    I understand what you're saying, but if I modify the code like this (to create identical tags):

                    RemoveDrawObject("tag1");

                    the object is not even drawn on the chart in the first place.

                    Comment


                      #11
                      Originally posted by laocoon View Post
                      I understand what you're saying, but if I modify the code like this (to create identical tags):

                      RemoveDrawObject("tag1");

                      the object is not even drawn on the chart in the first place.
                      Probably because it's removed everytime when you're trying to draw it?

                      Please see the condition you use to remove it, that would be true for a high percentile of bars you would see.
                      Last edited by NinjaTrader_Bertrand; 01-16-2012, 11:50 AM.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        I understand what you're saying Bertrand. I was just trying to remove the tag once the current bar is closed (which in my setup invalidates the signal and thus makes the tag useless).
                        I'm sure there is a better way of achieving this but I didn't find it yet.

                        Thanks

                        Comment


                          #13
                          Originally posted by laocoon View Post
                          I understand what you're saying Bertrand. I was just trying to remove the tag once the current bar is closed (which in my setup invalidates the signal and thus makes the tag useless).
                          I'm sure there is a better way of achieving this but I didn't find it yet.

                          Thanks
                          This is your original code.

                          Code:
                          if (High[0] > High[1] || High[0] < High[1])
                                      {
                                          RemoveDrawObject("tag1" + (CurrentBar -1));
                                      }
                          The only time your filter condition is not true (and hence the object removal code does not run) is if, and only if, High[0] is equal to High[1], a pretty low occurrence at pretty much anytime. IOW, your removal code is almost certain to be run on every bar.

                          Comment


                            #14
                            Thanks for your comment Koganam, you're absolutely correct.
                            This was actually intended, as the " High[0] is equal to High[1]" condition is the only condition in my strategy where the tag can REMAIN on the chart (after the bar has closed and the new one opens).

                            I'm still looking for an easier way to code this though, as the thing I'm really trying to achieve is the following:

                            If strategy conditions are met (on 10 min chart): draw tag on chart
                            Once current 10 min bar has closed (and thus signal is no longer valid): remove tag
                            If conditions are met again on another 10 min bar: draw tag
                            etc.

                            It sounds embarassingly easy but I wasn't able to code it so far.

                            Thanks

                            Comment


                              #15
                              Hi laocoon,

                              For this implementation you may not need to add + CurrentBar to provide a unique tag, as you're only drawing one thing at a time. I would suspect you could create this with something like:

                              Code:
                              if(Close[0] > Open[0])
                              DrawTextFixed("myTag", "myText", TextPosition.BottomLeft);
                              		
                              else RemoveDrawObject("myTag");
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by gentlebenthebear, Today, 01:30 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post gentlebenthebear  
                              Working...
                              X