No announcement yet.

Partner 728x90


Creating a Dataseries that looks like one created by "Add" but that I can modify

  • Filter
  • Time
  • Show
Clear All
new posts

    Creating a Dataseries that looks like one created by "Add" but that I can modify

    I am struggling with building a DataSeries (or something similar). I am looking for a way that I can build a dataseries that is similar to the Bars Object created when I call the "add" method, but that I can write to and read from. So far I've had no luck.

    Basically I'm trying to create a "custom dataseries" that contains open, high, low, close etc in its array, then use it by passing it to something like Stochastic() which uses the open, high, low and close. I can create a Bars Object using 'Add' but then I can't write anything to it. Is there a way to create a Bars Object that looks just like the one created by "Add" but that I can manipulate myself?

    I'd apprecate it if anyone could point me in the right direction.


    Hi Steve, have you checked already into the ideas discussed here? -
    BertrandNinjaTrader Customer Service


      I have had a read through the link. Thanks for the info. I think that information is possibly along the lines of what I am trying to do, however I thought there would be an easy way to create a Bars Array or DataSeries that looks and behaves identical to the one created by the Add() method so that I could read/write to it. Do you have any sample code of a read/write Bars Array?


        Hi Steve, unfortunately this beyond the level of support we provide, but please check post 3 from this thread here, is this what you had in mind?

        Otherwise, I would suggest reading up about Arrays in C# on MSDN and using this then.
        BertrandNinjaTrader Customer Service


          Hi Bertrand,
          Yes that is along the lines of what I was looking to do. Thanks ... however ...

          How can I then pass that data to a function/indicator such as Stochastic which needs more than just the close price of the array. When calling the Stochastic function, I pass the BarsArray. If I've created my own array, how can I pass this to the function ?



            Stochastics looks for DataSeries objects so you would need to parse the relevant information into a DataSeries. Or you could just skip the array altogether and just start off making multiple DataSeries objects.
            Josh P.NinjaTrader Customer Service


              Thanks Josh,
              I think we might be getting somewhere now. How do I make a DataSeries that contains OHLC data that I can pass to the Stochastics function? I haven't yet found a way to make a DataSeries that I can load this information into, then get the Stochastics function to pull it using Open[0], Close[0] etc

              If you have a bit of sample code it would be aprreciated.



                Unless I'm missing something about what you're looking for, OHLC data is already a DataSeries. You would simply call the stochachastic function like this.

                Stochastics(Open, PeriodD, PeriodK, Smooth);

                or Plot0.Set(Stochastics(High, 7, 14, 3)[0]);

                or something similar.

                BTW, if you have
                PriceTypeSupported =
                then you could use Stochastics(Input, 7, 14, 3);
                and select the Input DataSeries at run time.

                Hope this helps.
                Last edited by VTtrader; 07-21-2009, 09:54 PM.


                  Thanks VT - Steve, did you check already into this link for the DataSeries class explanation?

                  As VT noted, Stochastics accepts this directly as input.
                  BertrandNinjaTrader Customer Service


                    Hi VT and Bertrand,
                    Thanks for the pointer VT. I follow what your saying. OHLC is already a DataSeries, HOWEVER ... and this is the big However that always walks me into a solid wall. I want to create a DataSeries myself and then populate it with my own OHLC data. Basically I want to be able to "modify" the OHLC data before I write it to my own DataSeries.
                    What I write into my new DataSeries isn't going to be the same data as the OHLC data I get from my Add() DataSeries/BarsArray.

                    I look at the example code given in the below DataSeries Class definition in help:

                    protected override void OnBarUpdate()
                    // Calculate the range of the current bar and set the value
                    myDataSeries.Set(High[0] - Low[0]);
                    // Print the current 10 period SMA of range
                    Print("Value is " + SMA(myDataSeries, 10)[0]);

                    I can pass a DataSeries to SMA and it will handle it, HOWEVER SMA only needs one parameter, so will suffice with a single dimension array. How would I pass a custom made DataSeries to a function such as Stochastics which requires the LOW, HIGH and CLOSE values for a particular bar?

                    So I guess my asking is:
                    1) How do I create a multidimensional DataSeries, so that I can contain custom values of OHLC for each bar?
                    2) If I can't do 1) then how do I pass 4xDataSeries to a function such as Stochastics and not have to rewrite Stochastics to handle 4x individual DataSeries?

                    I am sorry if I'm not coming across clearly here, I am just having alot of trouble trying to do something that I believed should have been easy ... which was to make my own BarsArray (which I believe is only a collection of DataSeries) which I could then pass to an indicator function.

                    I am trying to create a DataSeries "myDataSeries" then load it with values
                    myDataSeries.Open.Set = 123;
                    myDataSeries.High.Set = 175;
                    myDataSeries.Low.Set = 100;
                    myDataSeries.Close.Set = 150;

                    then pass it to an indicator function

                    Stochastics(myDataSeries, 7, 14, 3);

                    Where the function Stochastics will extract the Low, High and Close values. Question is how do I load the Open, High, Low and Close into myDataSeries???

                    Kind Regards
                    Last edited by OzSteve; 07-22-2009, 07:38 PM.


                      Stochastics of price uses the Low and High over the lookback period but only because it is looking for the lowest low and the highest high price. In other words, since "Close" is only one part of a bar it will never give you the highest or lowest price something traded over the lookback period. If you're looking for the "stochastic" of something other than price (such as an indicator or your myDataSeries), you'll need to rewrite the Stochastic function (or use it inline) to use the Lowest Low and Highest High values of your myDataSeries over the lookback period. Then the stochastic calculation can be done on just one dataseries.

                      For example the built in NT Stochastics function would need to be modified to something like this:

                      protectedoverridevoid OnBarUpdate()
                      0] - MIN(myDataSeries, PeriodK)[0]);
                      den.Set(MAX(myDataSeries, PeriodK)[
                      0] - MIN(myDataSeries, PeriodK)[0]); // PeriodK = Kperiod

                      100 * SUM(nom, Smooth)[0] / (SUM(den, Smooth)[0] == 0 ? 1.0 : SUM(den, Smooth)[0])); // Smooth = SlowKperiod
                      D.Set(SMA(K, PeriodD)[0]); // PeriodD = SlowDperiod

                      Hope this helps,
                      Last edited by VTtrader; 07-22-2009, 10:58 PM.


                        Hi Steve,
                        I didn't think I was very clear (also read your link on the other thread). A couple of things comes to mind.
                        First, the way you talk about creating your own BarsArray so you could pass it to a Stochastics call. Even if it were possible, it wouldn't keep you from having to rewrite the Stochastics function to work with your own BarsArray, since you couldn't have different arrays called Close[0].
                        Second, generally an indicator has a value for each bar but isn't often used (or needed) to know it's OHLC value intrabar. While this is possible, any result would not prevent the need to write custom functions for any usage of the data, regardless of how the arrays were built.
                        For your example above, using Stochastics, it is actually a very simple modification and you could even use the calculation inline instead of a function call. I went ahead and modified the NT Stochastics indicator so that it works on a single DataSeries or Indicator as input.

                        To use it:
                        Define your DataSeries

                        And call the function
                        Plot0.Set(StochInd(myDataSeries, 7, 14, 3)[0]);
                        That will return %K value by default

                        Alternatively you can call it like this
                        Plot1.Set(StochInd(myDataSeries, 7, 14, 3).K[0]);
                        Plot2.Set(StochInd(myDataSeries, 7, 14, 3).D[0]);
                        The later will return %D value

                        Hope this helps,

                        Attached Files
                        Last edited by VTtrader; 07-23-2009, 08:47 PM.


                          Steve, then you either need to work with a custom Stochastic method and a multidimensional array -

                          Or you work with separate DataSeries objects for the OHLC info.
                          BertrandNinjaTrader Customer Service


                            Thanks Bertrand and VT,
                            I really appreciate your assistance. I'm going to take the information you've given me and try to work it and experiment a little. Then depending how far I get I might have to get back to you again.

                            Thanks for your help.

                            Kind Regards


                            Latest Posts


                            Topics Statistics Last Post
                            Started by toughiee, Today, 12:04 AM
                            0 responses
                            Last Post toughiee  
                            Started by vdoan20, Yesterday, 08:30 PM
                            0 responses
                            Last Post vdoan20
                            by vdoan20
                            Started by gupagoer, Yesterday, 07:42 PM
                            0 responses
                            Last Post gupagoer  
                            Started by Holligoly, Yesterday, 05:13 PM
                            2 responses
                            Last Post Holligoly  
                            Started by Raginpower, Yesterday, 01:53 PM
                            0 responses
                            Last Post Raginpower