Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add a color to Draw.TextFixed

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

    Add a color to Draw.TextFixed

    I am trying to add a color to the text in Draw.TextFixed. Possibly if you're a programmer the help guide makes sense but for us novices it is clear as mud. I have tried a dozen different variations to get a font into the statement but none has worked. All I am trying to do is, under a condition, is turn the text White

    #2
    Hello galsermil,

    Thanks for your post and welcome to the NinjaTrader forums!

    Ninjascript is written in the programming language C# and if you are unfamiliar it can be difficult to follow. You may want to review the educational link here: https://ninjatrader.com/support/help..._resources.htm in addition you can find plenty of free C# resources on the internet.

    The helpguide show the methods and shows alternate ways to use the methods. The method parameters are identified as to their type.

    To color the text you would need to use the Draw.TextFixed() overload that has these parameters:

    Draw.TextFixed(NinjaScriptBase owner, string tag, string text, TextPosition textPosition, Brush textBrush, SimpleFont font, Brush outlineBrush, Brush areaBrush, int areaOpacity);

    You would replace the parameters with the specifics for your needs

    You would need to set Brush testBrush to the color you wish.

    For example:

    Draw.TextFixed (this, "mytag", "Display this text", TextPosition.TopRight, Brushes.White, new NinjaTrader.Gui.Tools.SimpleFont ("Arial", 10), Brushes.Transparent, Brushes.Transparent, 0);

    Here is a link to the helpguide concerning SimpleFont: https://ninjatrader.com/support/help...font_class.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Many Thanks

      Can I suggest that your colleges follow your lead and give specific examples, as you do, when the query comes from a novice at least. I have tried that specific syntax and merely get various error messages. My syntax was identical except that I had 12 after Arial but I will try again.

      Comment


        #4
        Hello galsermil,

        Thanks for your reply and comments.

        If you continue to get errors, please feel free to post your code that is generating the errors.
        While we do not provide debugging services we can certainly take a quick look and give you guidance to help resolve the errors.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          The code compiles and the two print statements execute but the Text does not turn White.. I am submitting the code

          double diff = Math.Abs(Close[0] - EMA(13)[0]);

          {
          Print(" Diff/TickSize "+diff/TickSize);
          }
          if(diff/TickSize >= 10)
          {
          Print(" Diff/TickSize "+diff/TickSize+"Inside"+Close[0]);
          Draw.TextFixed(this, "tag1", "EMADiff = "+ Math.Round(diff/TickSize), TextPosition.TopRight,Brushes.White,new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12), Brushes.Transparent,Brushes.Transparent,0);
          }
          else
          {
          Draw.TextFixed(this, "tag1", "EMADiff = "+ Math.Round(diff/TickSize), TextPosition.TopRight);
          }
          if ((diff>=Differ*TickSize))
          {
          // CandleOutlineBrush = Brushes.Azure;
          Draw.Line(this, "MyLine"+CurrentBar, false, 0, Close[0], 0, Open[0], Brushes.White, DashStyleHelper.Solid, 2);

          }

          Comment


            #6
            Hello galsermil,

            Thanks for your reply.

            There are 3 different ways to accomplish this. Not trying to overwhelm you but would suggest you try each as they will all work and there is always more than one way to do the same thing.

            ===== 1 ====================

            I would suggest setting the color on both sides, something like this using your current code:

            if(diff/TickSize >= 10)
            {
            Print(" Diff/TickSize "+diff/TickSize+"Inside"+Close[0]);
            Draw.TextFixed(this, "tag1", "EMADiff = "+ Math.Round(diff/TickSize), TextPosition.TopRight,Brushes.White, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12), Brushes.Transparent,Brushes.Transparent,0);
            }
            else
            {

            Draw.TextFixed(this, "tag1", "EMADiff = "+ Math.Round(diff/TickSize), TextPosition.TopRight,Brushes.Green, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12), Brushes.Transparent,Brushes.Transparent,0);
            }


            =========2===============

            One alternative approach would be to create a private Brush and set the color based on the if statement. For example:

            Declare the private brush at the class level:

            public class blank : Indicator
            {
            private Brush myBrush; // create a brush to use in the code

            protected override void OnStateChange()
            {


            Then change your code to:

            if(diff/TickSize >= 10)
            {
            myBrush = Brushes.Red;
            }
            else
            {
            myBrush = Brushes.Green;
            }
            Draw.TextFixed(this, "tag1", "EMADiff = "+ Math.Round(diff/TickSize), TextPosition.TopRight,myBrush, new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12), Brushes.Transparent,Brushes.Transparent,0);


            The advantage with the above is only one draw statement is needed.

            =======3==============

            Finally, another alternative is to embed the if logic right into the Draw statement to have it choose the brush based on the logic of the diff >= some number, for example:

            Draw.TextFixed(this, "tag1", "EMADiff = "+ Math.Round(diff/TickSize), TextPosition.TopRight, (((diff / TickSize) > 2) ? Brushes.Red : Brushes.Green), new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12), Brushes.Transparent,Brushes.Transparent,0);

            In this way you just calculate the Diff and then the draw statement does the rest. For clarity this: (((diff / TickSize) > 2) ? Brushes.Red : Brushes.Green) has the logic evaluation of (diff / TickSize) > 2) the "?" means if it is true then use the Brushes.Red, if it is false then it uses Brushes.Green.

            edit - minor corrections for readability.
            Last edited by NinjaTrader_PaulH; 11-08-2017, 12:46 PM.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              It works.

              Paul,

              Your first suggestion was the easiest for me to understand, so I took it and it works like a charm.

              Thank you.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ghoul, Today, 06:02 PM
              2 responses
              13 views
              0 likes
              Last Post ghoul
              by ghoul
               
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              44 views
              0 likes
              Last Post jeronymite  
              Started by Barry Milan, Yesterday, 10:35 PM
              7 responses
              20 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by AttiM, 02-14-2024, 05:20 PM
              10 responses
              180 views
              0 likes
              Last Post jeronymite  
              Started by DanielSanMartin, Yesterday, 02:37 PM
              2 responses
              13 views
              0 likes
              Last Post DanielSanMartin  
              Working...
              X