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 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 jclose, Today, 09:37 PM
            0 responses
            5 views
            0 likes
            Last Post jclose
            by jclose
             
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            10 responses
            1,413 views
            0 likes
            Last Post Traderontheroad  
            Started by firefoxforum12, Today, 08:53 PM
            0 responses
            11 views
            0 likes
            Last Post firefoxforum12  
            Started by stafe, Today, 08:34 PM
            0 responses
            11 views
            0 likes
            Last Post stafe
            by stafe
             
            Started by sastrades, 01-31-2024, 10:19 PM
            11 responses
            169 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X