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

Dynamically changing the plot color

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

    Dynamically changing the plot color

    I have 4 plots that I would like to overlay on prices. Two plots are TSFs (one over a 20 period, the other over an 80 period) and the other two are averages of the first two (over a 5 period for the shorter TSF, over a 20 period for the longer TSF). If the TSF is greater than its average, both the TSF and the average should be green, otherwise they should be magenta. As there is apparently no way to determine the plot color for each bar, I have chose an implementation via .Min and .Max of the Plot objects (which required the creation of 8 plots instead of 4). But I can't make it work. Any advice would be appreciated (open to other ways of implementing this as well).

    Code:
            protected override void Initialize()
            {
                Add(new Plot(Color.Green, PlotStyle.Line, "LTUp")); // Plot0
                Add(new Plot(Color.Magenta, PlotStyle.Line, "LTDn")); // Plot1
                Add(new Plot(Color.Magenta, PlotStyle.Line, "LTAvgUp")); // Plot2
                Add(new Plot(Color.Green, PlotStyle.Line, "LTAvgDn")); // Plot3
                Add(new Plot(Color.Green, PlotStyle.Line, "STUp")); // Plot4
                Add(new Plot(Color.Magenta, PlotStyle.Line, "STDn")); // Plot5
                Add(new Plot(Color.Magenta, PlotStyle.Line, "STAvgUp")); // Plot6
                Add(new Plot(Color.Green, PlotStyle.Line, "STAvgDn")); // Plot7
                CalculateOnBarClose    = true;
                Overlay                = true;
                PriceTypeSupported    = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 80) return;
                Values[0].Set(TSF(0,80)[0]); // LT Up
                Values[1].Set(TSF(0,80)[0]); // LT Dn
                Values[2].Set(EMA(Values[0],20)[0]); // LT Avg Up
                Values[3].Set(EMA(Values[0],20)[0]); // LT Avg Dn
                Values[4].Set(TSF(0,20)[0]); // ST Up
                Values[5].Set(TSF(0,20)[0]); // ST Dn
                Values[6].Set(EMA(Values[4],5)[0]); // ST Avg Up
                Values[7].Set(EMA(Values[4],5)[0]); // ST Avg Dn
                Plots[0].Min = EMA(Values[0],20)[0]; // Green when above EMA20
                Plots[1].Max = EMA(Values[0],20)[0]; // Magenta when below EMA20
                Plots[2].Min = TSF(0,80)[0]; // Green when below TSF80
                Plots[3].Max = TSF(0,80)[0]; // Magenta when above TSF80
                Plots[4].Min = EMA(Values[4],5)[0];  // Green when above EMA5
                Plots[5].Max = EMA(Values[4],5)[0]; // Magenta when below EMA5
                Plots[6].Min = TSF(0,20)[0]; // Magenta when below TSF20
                Plots[7].Max = TSF(0,20)[0]; // Green when above TSF20

    #2
    trader2be,

    You seem like you are trying to do multi-colored plots. Please see this reference sample for how to do them: http://www.ninjatrader-support2.com/...ead.php?t=3227
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh-

      I've been using the SampleMultiColoredPlot indicator to highlight slope changes.

      Would it be possible to add a sound or audio alert for slope changed to this indicator?

      Comment


        #4
        CoopGeko, yes this would be possible via custom coding as well - you would be using then the PlaySound() or Alert() methods in our NinjaScript language to achieve this.


        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        4 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X