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

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
      BertrandNinjaTrader Customer Service

      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...
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by r68cervera, Today, 05:29 AM
                0 responses
                2 views
                0 likes
                Last Post r68cervera  
                Started by geddyisodin, Today, 05:20 AM
                0 responses
                3 views
                0 likes
                Last Post geddyisodin  
                Started by JonesJoker, 04-22-2024, 12:23 PM
                6 responses
                33 views
                0 likes
                Last Post JonesJoker  
                Started by GussJ, 03-04-2020, 03:11 PM
                12 responses
                3,239 views
                0 likes
                Last Post Leafcutter  
                Started by AveryFlynn, Today, 04:57 AM
                0 responses
                6 views
                0 likes
                Last Post AveryFlynn  
                Working...
                X