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

Embedding calculated data in indicator

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

    Embedding calculated data in indicator

    Hi guys

    I'm working on an indicator, and I'm having the following problem:

    I've got successful code (using a 'while loop') which compiles OK. I've defined this data by

    Code:
    double x = [I](calculations)[/I] ;
    This is the crunch: I'd like to embed x within an EMA, but

    Code:
    double y =     EMA(x,14)[0];
    doesn't work. Errors show 'overload method match' and converting from 'double' to data series.

    I'd greatly appreciate any guidance as to how to get this work, so I can somehow end up with an EMA of x.

    Many thanks in advance.

    #2
    Hello arbuthnot,

    I believe the issue is that the variable "x" is a double type object. EMA has two different overloads:

    1. EMA(int period)
    2. EMA(IDataSeries input, int period)

    The one you are using is the 2nd one with a Data Series being required to first parameter.

    If you would like to use the 14 period EMA of the data series your indicator is currently set to you may do something like the following:

    Code:
    double y = EMA(14)[0];
    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks very much, JC, for pointing me towards the concept of 'dataseries'. I looked this up in Help and found an indicator which had implemented this function.

      A few minutes later, all was working great and it's now on a chart.

      For those reading this thread with the same problems, this is how I achieved this myself:

      Code:
      Variables
      
      private DataSeries    zseries; // "zseries" is my own name: could be anything.
      ...
      
      protected override void Initialize()
      
          zseries    = new DataSeries(this);
      
      ...
      
      protected override void OnBarUpdate()
      
      [I](my calculations for z)[/I]
      
      zseries.Set(z);
                  
      double zz = EMA(zseries, 14)[0];
                  
      Plot0.Set(zz);
      Now I know about data series, it can help me branch out into new coding directions.

      Much obliged, JC.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      31 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      2 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,281 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      19 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Started by Tim-c, Today, 02:10 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X