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 frankthearm, Today, 09:08 AM
      6 responses
      24 views
      0 likes
      Last Post frankthearm  
      Started by maybeimnotrader, Yesterday, 05:46 PM
      3 responses
      23 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by adeelshahzad, Today, 03:54 AM
      5 responses
      32 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by stafe, 04-15-2024, 08:34 PM
      7 responses
      32 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by merzo, 06-25-2023, 02:19 AM
      10 responses
      823 views
      1 like
      Last Post NinjaTrader_ChristopherJ  
      Working...
      X