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

EMA changes color according to slope

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

    EMA changes color according to slope

    Do we have a code for EMA green when up andsteep, red for down and steep, black for neither of these?

    I found this code which looks interesting, posted by a member and pasted it in but it shows error on the last line ' }expectation' I am clueless about coding, but I thought that I might be lucky if I just pasted it into a new indicator.

    Can anyone help?



    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //

    #region Using declarations
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Exponential Moving Average. The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMACOLORS2 applies more weight to recent prices than the SMA.
    /// </summary>
    [Description("The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMACOLORS2 applies more weight to recent prices than the SMA.")]
    public class EMACOLORS2 : Indicator
    {
    #region Variables
    private int period = 14;
    private int ema34slope = 0;
    private double radToDegrees = 180/Math.PI; // to convert Radians to Degrees for slope calc
    private int angle1 = 30;
    private int angle2 = 60;
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.Green, "EMAup"));
    Add(new Plot(Color.Maroon, "EMAdown"));
    Add(new Plot(Color.Red, "EMAslopedown"));
    Add(new Plot(Color.LimeGreen, "EMAslopeup"));
    Add(new Plot(Color.Gray, "EMAflat"));
    Plots[0].Pen.Width = 2;
    Plots[1].Pen.Width = 2;
    Plots[2].Pen.Width = 2;
    Plots[3].Pen.Width = 2;
    Plots[4].Pen.Width = 2;
    Plots[0].Pen.DashStyle = DashStyle.Dash;
    Plots[1].Pen.DashStyle = DashStyle.Dash;
    Plots[2].Pen.DashStyle = DashStyle.Dash;
    Plots[3].Pen.DashStyle = DashStyle.Dash;
    Plots[4].Pen.DashStyle = DashStyle.Dash;
    Overlay = true;
    PriceTypeSupported = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if(CurrentBar<Period) return;
    ema34slope = (int)(radToDegrees*(Math.Atan((EMA(34)[0]-(EMA(34)[1]+EMA(34)[2])/2)/1.5/TickSize)));
    if(Rising(EMA(Period)))
    {
    if(ema34slope>=angle2)
    {
    EMAslopeup.Set(1,EMA(Period)[1]);
    EMAslopeup.Set(EMA(Period)[0]);
    }
    else
    if (ema34slope>=angle1)
    {
    EMAup.Set(1,EMA(Period)[1]);
    EMAup.Set(EMA(Period)[0]);
    }
    else
    { EMAflat.Set(1,EMA(Period)[1]);
    EMAflat.Set(EMA(Period)[0]);
    }
    }
    else
    { if(ema34slope<=-angle2)
    {
    EMAslopedown.Set(1,EMA(Period)[1]);
    EMAslopedown.Set(EMA(Period)[0]);
    }
    else
    if (ema34slope<=-angle1)
    {
    EMAdown.Set(1,EMA(Period)[1]);
    EMAdown.Set(EMA(Period)[0]);
    }
    else
    { EMAflat.Set(1,EMA(Period)[1]);
    EMAflat.Set(EMA(Period)[0]);
    }
    }
    }

    #2
    I would suggest you check into the EMA Slope color script shared here - http://www.ninjatrader.com/support/f...1&pp=15&page=3

    It should be close to what you seek.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand

      That's very useful.

      Also, if an indicator exists where the color changes once it has moved up a couple of points, or once it reaches a certain angle, that would be useful too.

      Comment


        #4
        stevep3, unfortunately we do not have such an example. I recall quite a few posts have been devoted to that subject, so you could search the forum for "angle" or "slope".
        AustinNinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_Austin

          Thanks for your reply.

          I will follow your advice.

          Comment


            #6
            Does anyone have this indicator edited to work in NT8?

            Thanks

            Comment


              #7
              Originally posted by tswillson16 View Post
              Does anyone have this indicator edited to work in NT8?

              Thanks
              tswillson16, this was actually converted and posted to our NT8 indicators dedicated sharing section - http://ninjatrader.com/support/forum...d=7&linkid=864
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Bertrand,

                Thank you-!!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ScottWalsh, Today, 04:52 PM
                0 responses
                1 view
                0 likes
                Last Post ScottWalsh  
                Started by ScottWalsh, Today, 04:29 PM
                0 responses
                5 views
                0 likes
                Last Post ScottWalsh  
                Started by rtwave, 04-12-2024, 09:30 AM
                2 responses
                22 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Started by tsantospinto, 04-12-2024, 07:04 PM
                5 responses
                70 views
                0 likes
                Last Post tsantospinto  
                Started by cre8able, Today, 03:20 PM
                0 responses
                7 views
                0 likes
                Last Post cre8able  
                Working...
                X