Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing plot colors inside of a strategy or indicator

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

    Changing plot colors inside of a strategy or indicator

    In a NinjaScriptindicator or strategy, you add plots via the Add() method:

    For example:
    protected override void Intialize()
    {
    Add(new Plot(Color.Green, "Plot1"));
    Add(new Plot(Color.Red, "Plot2"));
    }
    Plots are automatically added to the Plots array. You can access individual plot objects and modify properties on them through this array.

    The example code belowswitches the entire "Plot1" color betweengreen and red depending on the SMA values:
    protected override void OnBarUpdate()
    {
    if (SMA(5)[0] > SMA(15)[0])
    Plots[0].Pen.Color = Color.Green;
    else
    Plots[0].Pen.Color = Color.Red;
    }
    RayNinjaTrader Customer Service

    #2
    imported post

    Does this approach work? I was under the impression that you had to "set" different plots of different colors to dynamically change colors.

    Regards,

    Whitmark
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    Comment


      #3
      imported post

      I tried this method and couldn't get it to work. What else needs to be done to make it work?

      OUFan




      Comment


        #4
        imported post

        Yes, this works for changing the "entire" plot color. This is not a solution for a multi-colored plot.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          Okay, for the record then, the initial example works and is useful to understand how plots work but is not a practical example. The typical application of this type of example ismulti-color plot. . . NinjaScipt newbies take heed.
          whitmark
          NinjaTrader Ecosystem Vendor - Whitmark Development

          Comment


            #6
            For the sake of clarification, there is a comment earlier in this thread that implies that the Add() method can be used within a NinjaScript strategy to add a Plot. This is not the case. The Add() method, when used with a strategy, can be used add an indicator (that may have its own plot) or another bars object (that will not display), but the Add(Plot) or Add(Line) is currently only reserved for NinjaScript indicators.
            whitmark
            NinjaTrader Ecosystem Vendor - Whitmark Development

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by canzana, Today, 12:11 AM
            0 responses
            1 view
            0 likes
            Last Post canzana
            by canzana
             
            Started by canzana, Today, 12:10 AM
            0 responses
            1 view
            0 likes
            Last Post canzana
            by canzana
             
            Started by thebionukerlife, Yesterday, 11:41 PM
            0 responses
            2 views
            0 likes
            Last Post thebionukerlife  
            Started by thebionukerlife, Yesterday, 11:40 PM
            0 responses
            2 views
            0 likes
            Last Post thebionukerlife  
            Started by KirkHammett, Yesterday, 11:15 PM
            0 responses
            5 views
            0 likes
            Last Post KirkHammett  
            Working...
            X