Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing line color based on indicator

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

    Changing line color based on indicator

    I tried to change line color using the following but it won't change. Any idea?

    protectedoverridevoid Initialize()
    {
    Add(
    new Plot(Color.Orange, PlotStyle.Line, "L2"));
    ...
    }

    ....
    if(Close[0] < (currentLow+todayFlip) && Close[0] < priordayClose)
    {
    Print(
    "red");
    Plots[
    0].Pen = new Pen(Color.Red);
    }
    else
    {
    Print(
    "blue");
    Plots[
    0].Pen = new Pen(Color.Blue);
    }

    #2
    ssg10,

    as of now, you cannot do it in that fashion. I believe this changes in NT 7.0.

    Either way, you have to have a new plot for each color,

    so to get what you want...

    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()
    {
    Add([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Plot(Color.Red, PlotStyle.Line, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"L2c1"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]));[/SIZE][/FONT][FONT=Courier New][SIZE=2]
    Add([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Plot(Color.Blue, PlotStyle.Line, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"L2c2"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
    ...
    }
     
    ....
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] < (currentLow+todayFlip) && Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] < priordayClose)
    {
       Print([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"red"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
       //set L2c1 here
    [/SIZE][/FONT][FONT=Courier New][SIZE=2]   L2c1.Set(somevalue);
       //if its a LINE plot, you may have to connect the two depending on your application
       L2c1.Set(1, somevalue[1]);
    }
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]else
    [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]{
    [/SIZE][/FONT][FONT=Courier New][SIZE=2]   //set L2c2 here
    [/SIZE][/FONT][FONT=Courier New][SIZE=2]   L2c2.Set(somevalue);
       //if its a LINE plot, you may have to connect the two depending on your application
       L2c2.Set(1, somevalue[1]);[/SIZE][/FONT][FONT=Courier New][SIZE=2]
    }
    [/SIZE][/FONT]


    I believe there is an NT reference sample of this.
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #3
      Thanks for the help mrlogik, here's the reference sample for multicolored plots ssg10 - http://www.ninjatrader-support2.com/...ead.php?t=3227

      Comment


        #4
        Thanks!

        How do we refer to the plot object to change its property?

        Add(new Plot(Color.Red, PlotStyle.Line, "L2c1"));

        will L2c1.Set work, because we define above "L2c1" ?

        Comment


          #5
          From the sample code provided, I got a question.

          RisingPlot.Set(1, SMA(Period)[1]);

          Where is RisingPlot object created?

          Comment


            #6
            Originally posted by ssg10 View Post
            From the sample code provided, I got a question.

            RisingPlot.Set(1, SMA(Period)[1]);

            Where is RisingPlot object created?
            It's a property of a your indicator class

            Comment


              #7
              Originally posted by ssg10 View Post
              Thanks!

              How do we refer to the plot object to change its property?

              Add(new Plot(Color.Red, PlotStyle.Line, "L2c1"));

              will L2c1.Set work, because we define above "L2c1" ?
              Since you have added this Plot in the first spot it can be referred to as Values[0]. If it is defined as "L2c1" in your Properties section you can then call it by that name.
              eDanny
              NinjaTrader Ecosystem Vendor - Integrity Traders

              Comment


                #8
                ssg10, please expand the properties section of the SampleMultiColoredPlot script, then you see the 'linking' of RisingPlot to Values[0] and so on for the other ones...

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                650 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                577 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X