NexusFi: Find Your Edge


Home Menu

 





NT7 - moving average - green when rising, red when falling?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one skyfly with 2 posts (1 thanks)
    2. looks_two Zondor with 2 posts (4 thanks)
    3. looks_3 fluxsmith with 2 posts (3 thanks)
    4. looks_4 max-td with 1 posts (0 thanks)
      Best Posters
    1. looks_one RJay with 4 thanks per post
    2. looks_two Zondor with 2 thanks per post
    3. looks_3 fluxsmith with 1.5 thanks per post
    4. looks_4 skyfly with 0.5 thanks per post
    1. trending_up 10,932 views
    2. thumb_up 12 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 2 attachments




 
Search this Thread
  #1 (permalink)
 
Todd's Avatar
 Todd 
Alpharetta, GA
 
Experience: Intermediate
Platform: ninja
Broker: Mirus / Zenfire
Trading: ES
Posts: 232 since Jun 2009
Thanks Given: 28
Thanks Received: 40

With NT7, is there a moving average indicator (SMA, EMA, WMA) that can be green when rising and red when fallling?


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The Week Ahead -- CPI Wednesday With Oil Past $90, PPI L …
Traders Hideout
$12M Ceasefire Contract Goes Disputed as Bandar Abbas St …
Prediction Markets & Event Contracts
After $87M Settles NO: Irans Nuclear Redline Sets Up the …
Prediction Markets & Event Contracts
NYSE Owner ICE Invests in Crypto Exchange OKX at $25 Bil …
Cryptocurrency
CFTC Approves First US Bitcoin Perpetual Futures -- Kals …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 Vendor: www.innovative-trading-solutions-online.com 
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: ES
Posts: 687 since Jun 2009
Thanks Given: 765
Thanks Received: 789



Todd View Post
With NT7, is there a moving average indicator (SMA, EMA, WMA) that can be green when rising and red when fallling?


Hi Todd,

Someone made this a while back, I forget who.

Copy into indicators directory and compile.

Works in both 6.5 and 7.0 .

You can select EMA, WMA, SMA, and HMA.

Enjoy,

RJay


Attached Files
Elite Membership required to download: ColorSampleUniversalMovingAverage2.cs
Reply With Quote
  #4 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 323


Todd View Post
With NT7, is there a moving average indicator (SMA, EMA, WMA) that can be green when rising and red when fallling?

No, but it's easy. Here's one with some boilerplate elided:
(as shown requires https://nexusfi.com/free_downloads/ninjatrader-7/indicators/517-download.html?view)

 
Code
namespace NinjaTrader.Indicator
{
 [Description("EMA colored green when rising and red when falling.")]
 public class jhlEMAColored : Indicator
 {
    #region Variables
    // Wizard generated variables
    private int period = 14; // Default setting for Period
    // User defined variables (add any user defined variables below)
    private JHL.Utility.EMA ema;
    private double prior;
    private int priorBar = -1;
    #endregion


    protected override void Initialize()
    {
       ema = new JHL.Utility.EMA(Period);
       Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Hash, "Rising"));
       Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Hash, "Falling"));
       Overlay = true;
    }

    protected override void OnBarUpdate()
    {
       if ( CurrentBar == 0 ) {
          prior = Input[0];
          return;
       }
 
       double a = ema.set(Input[0], CurrentBar);
       if ( a > prior ) {
          Rising.Set(a);
          if ( Plots[0].PlotStyle == PlotStyle.Line && !Rising.ContainsValue(1) ) 
             Rising.Set(1, Falling[1]);
       }
       else if ( a < prior ) {
          Falling.Set(a);
          if ( Plots[1].PlotStyle == PlotStyle.Line && !Falling.ContainsValue(1) )
             Falling.Set(1, Rising[1]);
       }
       else { // Equality, set both and let NT deal with it?
          Rising.Set(a);
          Falling.Set(a);
       }
 
       if ( CurrentBar > priorBar ) {
          prior = a;
          priorBar = CurrentBar;
       }
    }
 
    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Rising
    {
       get { return Values[0]; }
    }
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Falling
    {
       get { return Values[1]; }
    }
    [Description("Number of periods in calculations.")]
    [GridCategory("Parameters")]
    publicint Period
    {
       get { return period; }
       set { period = Math.Max(1, value); }
    }
    #endregion
 }
}


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #5 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: NinjatraderŽ
Broker: CQG, Kinetick
Trading: Gameplay KlownbineŽ Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,734

In NT7 we have the new PlotColors Method that allows the color of a single plot to be changed on the fly, without having to use the NT6.5 kluge of switching between different plots and repainting the segment connecting the current value to the value from one bar back.

So if we are plotting an MA to the first plot of an indicator, just do this to have different colors when the indicator is rising or falling.

If(Rising(Values[0]) PlotColors[0][0]=upColor;
if(Falling(Values[0])PlotColors[0][0]=downColor;

or do this to change the color based on the current value vs some threshold

if(Values[0]>SomeThresholdValue) PlotColors[0][0]=upColor;
if(Values[0]<SomeThresholdValue) PlotColors[0][0]=downColor;

The upColor and downColor can be user selectable. They need to be declared as variables, there must be Get/Set statements for them, and they need to be serialized.

There is a thread in the Ninjatrader forums called Multi Color Plot Approach that explains this further. This goes back to the early beta releases of NT7.


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 323


Zondor View Post
In NT7 we have the new PlotColors Method that allows the color of a single plot to be changed on the fly...

That really is better, it does the right thing on non-line plots, and on line plots it splits the difference.


Attached Files
Elite Membership required to download: jhlEMAColored.zip
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #7 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: NinjatraderŽ
Broker: CQG, Kinetick
Trading: Gameplay KlownbineŽ Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,734

Here is an example of a moving average that uses the PlotColors method to give user selectable colors for the rising and falling plot.

https://nexusfi.com/free_downloads/vip_elite_circle/540-download.html?view

It's a triple smoothed EMA, not a simple EMA. It uses predefined instances of the EMA for optimization. Once more, thanks to Richard Todd of MoveTheMarkets.com for his article on this subject.

You may be surprised at how fast this indicator loads and refreshes. Further optimization can be accomplished by making an external call to a more efficient implementation of the EMA, rather than to @EMA.cs.


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
 skyfly 
Texas
 
Posts: 113 since Jun 2010

Every time I try down loading something I get error messages. I have tried more than one indicator, so I know something is wrong on my end. But I have no idea what. I have NT7, every time I try to compile it I get these stupid little error messages. Something about the name and blah blah blah


Reply With Quote
  #9 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

hey skyfly,

please stay in ONE thread with your comiling / importing-issues !
you have one main problem in your Ninja that causes all these errors when compiling / importing.

this has to be find & solved before anything else is working.
please stay here

+ do all the steps, post screenshots of the errors etc to find out whats the problem at your side.
posting in diff threads makes no sense.
we will assist you if we can !

thanks max


max-td
Reply With Quote
  #10 (permalink)
 skyfly 
Texas
 
Posts: 113 since Jun 2010


Right ok...my bad, was just venting a little lol. Just because I have no idea how to fix this, or really even explain it. But I'll keep it in one area from now on. Sorry about that.


Reply With Quote




Last Updated on July 13, 2010


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts