Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unsynched Array to EMA

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

    Unsynched Array to EMA

    Hi NinjaExperts,
    Any idea how to calculate an EMA for values stored in an unsynched array?
    I log values of interest (VOI), which can occur whenever, in an array. The VOI array is on purpose not synched to the primary series. Thus, if I have 100 bars in the primary, I might only have 15 values in the VOI array. I do not want to fill the "gaps" (85 bars) in the VOI array with nonsense values (either zero or a dummy copy of the respective last value until the next "real" value occurs).
    Until here, everything works exactly as expected. I can log data points as needed and correctly pull them again (e.g. VOI[14]), whenever I like to do so. .
    However, I also need to be able to calculate (custom) indicators on values of the VOI array for n occurrences. Easy for a SMA using "for loops" over desired length of index and divide the total by the index length, but how to access the items of the array if I really need each individual value of n for further calcs, like for an EMA?
    Direct access to the array is apparently not available. And I don't seem to be able to convert an array into a series either.
    Any hint how to solve the coding challenge (or to otherwise serve my needs laid out above) is greatly appreciated.
    https://ninjatrader.com/support/help...onential_e.htm
    Thx.
    NT-Roland

    #2
    Hi NT-Roland, thanks for your question.

    Any Series<T> object is going to have a slot index for every bar on the chart or underlying data series. You would need to use a custom List<T> to prevent a sparsely populated array, you can call List<t>.Add() to add a new item to the list. A moving average for this array would need to be calculated manually in a custom function since you would no longer be using the Series<T> and do not have a value for every bar.

    Best regards,
    -ChrisL


    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi ChrisL,
      Thanks for confirming that I'm not missing something obvious.
      I will continue with custom indicator calcs using "for loops" straight from the unsynched array or first convert n values of this array to a list and then work against that extract.
      Would be cool, if n items of lists/unsynched arrays could be exposed to indicator calcs straight away. I can imagine quite some use cases where you would want to calculate an indicator on just n occurrences of last valid data points rather than on each bar (with dummy values in between), but use the result of such indicator on your primary series.
      NT-Roland

      Comment


        #4
        Have you thought about creating a Series object to be used as a temporary
        data placeholder, like a middle-man dummy object, who's only purpose is
        to be used for the calculations made by an indicator?

        The trick is completely re-populating this dummy Series on the fly, with
        whatever array data you have, such as your VOI array.

        That is, when you want to perform calculations from a Indicator class
        on your VOI array, you first copy all VOI elements into the most recent
        positions of this dummy Series object -- you are effectively gutting
        the contents of the dummy Series object and completely reinstalling
        the values it holds -- but all this can be done with a few simple loops.

        Then use this dummy Series object as input to whatever indicator
        you're interested in.

        However ...

        If you're really only interested in one or two indicators, then I'd
        recommend you roll your own class that handles working directly
        with whatever data you give it. I made a CalcEMA class just for
        this purpose -- it kept it's own list of data values (naturally, I add
        items to the list with a Ninja-like 'Set' method) and the value of
        the EMA calculation was updated each time you added a new
        item to the list via Set.

        Comment


          #5
          Hi bltdavid,
          Excellent suggestion.
          I think, I will try the "dummy Series" override first because it would give me access to all indicators in one go.
          Thank you very much.
          NT-Roland

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by yodaler, Today, 06:12 PM
          0 responses
          5 views
          0 likes
          Last Post yodaler
          by yodaler
           
          Started by op1031, Today, 05:16 PM
          0 responses
          1 view
          0 likes
          Last Post op1031
          by op1031
           
          Started by fscabrera03, Today, 01:18 PM
          1 response
          12 views
          0 likes
          Last Post fscabrera03  
          Started by BottomShark77, Today, 12:20 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by bowling, Today, 06:16 AM
          3 responses
          30 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Working...
          X