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

changing default EMA values

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

    changing default EMA values

    Dear Traders

    I am a beginner with NinjaScript so hopefully my request will be a piece of cake

    I am trying to create a custom EMA indicator: with a period of 5 and based on HIGH prices.

    I thought I should use the existing NinjaScript code for default EMA and adapt it to my needs. So I have changed a period value successfully to 5. But couldn't think of how to code EMA so that it is based on HIGH prices.


    Just for your information I paste my variable section here:

    public class ema5 : Indicator
    {
    #region Variables
    private int period = 5;
    #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.Blue, "ema5"));

    Overlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
    }

    #2
    Originally posted by ionaz View Post
    Dear Traders

    I am a beginner with NinjaScript so hopefully my request will be a piece of cake

    I am trying to create a custom EMA indicator: with a period of 5 and based on HIGH prices.

    I thought I should use the existing NinjaScript code for default EMA and adapt it to my needs. So I have changed a period value successfully to 5. But couldn't think of how to code EMA so that it is based on HIGH prices.


    Just for your information I paste my variable section here:

    public class ema5 : Indicator
    {
    #region Variables
    private int period = 5;
    #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.Blue, "ema5"));

    Overlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
    }
    You have coded it in the most flexible manner. Just use the configuration GUI to indicate that you want to use the High as your input DataSeries, at the time that you apply the indicator to a chart.

    If you must insist on hard-coding it (not my method of choice, but it is your indicator, so your decision ), just change the word Input to High in the Value.Set line.

    Comment


      #3
      koganam,

      Thank you very much! it worked

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rtwave, 04-12-2024, 09:30 AM
      4 responses
      29 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Started by yertle, Yesterday, 08:38 AM
      7 responses
      28 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by bmartz, 03-12-2024, 06:12 AM
      2 responses
      21 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by funk10101, Today, 12:02 AM
      0 responses
      6 views
      0 likes
      Last Post funk10101  
      Started by gravdigaz6, Yesterday, 11:40 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X