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

Parsing variables from one indicator to another

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

    Parsing variables from one indicator to another

    All,

    I've managed to boggle my brain on this one. I've an indicator that has four integer variables I wish to access from another indicator (both of which on the same bar object). When these these integer values are accessed by the other indicator, it appears they are transformed into doubles. This transformation means I can not use the values against other integers (i.e. CurrentBar).

    I attempted to follow the example of Mike below from a 31 May 2009 post (below) but on reflection I don't think it will solve my problem. How do I parse variables from one indicator to another?

    As always any assistance would be appreciated.
    Shannon


    Originally posted by ctrlbrk View Post
    Velocity,

    If your intention is to have a DataSeries that is accessible for a strategy or other indicator (Signal -1: short, Signal 1: long), then you can do it without a Plot. Just do:

    #variables
    private DataSeries signal;

    #init
    signal = new DataSeries(this);

    #onbarupdate
    Signal.Set(1); // long
    Signal.Set(-1); // short

    #parms
    public DataSeries Signal
    {
    get { return signal; }
    }


    Alternatively, you can do as Ray suggests and set auto scale to false, it will solve the problem as well.

    Mike

    #2
    Shannon, in your script I assume you're working with exposing a standard DataSeries holding doubles so this would be expected - please try this with the IntSeries - http://www.ninjatrader-support.com/H...riesClass.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      Thanks for the quick reply.

      This will no doubt show me as a novice programmer, but how exactly do I access these IntSeries in another indicator? Is the indicator that sets the IntSeries "Added" to another indicator in the initialisation section, thus adding the IntSeries as well?

      Thanks again
      Shannon

      Comment


        #4
        Shannon , you're welcome - should have added this link here for a sample - http://www.ninjatrader-support2.com/...ead.php?t=4991
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand,

          I've implemented the IntSeries structure without a hitch. As mentioned in the first post, I need to access integer variables from one indicator in another indicator. This meant the public IntSeries ICurrentPeak was set as CurrentPeak (an integer -> a prior CurrentBar marker) as opposed to the private IntSeries iCurrentPeak as per the "SampleBoolSeries" example. The IntSeries ICurrentPeak is set on each bar update event.

          I've tested this implementation via Print and the Output window all seems to work well. Though I did not implement the "exposed variable" section of the "SampleBoolSeries" example code (I'm not 100% across its need in this situation).

          I've hit a wall in accessing the IntSeries information in another indicator. The "SampleBoolSeries" example accesses the BoolSeries in a strategy using the Add() command. Attempting to add the indicator to another indicator usingn the Add() command results in two errors:
          1) The best overloaded method match for 'NinjaTrader.Data.DataSeries.Set(double)' has some
          invalid arguments , and
          2) Argument '1': cannot convert from 'string' to 'double'.

          Testing, I attempted to "Add(MACD(12,26,9));" as in the "SampleBoolSeries" example. The same errors present. Any ideas?

          As always, thanks
          Shannon

          Comment


            #6
            Shannon, you can't ADD() the MACD in the indicator as this is not supported for indicators in NinjaTrader 6.5

            You wouldn't need the exposed variable if you work with dataseries classes like the Int one (those are synched automatically to provide up to date values), just make sure those are public in the properties section of the indicator you wish to access them from.

            Then call them like the sample call provided in the SampleBoolSeriesStrategy -
            Code:
             
            if (SampleBoolSeries().BullIndication[0])
            { do your thing}
            Of course this would need to be adapted to -

            a) your indicator name exposing those Int series values
            b) the Int series name you've chosen in your indicator
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Bertrand,

              Thanks a bunch, that worked a charm. I tip my hat to you for a very clear explanation!

              As a follow on question, as the four IntSeries are called into the indicator separately, is the indicator which calculates the IntSeries (aka. base indicator) run four times for each bar update? Or is the base indicator run the once with all four IntSeries called from the one run?

              In the event the four calls result in the base indicator run four times, is it possible to do this more efficiently?

              As always, thanks
              Shannon

              Comment


                #8
                Shannon,

                There will be one instance of the base indicator provided the base indicator is called with the same parameters.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  NT Team,

                  Following on from the below thread, I managed to parse flagged bars (i.e. integers) from one indicator to another indicator using IntSeries. This was used where one indicator flagged particular bars, and another indicator referenced this information (e.g. High[CurrentBar-flaggedBar]). Both indicators were on the same chart (e.i. same time period, same instrument)

                  This approach does not work when the indicator used to flag bars is run on a different chart to the indicator which references the flaggedBar in terms of time period and/or instrument (e.g. cash vs. futures). This is logical as the "CurrentBar" is based on the primary BarSeries while the flaggedBar integer is based on a different BarSeries. The subtraction, as above, results in an inappropriate bar being referenced.

                  Is there some way an appropriate bar reference could be established?
                  As always, any suggestions would be appreciated.

                  Regards
                  Shannon
                  Last edited by Shansen; 08-13-2009, 05:48 AM.

                  Comment


                    #10
                    Shannon, multiseries indicators will be supported in NinjaTrader 7. For now you would have to work in a multitime / instrument strategy for this in NinjaTrader 6.5 -



                    To sync dataseries objects to other timeframes for the strategy, please check into this sample here - http://www.ninjatrader-support2.com/...ead.php?t=3572
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Bertrand,

                      Please confirm the below script would result in the BarArray[1] being out of sync with BarArray[0]. Also, is there any logical reason the "Math.Max" formula would return a number that was neither the first or second element in the function? Yes, I have used the Output window to test this area.

                      Thanks
                      Shannon
                      protected override void Initialize()
                      {
                      // BARS OBJECT 0 - The chart the strategy was applied to.
                      // BARS OBJECT 1 - Longer-term Bars object
                      Add(PeriodType.Minute,60);

                      CalculateOnBarClose = false;
                      }

                      protected override void OnBarUpdate()
                      {
                      if (BarsInProgress != 0)
                      return;

                      dBreakoutLevel = Math.Max(SMA(BarsArray[1],10)[0], SMA(BarsArray[1],5)[0]);

                      Print ("dBreakoutLevel = " + dBreakoutLevel);
                      }
                      Last edited by Shansen; 09-07-2009, 05:15 AM.

                      Comment


                        #12
                        Hi Shannon, no since those are no custom data series objects you use.

                        For Math.Max - did you also 'print' the SMA values you inputted into it?
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Bertrand,

                          Thanks for the reply.

                          On the Math.Max query, it would appear I was simply looking at the code to long. With a fresh brain, the error was plain to see, and the error was mine. Thanks


                          Apologies for asking the synchronisation question rather backwards. To clarify your response, are you saying the primary bars object and secondary bars object would be synchronised or not?

                          I have a custom indicator that is referenced from a strategy. Logically, the indicator can operate on other chart timeframes and chart instruments. The custom indicator has six public IntSeries and six public DataSeries to parse information from the indicator to the strategy for evaluation. While operating in a live environment (simulation account) all appears to be working well, i.e. the strategy appears to be referencing the correct information from the custom indicator.

                          However, I’ve imported data for the ^SP500 & corresponding ES contracts for the calendar year 2008. When charts are loaded based on this data, the global crosshairs points to the appropriate data in the ^SP500 and ES instruments as expected. When the strategy is run on this historical data the information referenced from the customer indicator via the public IntSeries and DataSeries appears to be incorrect, out of sync.

                          Any ideas? (Given my mix-up on the Math.Max query it is possible I am missing something)

                          As always, thanks
                          Shannon

                          Comment


                            #14
                            Shannon, great the Math.Max is resolved - if you use custom dataseries objects in a strategy you would need to synch them as per this example - http://www.ninjatrader-support2.com/...ead.php?t=3572

                            Also, please check into the referenced indicator and delete any CalculateOnBarClose reference you may have set in the Initialize() of it. Then just set this property in the calling strategy.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Bertrand,

                              Thanks for the response. Especially the pickup on CalculateOnBarClose references in indicators called from a strategy.

                              That leads to another question. The strategy in question is programmed to run only in the last 3 seconds of each bar (e.g. 1min) on an ES futures contract.
                              // Only process in the last 3 seconds of each bar
                              TimeSpan barTimeLeft = Bars.Get(Bars.Count - 1).Time.Subtract(DateTime.Now);
                              if (!(barTimeLeft.Seconds <= 3))
                              return;
                              However one of the called indicators which defines significant peaks / troughs in recent history should really be run at the end of each bar to ensure the actual high / low of a bar is used in defining and retaining peaks / troughs, and no duplications occur.

                              What methods would you suggest to effect this? At first glance, analysis could be conducted from the perspective of one bar ago (e.g. High[1]) as opposed to the current bar. However, I believe there would be significant complications in this approach.

                              I have not yet given thought to the situation where a bar update event does not occur in the last three seconds of a bar and it’s effect on the called indicator.

                              Regards
                              Shannon

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X