• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rontronimous, Today, 09:41 PM
        0 responses
        1 view
        0 likes
        Last Post rontronimous  
        Started by 400396, Today, 09:34 PM
        0 responses
        2 views
        0 likes
        Last Post 400396
        by 400396
         
        Started by sandman55, Today, 08:00 PM
        0 responses
        3 views
        0 likes
        Last Post sandman55  
        Started by Oracletrades, Yesterday, 02:56 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Bbrandon5567, Today, 04:56 PM
        1 response
        8 views
        0 likes
        Last Post Bbrandon5567  
        Working...
        X