Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Chart background color based on indicator output

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

    Chart background color based on indicator output

    I was wondering if there was a way to edit an indicator to change the chart background color, and to actually do it globally so all my charts background colors change, based on the current value of the indicator. Although it sounds simple, I want to have a green background when RSI > 50 and a red background when RSI < 50.

    Searching the topics here hasn't led to anything similar. I'm not a programmer, but I can bump my way around the strategy wizard, so I was curious if there was a similar wizard for indicators.

    #2
    Hello qphage,

    Thank you for your reply.

    To clarify, are you wanting the chart background to change based on the value of the RSI of one of the charts on all the other charts, or would you want it to use the RSI value of whatever the primary series bars are? For example, an RSI on a 5 minute chart will have different values than an RSI on a 60 minute chart. For example, if you place the indicator on a 1 minute chart, would you want the backgrounds of all the charts to change based on the 1 minute chart's RSI values?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hi Kate,
      I'm basically only using 2 charts, both 5 minute, but the RSI on the 1st chart, or the one I want to trigger the changes, won't match the RSI on the second chart because the first chart will be a line-break chart, and the second a regular candle chart. That's why I want global changes, so that when RSI 1st chart > 50, both backgrounds change to green..( < 50 both red).
      To answer your question as well, if not more complex - yes, I would like the 5 minute line break trigger chart (1st) to customize the second chart whatever the interval is set to (on the 2nd chart) 1,5,15 min etc.
      Hope that is clearer....
      Gary.

      Comment


        #4
        Hello qphage,

        Thank you for your reply.

        While there is indeed an Indicator Wizard in the platform that comes up in the NinjaScript Editor when you right click on the Indicator folder on the right and select New Indicator, this isn't a full fledged indicator builder like the Strategy Builder. It can only set up basic things like added series, plots, and user inputs. Any other code you'd have to manually create.

        That being said, I've created a simple example indicator that calls the RSI on a basic 5 minute series (the RSI period and smooth settings are customizable user inputs, but the RSI will always be calculated on the added 5 minute series and when applied to a chart, will color the background of the chart green if the current 5 minute RSI value is 50 or above and red if it's 50 or below. I've put a number of comments in the code so you can use this as a learning example off which to base your own code.

        For example, if you wanted to use a 5 minute line break series instead of regular 5 minute candles you could swap out the call to AddDataSeries with a call to AddLineBreak:



        You can then apply this to each chart you want to see the current background color change based on that RSI.

        Please let us know if we may be of further assistance to you.
        Attached Files

        Comment


          #5
          My extreme thanks for this Kate, and sorry for such a long delay with my reply.
          It is doing just as I asked, and I'm having some fun tweaking it for use on other time frames.

          I was wondering, could you direct me to a tutorial that walks through adding code that can adjust the area's opacity?
          OR AND, can add that function to the indicator's dialog box?

          Gary

          Comment


            #6
            Hello qphage,

            Thank you for your reply.

            For that you would need to create and freeze a new solid color brush using FromArgb:

            // set the background brush for every bar to green
            Brush myBrush = new SolidColorBrush(Color.FromArgb(100, 0, 255, 0));
            myBrush.Freeze();

            BackBrushAll = myBrush;

            The first number (100) there is the opacity. Higher is more opaque The other values are standard RGB values - you can use online color pickers to help you get the values you'd want for those.

            You can then create an input if you like to get an opacity value from the user and then use that variable in place of the opacity value.

            Please let us know if we may be of further assistance to you.

            Comment


              #7
              Hi Kate, Would you be so kind as to create me a sample indicator for the SMI Indicator that changes the background color of current chart when the SMI line crosses the SMIEMA line. I am not a programmer. I would want to be able to change the SMI Indicator Parameters. Thank you in advance for your help.
              Larry Wagoner

              Comment


                #8
                Hello Larry,

                Below I am providing a link to a support article with helpful resources on getting started with C# programming and NinjaScript.


                "the SMI Indicator that changes the background color of current chart when the SMI line crosses the SMIEMA line"

                This script could actually be built using the Strategy Builder with a point and click interface. Be sure to watch the 'Automate Your Trading with NinjaTrader's Strategy Builder' training video linked from the Getting Started with NinjaScript support article.​


                In the example provided by Kate in post # 4 note:
                • Within the scope of the class the RSI1 variable declared as the type RSI on line 30
                • Within State.DataLoaded of OnStateChange() the instantiation of the RSI indicator on an added 5 minute series by calling the RSI method and assigning this to the RSI1 variable on line 61
                • The condition comparing this value to greater than or equal to 50 on line 72 or less than 50 on line 78.
                For your custom script within the scope of the class declare a variable of the type SMI.
                Where you have mentioned: "SMIEMA " this sounds like you want to supply the SMI as the input series to the EMA.
                If so, also declare a variable of the type EMA.

                private SMI SMI1;
                private EMA SMIEMA1;

                Within the scope of the State.DataLoaded condition logic block call the SMI() method and assign this to the SMI variable. Call the EMA() method and supply the SMI variable as the first parameter, and assign this to the EMA variable.

                SMI1 = SMI(25, 1, 13, 25);
                SMIEMA1 = EMA(SMI, 14);

                "changes the background color of current chart when the SMI line crosses the SMIEMA line"

                So instead of above or below, you would like to only change the background color if the plots have crossed above or below?

                The CrossAbove() and CrossBelow() methods can be used to detect crosses.
                Help guide: NinjaScript > Language Reference > Common > Analytical > CrossAbove()
                Help guide: NinjaScript > Language Reference > Common > Analytical > CrossBelow()

                if (CrossAbove(SMI1, SMIEMA1, 1))
                {
                BackBrushAll = Brushes.Green;
                }
                else if (CrossBelow(SM1, SMIEMA1, 1))
                {
                BackBrushAll = Brushes.Red;
                }


                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Chelsea, Thank you for your response. I have watched the tutorial several times and still don't understand it. Most of Us 70 year olds see how someone else has been helped and hope that we might be able to get some free help too!!
                  Thanks anyway and
                  Sincerely, Larry Wagoner

                  Comment


                    #10
                    Hello Larry,

                    Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                    That said, through email or on the forum we are happy to answer any specific questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                    In this case, an example was provided and an understanding of what to change to suite your needs was provided.

                    This thread will remain open for any community members that would like to create your custom script as a convenience to you.

                    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services.

                    You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more!
                    Programming Services - https://ninjatraderecosystem.com/sea...mming-services
                    Educators - https://ninjatraderecosystem.com/sea...ures=education

                    You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third party services for NinjaTrader all pricing and support information will need to be obtained through the consultant.

                    This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                    Please let me know if you have any questions, or if I can provide any further assistance.​
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    62 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    134 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    75 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    50 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X