NexusFi: Find Your Edge


Home Menu

 





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


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Zondor with 2 posts (4 thanks)
    2. looks_two fluxsmith with 2 posts (3 thanks)
    3. looks_3 skyfly with 2 posts (1 thanks)
    4. looks_4 Todd 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 9,901 views
    2. thumb_up 12 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 2 attachments




 
Search this Thread

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

  #1 (permalink)
 
Todd's Avatar
 Todd 
Alpharetta, GA
 
Experience: Intermediate
Platform: ninja
Broker: Mirus / Zenfire
Trading: ES
Posts: 234 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?
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
 
  #3 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787



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: 322


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 )

 
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,731

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 Twitter 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: 322


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,731

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



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 Twitter 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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts