Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      134 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      75 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      119 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      114 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      92 views
      0 likes
      Last Post CarlTrading  
      Working...
      X