Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

value = EMA(14)

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

    value = EMA(14)

    normally, we set the plot0 using the following code
    Value.Set(EMA(14)[0]);

    But why can we not use the following code in the Initialize() directly
    Value = EMA(14);

    When I write like Value = EMA(14), the ninjatrader says error. How can we solve this problem?




    #2
    Hello,

    Thank you for the question.

    Value would be a DataSeries but you are trying to assign the type EMA to a DataSeries which would throw an error.

    I wanted to check, are you just trying to plot the EMA? If so, you would need to utilize Set and do this from OnBarUpdate to avoid errors like your first example:

    Value.Set(EMA(14)[0]);

    I look forward to being of further assistance.

    Comment


      #3
      I am not trying to plot the EMA. Instead, I try to smooth an indicator and let the smoothed value to be the Value DataSeries.

      I can assign an IDataSeries m_smooth like this

      private IDataSeries m_smooth;

      if (type == "EMA")
      m_smooth = EMA(14);
      else if (type =="SMA")
      m_smooth = SMA(14);

      and then let Value.Set(m_smooth[0]);

      Doing this way, we need to DataSeries: m_smooth and Value.
      Can we find a way to reduce the number of DataSereis to only one since Value itself is a DataSeries too?
      something like

      if (type == "EMA")
      (IDataSeries) Value = EMA(14);
      else if (type =="SMA")
      (IDataSeries) Value = SMA(14);

      Can we?

      I just want to reduce the number of used DastaSeries classes in my program.

      Thank you very much.



      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for the question.

      Value would be a DataSeries but you are trying to assign the type EMA to a DataSeries which would throw an error.

      I wanted to check, are you just trying to plot the EMA? If so, you would need to utilize Set and do this from OnBarUpdate to avoid errors like your first example:

      Value.Set(EMA(14)[0]);

      I look forward to being of further assistance.

      Comment


        #4
        Hello,

        The way you are currently doing it would be the standard or suggested way.

        Each indicator will be a Type of its self meaning the EMA is of type EMA and not a DataSeries so trying to assign the type EMA would throw an error because it is not directly a DataSeries.

        You could use only 1 DataSeries and delegate the value in OBU by a switch

        Code:
        if (type == "EMA")
        m_smooth.Set(EMA(14)[0]);
        else if (type =="SMA")
        m_smooth.Set(SMA(14)[0]);

        I am not sure there would be a way to just assign the whole series to a variable in this way, either assigning the Indicator to a variable so you can call it by the variableName[0] or just delegating the logic to output the value to one series as shown above.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        331 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        549 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X