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

DM - Directional Movement

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

    DM - Directional Movement

    I am trying to assign a secondary timeframe to a dataseries with:
    if(dsDMP2 == null) dsDMP2 = new DataSeries(DM(BarsArray[1],period2).DiPlus);
    and I get a CS1502 and a NT1503 error.

    If I leave off the ".DiPlus" it works OK.
    (1) Why doesn't this work? Isn't the DiPlus a series?

    (2) Will any formula work in order to assign BarsArray[1] to a dataseries even though I may use a different formula in the ".Set" command? i.e. Use an SMA in the "new" but use ADX in the "Set".

    Thanks

    #2
    Romulan,

    DiPlus is a data series.

    The DataSeries initialize method expects a "IndicatorBase" object, however there are 5 other overrides for it. Its recommended to initialize dataseries as follows :

    dsDMP2 = new DataSeries(this);

    I would suggest typing the above out to the ( in the editor, then you can use intellisense to check for what this object expects as inputs.

    I believe you are trying to do this? http://www.ninjatrader.com/support/f...ead.php?t=3572

    Please let me know if I may assist further.
    Last edited by NinjaTrader_AdamP; 01-31-2012, 08:34 AM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      If I understand multi-timeframe correctly, according to the Help regarding multi-timeframe and a secondary series the proper way to initialize a DataSeries is how I described in my initial statment. The "new(this)" attaches the primary instrument.

      Am I wrong on this?

      I also need an answer to (2).

      Comment


        #4
        Romulan,

        To add a second instrument or time frame you need to use the Add() method. The "this" attaches an IndicatorBase object. The DataSeries needs to know how large to be, so it inherits the "MaximumBarsLookBack" and "MinimumBarsLookBack" values.

        Will any formula work in order to assign BarsArray[1] to a dataseries even though I may use a different formula in the ".Set" command? i.e. Use an SMA in the "new" but use ADX in the "Set".
        I am not sure I understand. If you want to synchronize dataseries, then please view that link I provided in my previous post. If you could clarify I would be happy to comment further.

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          I appoligize for not explaining myself correctly so let me start over. I hope I explain everything this time.

          BACKGROUND
          I have a multi-timeframe indicator with a 1 minute timeframe (primary), a 3 minute timeframe (seconday) and a 5 minute timeframe (secondary). The calculations are done tick by tick so CalculateOnBarClose = false; I use the ADX, DiPus and DiMinus for each timeframe and determine if each one for each timeframe is rising, falling, etc. Instead of calling the indicator several times I wanted to use a DataSeries, call the indicator once and set the values in the dataseries and test it several times. I thought this would be faster.

          The indicator compiles and appears to run correctly. However, if I compare the results for the 3 minute and 5 minute (secondaries) to charts for a 3 minute and 5 minute that have the DM indicator on it, they do not match at times - sometimes they do, sometimes they don't. This makes me think that I may be doing something wrong with the data series objects, hence my questions.

          CODING
          My primary input is a 1 minute NQ. The seconday NQ 3 and 5 minutes are added in the initialize with:
          // ADD SECOND TIMEFRAME
          Add(PeriodType.Minute, interval2); <= 3 minute
          // ADD THIRD TIMEFRAME
          Add(PeriodType.Minute, interval3); <= 5 minute

          Here is a snipit from the SampleDataSeries.zip example explain dataseries & multi-timeframe:
          if (secondarySeries == null)
          {
          /* Syncs another DataSeries object to the secondary bar object.
          We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
          The indicator can be any indicator. The DataSeries will be synced to whatever the
          BarsArray[] is provided.*/
          secondarySeries = new DataSeries(SMA(BarsArray[1], 50));
          }

          According to the above snippet a DataSeries object for the PRIMARY ONLY is created with "new(this)" in the Initialize event with:
          dsADX1 = new DataSeries(this);
          dsDMP1 = new DataSeries(this);
          dsDMM1 = new DataSeries(this);

          According to the above snippet a DataSeries object FOR SECONDARY has to be synchronized with the secondary bar object with the "new(BarsArray[n],x)" statement using the BarsArray[] object for the secondary instead of "new(this)". This I do in the OnBarUpdate with:
          (Note that this will only be done once.)
          if(dsADX2 == null) dsADX2 = new DataSeries(DM(BarsArray[1],period2)); <= Note the BarsArray[1] indicating secondary
          if(dsDMP2 == null) dsDMP2 = new DataSeries(DM(BarsArray[1],period2).DiPlus); <= this code fails
          if(dsDMM2 == null) dsDMM2 = new DataSeries(DM(BarsArray[1],period2).DiMinus); <= this code fails
          However, the calls to DiPlus and DiMinus failed with CS1502 and NT1503.
          I could not understand why I was getting these errors so I used the following calls instead:
          if(dsADX2 == null) dsADX2 = new DataSeries(DM(BarsArray[1],period2));
          if(dsDMP2 == null) dsDMP2 = new DataSeries(DM(BarsArray[1],period2)); <= this code compiles
          if(dsDMM2 == null) dsDMM2 = new DataSeries(DM(BarsArray[1],period2)); <= this code compiles

          Later in the OnBarUpdate event I set the data series with:
          if (BarsInProgress == 1)
          {
          dsADX2.Set(DM(BarsArray[1],period2)[0]);
          dsDMP2.Set(DM(BarsArray[1],period2).DiPlus[0]);
          dsDMM2.Set(DM(BarsArray[1],period2).DiMinus[0]);
          }

          My indicator now compiles correctly with no errors. However, some of the results I get from this indicator do not match with the charts for a 3 minute and/or 5 minute with the DM indicator.

          QUESTIONS. And these concern the DataSeries Synchronized with the secondary inputs.
          (Q1) Why does call to DM() work but the call to DM().DiPlus fail with errors CS1502 and NT1503:
          if(dsDMP2 == null) dsDMP2 = new DataSeries(DM(BarsArray[1],period2).DiPlus); <= this fails

          (Q2) Note that I had to use one formula in the "new" but a different one in the ".Set" to get it to compile:
          if(dsDMP2 == null) dsDMP2 = new DataSeries(DM(BarsArray[1],period2)); <== had to use DM() because DM().DiPlus failed here
          if(dsDMM2 == null) dsDMM2 = new DataSeries(DM(BarsArray[1],period2));
          if (BarsInProgress == 1)
          {
          dsADX2.Set(DM(BarsArray[1],period2)[0]);
          dsDMP2.Set(DM(BarsArray[1],period2).DiPlus[0]); <= the .Set" uses DM().DiPlus while I had to use "DM() in the "new"
          dsDMM2.Set(DM(BarsArray[1],period2).DiMinus[0]);
          }
          Does this make a difference??? Is this affecting my results?? Or do I have to use the EXACT same formula in both??? Is the important thing that I use the correct BarsArray[n] and the formulas are immaterial??

          And another new question.
          (Q3) Since the indicater uses tick by tick does that mean that "if (BarsInProgress == 0)" and "if (BarsInProgress == 1)" and "if (BarsInProgress == 2)" will be true for each incoming tick and executed for each incoming tick??

          Thanks

          Comment


            #6
            Romulan,

            DM().DiPlus is a dataseries, whereas the constructor of the DataSeries object expects an IndicatorBase object. I.e. there is no way to initialize a DataSeries with another DataSeries as input.

            You will want to use BarsInProgress to filter each time frame's call of OnBarUpdate, and use it to synchronize the data series. I see you are using BarsInProgress == 1, are you also using it for 0 and 2 since you added 2 time frames?

            It looks like you are using the .Set methods correctly.

            BarsInProgress == 0 will only be true if the primary data series is being updated, BarsInProgress == 2 will only be true if the second data series is being updated, etc. even in calculate on bar close = false strategies it is recommended to filter using these since you want to make sure that the data series that is calling the OnBarUpdate method is updated before synchronizing to the new dataseries.
            Adam P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            7 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            4 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            12 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            13 views
            0 likes
            Last Post bltdavid  
            Working...
            X