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

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 sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,234 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        1 view
        0 likes
        Last Post thread
        by thread
         
        Started by jclose, Yesterday, 09:37 PM
        0 responses
        6 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,414 views
        0 likes
        Last Post Traderontheroad  
        Started by firefoxforum12, Yesterday, 08:53 PM
        0 responses
        11 views
        0 likes
        Last Post firefoxforum12  
        Working...
        X