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

Sma that changes color with trend

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

    Sma that changes color with trend

    how to change plot color of sma in NinjaTrader8 ?
    I would like to look back a certain number of bars, not 1 bar like the IsRising code

    eg:
    if (SMA(Period)[0] > SMA(Period)[10])
    PlotBrushes[0][0] = PlotBrushes.Green

    I have no problem writing an indicator using the IsRising code but that only looks back one bar, and is pretty useless for showing trends.

    It seems very difficult to change plot colors.
    Any help would be greatly appreciated

    Thanks
    EsTraderPete

    #2
    Hello EsTraderPete,

    Thanks for writing in.

    You may utilize the ChartIndicators collection to change the color of an indicator's plot.

    Code:
    AddChartIndicator(EMA(Fast));
    AddChartIndicator(EMA(Slow));
    
    ChartIndicators[0].Plots[0].Brush = Brushes.Black;
    ChartIndicators[1].Plots[0].Brush = Brushes.Blue;


    We also have a sample on multi colored plots that may be of use to you. I will link it below:


    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks for replying.
      That example will plot two different emas. What I am trying to do is change the color of one ma.
      As in the IsRising example in the help guide but instead of just looking back one bar as IsRising does, I want to look back 10 or more.

      Comment


        #4
        Originally posted by EsTraderPete View Post
        Thanks for replying.
        That example will plot two different emas. What I am trying to do is change the color of one ma.
        As in the IsRising example in the help guide but instead of just looking back one bar as IsRising does, I want to look back 10 or more.
        Your syntax is defective.
        Code:
        if (SMA(Period)[0] > SMA(Period)[10])
        {
            // PlotBrushes[0][0] = PlotBrushes.Green - [COLOR="Red"][B]this is wrong[/B][/COLOR]
            PlotBrushes[0][0] = Brushes.Green
        }

        Comment


          #5
          Hello EsTraderPete,

          Thanks for writing back to this thread.

          It looks like koganam has given you a direct example that you could also use.

          If you have any other questions, please don't hesitate to ask.
          JimNinjaTrader Customer Service

          Comment


            #6
            Thank you very much for your help. My syntax was the problem. The example from koganam fixed the problem.

            Much appreciated
            EsTraderPete

            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