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

Problem - passing Series values into DEMA indicator

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

    Problem - passing Series values into DEMA indicator

    Hello,

    I have indicator which calculates values into variable:
    private Series<double>BuysDataSeries;

    I want to calculate DEMA from this series:
    ASK_DEMAobj = DEMA(BuysDataSeries, iASK_DemaPeroid);

    But I always get value:
    Print("ASK_DEMAobj: " + ASK_DEMAobj.Value[0]); // = 0;

    What am I doing wrong?

    I also provide indicator code in attachment (Add it to price panel). Can someone give me hint?

    Thanks a lot
    Pavel
    Attached Files

    #2
    Hello kujista,

    I took a look at the script and also see 0's. I quickly tried a couple of prints, first on the series:

    Code:
    Print("Series value: " + BuysDataSeries[0]);
    I see 0's so the value of the indicator should also be 0. I tried another test of just setting a value to the plot:

    Code:
    BuysDataSeries[0] = Close[0];
    if (ASK_DEMAobj != null) {
        ASK_DEMAobj.Update();
       Print("Series value: " + BuysDataSeries[0]);
       Print("ASK_DEMAobj: " + ASK_DEMAobj.Value[0]);
    }
    In this case I can see the indicator working, so that lets me know the general usage you have seems to be working. I would suggest taking a look at how you are setting values to the series being supplied to the indicators.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I found out, that when I add
      Print("ASK_DEMAobj: " + ASK_DEMAobj.Value[0]);
      into OnBarUpdate - it writes a value,

      But when called in OnRender.. it always shows 0's...

      When I want to get value from BuysDataSeries I have to use code below:

      double _buys = BuysDataSeries.GetValueAt(barIndex);

      Couldnt this be problem that indicator calculates wrong values?

      I am hopeless :-/

      Comment


        #4
        Hello kujista,

        That would be expected, OnRender is not like OnBarUpdate where you can access data with BarsAgo. You need to use the GetValueAt methods to retrieve data by its index when using OnRender. If your indicator uses both OnBarUpdate and OnRender to access the same data, you would have two separate sets of logic to access that data, one by indexes and the other by bars ago. OnRender is a render pass so this is not intended to reference a specific bar or place in time like OnBarUpdate, just the currently visible area.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you, I managed to realize it outside OnRender.

          But now i need to calculate DEMA which will not have list of values in time, but it will be list of numbers (first column) on screen: http://prntscr.com/p1dkmx
          Is there a way to pass list of values in first column to calculate DEMA for each row. When i set DemaPeriod to 5, first 5 rows will not have DEMA values. But 6th,7th etc.. should have calculated value from numbers.

          Could please help me how to store numbers to be able to calculate DEMA values for each row?

          Thanks a lot

          Pavel

          Comment


            #6
            Hello kujista,

            If the data you are referring to is in a Series<T> you could pass it to the DEMA for calculation, however if that is not in Series format you would likely need to manually calculate the DEMA from your dataset using the same equation. If you manually calculate the value that would essentially require recreating both the DEMA and EMA as equations.

            How is the data currently stored in your script prior to rendering it?

            I look forward to being of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello,

              If you look on this picture: http://prntscr.com/p1dkmx. There are 1st and 2nd column of numbers (ASK Volume, BID Volume). I store these values into List of PriceZoneRecord objects.
              See:
              public class PriceZoneRecord {
              public int buys; // = ASK Volume
              public int sells; // = BID Volume
              }

              Number of items equals to rows in the screen.

              I need advice, how to:
              1) Store values to some object named listOfBids (can it be Series<T>?) to use them as DEMA Input
              2) How to calculate DEMA with this input values.
              e.g.
              I have 60 rows (on chart), I use demaPeriod = 7
              So i need something like this
              for (int i=7;i< listOfBids.count();i++) {
              demaBIDValue = DEMA(listOfBids, demaPeriod)[i]; // ? How is it possible to calculate DEMA starting "bars ago"?
              }

              Is it clear what i need?

              Thanks a lot for help

              Pavel Kujal

              Comment


                #8
                Hello kujista,

                1) Store values to some object named listOfBids (can it be Series<T>?) to use them as DEMA Input
                2) How to calculate DEMA with this input values.
                For both of your questions this is going to relate to how the indicator works. The DEMA is expecting a series of doubles which is not the format you have here.

                If you wanted to create a series that contains the lists you can do that, however the indicators will not know what to do with that data because it is expecting a series of doubles.
                Code:
                private Series<List<PriceZoneRecord>> myCustomSeries;
                myCustomSeries = new Series<List<PriceZoneRecord>>(this, MaximumBarsLookBack.Infinite);
                For this goal you would likely need to manually calculate the DEMA by just doing the math and using logic in your script. Your data is in a list which is not going to match the indicators expectation of a series<double>. The indicator would not know what to do with that data and could not process it. You could instead make a method to calculate the DEMA by using math in your script and then pass the List of values to that method. The calculation of the DEMA is fairly simple although it does require the EMA so you would need to replicate both the EMA syntax and DEMA syntax.

                Using a loop like you have shown would be needed however you wouldn't call the indicator in the loop, you would just do the math there.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Brevo, Today, 01:45 AM
                0 responses
                2 views
                0 likes
                Last Post Brevo
                by Brevo
                 
                Started by aussugardefender, Today, 01:07 AM
                0 responses
                3 views
                0 likes
                Last Post aussugardefender  
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                238 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                384 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Started by oviejo, Today, 12:28 AM
                0 responses
                4 views
                0 likes
                Last Post oviejo
                by oviejo
                 
                Working...
                X