Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using the PlotColor when Drawing

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

    Using the PlotColor when Drawing

    Hello,

    I put together an indicator using a Plot that shows a hash and the pricemarker for a higher SMA. For example: I can use it in a 1minute chart so it indicates the SMA20 of a 360min DataSeries. I am not interested in the actual line of that 360 SMA20. I just want to see where it's price is at. Works fine and I can adjust the color through the PlotColor.

    Add(new Plot(Color.LightBlue, PlotStyle.Hash, "RoundedSMA"));
    PlotColors[0][1] = Color.Transparent; // (I use this so it only shows 1 hash)

    Now I would like to add a label into the chart that tells me the timeframe being used. To do that I use DrawText as follows:


    DrawText("tag", false, BarsArray[1].Period.ToString(), -1, (SMA(BarsArray[1],20))[0], 0, textcolor, new Font ("Arial", 7, FontStyle.Regular),StringAlignment.Near, Color.Empty, Color.Empty, 0);

    My question is whether there are any possibilities to define the textcolor through the Plot color?


    sandman






    #2
    Hello sandman,

    The Plots[plot index].Pen.Color will have the color used for the plot. This can be supplied to the DrawText() method.
    https://ninjatrader.com/support/help.../nt7/plots.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea, Thanks for the fast reply which sounds like it is possible.

      The references are unfortunately limited to Plots. They do not show how the DrawText() method can pull in the Plot colors.

      Is there a sample somewhere that shows more exactly how to do that (I am not a pro-programmer), or could you expand on what you said. In case it helps, I am including my indicator. This shows that currently the color has to be set twice: once for the plotting method which paints a hash and the pricemarker; and twice for the color of the label (using DrawText) and a limited horizontal line. I would want to get rid of the separate color choice and instead have it use the same color which the plot method uses.


      sandman

      Attached Files

      Comment


        #4
        Hello sandman,

        The Color object can be supplied anywhere a Color parameter is accepted.

        DrawText(string tag, string text, int barsAgo, double y, Color color)


        For example:
        DrawText("myText", "Some text", 0, High[0] + 2 * TickSize, Plots[0].Pen.Color);
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,

          You make it sound so easy I needed to know that "Plots[0].Pen.Color" is the basic formula.

          Needless to say it works like a charm. Many thanks.

          Have a good day!
          sandman

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X