Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 Pass Data Series from Startegy to Indicator

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

    NT8 Pass Data Series from Startegy to Indicator

    I am developing a strategy which goes trough historical data
    primary data series is 1 minute base
    secondary data series is tick data

    In my strategy I have created 2 custom data series


    private Series<double> customLow;
    private Series<double> customHigh;


    how to pass those data series to an indicator

    it looks like an indicator accepts only one data series: input

    can you please post a sample on how to declare additional data series as parameter for indicator
    and how to call the indicator from strategy

    #2
    Hello astef,

    Thank you for your inquiry.

    "input" is just the name for that particular argument.

    You would be able to pass customLow or customHigh to the indicator as they are both type Series. For example, on an SMA indicator:
    Code:
    // Prints the current value of a 20 period SMA using customLow Series
    double value = SMA(customLow, 20)[0];
    Print("The current SMA value is " + value.ToString());
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hi Zac

      Thank you for your reply.

      My question is ho to pass BOTH data series to an indicator
      I want to build a custom indicator which needs two accept multiple data series as parameters, not just one data series.

      Can you please give me a sample on how to declare a more two different data series within an indicator, and how to expose it to a strategy.

      indicator:
      public class MyIndicator: Indicator
      {
      private Series<double> CustomLow;
      private Series<double> CustomHigh;

      ......

      #region Properties
      //[Browsable(false)]
      //[XmlIgnore]
      public Series<double> CustomLow
      { get; set; }

      //[Browsable(false)]
      //[XmlIgnore]
      public Series<double> CustomHigh
      { get; set; }


      [Range(0.00, double.MaxValue), NinjaScriptProperty]
      [Display(ResourceType = typeof(Custom.Resource), Name = "AccelerationLong", GroupName = "NinjaScriptParameters", Order = 0)]
      public double Param3
      { get; set; }


      how to expose the above two data series to a strategy?


      how to call miindicator from within a strategy:
      Strategy:

      private Series<double> CustomLow;
      private Series<double> CustomHigh;

      double indicatorvalue = MyIndicator(CustomLow, CustomHigh, parma3, param4...);

      Comment


        #4
        Hello astef,

        Thank you for your patience.

        After some further research, it looks like you will need to create your own custom constructor in your indicator in order to expose the Series to your strategy.

        As an example, I have attached a sample indicator here with a Series and a bool property. The Custom Constructor region in the sample I provided is where you would want to look at to see what was done.

        You'll see that it's similar to the NinjaScript generated code region.

        I will be submitting this as a bug report because it looks like the NinjaScriptProperty tag is not triggering the inclusion of the Series property in the constructors within the NinjaScript generated code region.

        Please, let us know if we may be of further assistance.
        Attached Files
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hi Zachary,

          I really appreciate the sample but without a code for strategy, I am unable to use it.

          how to call the indicator from within the strategy?
          how do I pass the parameters (last value of series) to the indicator?
          how do I call the indicator to retrieve calculated value?


          I would like to use this indicator for back testing from a strategy which uses two time frames
          primary 1 min and secondary 1 tick

          when I am in tick series, I want o pass last two values to the indicator, and launch the indicator calculation in the 1 muntue time frame

          my ind = ind(barindex[0],customlow, customhigh)[1];

          <- calling indicator from primary time frame barindex[0], passing low and high from current tick timeframe, trying to retrieve indicator value form the not yet fully formed current 1 min bar

          Comment


            #6
            Hello astef,

            Can you please clarify what you mean by passing the last value of a Series to the indicator?

            If you are only trying to pass a single element of a Series<double> (the last value of the Series, as you have specified) to the indicator, your indicator would need a double property to pass to.

            I have provided a sample script, with both an indicator and strategy, to demonstrate this. The indicator will do some calculations and the strategy prints the result of the calculation.
            Attached Files
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hi Zachary,

              Thank you for your sample.

              I want to call an indicator from my strategy and want to pass to the indicator two values (doubles).
              Those values are current bar high and current bar low.
              I want to make sure that the indicator uses those two values instead of Low[0] and High[0]

              Low[1], Low[2} etc should be just normal, but I need to overwrite the last bars values Low[0] and High[0]. I am doing this to calculate value of the indicator on bar opening and intra bar, when the last 1 minute bar is not yet fully completed.

              I am attaching a sample code, where I tried to use your suggestions.
              in one case I just pass the barLow and barhigh values and the indicator creates custom series
              in second case I am passing entire series of lows and highs to the indicator.

              unfortunately none of those calls to the indicators work as I am getting array out of range errors.
              I will upload a complete sample here

              Kindly please suggest how to call an indicator successfully
              I am calling indicator in 1 minute timeframe from Tick timeframe.
              Attached Files

              Comment


                #8
                Originally posted by astef View Post
                Hi Zachary,

                Thank you for your sample.

                I want to call an indicator from my strategy and want to pass to the indicator two values (doubles).
                Those values are current bar high and current bar low.
                I want to make sure that the indicator uses those two values instead of Low[0] and High[0]

                Low[1], Low[2} etc should be just normal, but I need to overwrite the last bars values Low[0] and High[0]. I am doing this to calculate value of the indicator on bar opening and intra bar, when the last 1 minute bar is not yet fully completed.

                I am attaching a sample code, where I tried to use your suggestions.
                in one case I just pass the barLow and barhigh values and the indicator creates custom series
                in second case I am passing entire series of lows and highs to the indicator.

                unfortunately none of those calls to the indicators work as I am getting array out of range errors.
                I will upload a complete sample here

                Kindly please suggest how to call an indicator successfully
                I am calling indicator in 1 minute timeframe from Tick timeframe.
                So what you are asking then that you want the indicator to be able to calculate intrabar, regardless the strategy calculation method?

                Why not just use proper OOP principles? That would translate to:
                1. Create a named instance of the indicator within the strategy.
                2. Change that instance's CalculateOnBarClose property to false.
                3. Call Update() on the indicator, or else set that COBC property every tick in the strategy if necessary.

                Comment


                  #9
                  Hello astef,

                  I see in the two indicators that you are calling from your strategy is assigning Value[0] to a specific value without a plot being created in the indicators.

                  You will need to add an AddPlot() method to both of the called indicator's State == State.SetDefaults statements in the OnStateChange() method.



                  I am currently investigating if this behavior is expected or is a bug as this does not replicate NT7's behavior.
                  Zachary G.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Zac

                    Still having troubles.

                    I added the plots, but that still does not work.
                    I call both indicators on each tick.
                    The second indicator receiving entire series is only running on each new bar, even that it is called on each tick....

                    the first one also gives me false results


                    Lets say this again.
                    I just want to call an indicator (parabolic Sar in particular, but in this example just anything) and execute it in 1 min timeframe, however I need to overwrite last bar OHLC in accordance to the last tick data received.

                    Is this really impossible to do that?
                    I am trying for 4 weeks

                    just call any indicator and overwrite last bar data?

                    Please help

                    Comment


                      #11
                      Hello astef,

                      It looks like you are passing the primary Series to your second indicator rather than the secondary tick Series. Please ensure that you are passing this secondary Series (BarsArray[1]) rather than the primary Series for the input.

                      I would suggest adding Print() method calls to your code so you can see why you may be getting inaccurate results. Please take a look at this particular post on our support forum detailing debugging in NinjaTrader 8: http://ninjatrader.com/support/forum...49&postcount=2

                      I have created a sample strategy that checks for the highest high (based on tick data) of the current bar, passes this value to an indicator when OnBarUpdate() is called for the primary Series, and resets the value back to 0 for the next iteration.
                      Attached Files
                      Zachary G.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Zac

                        Thank you for your comments

                        I do pass primary series as I want the indicator to calculate the value of indicator using primary series data. I only want to overwrite LAST bar from primary series.
                        I want the indicator to calculate the vale in 1 min timeframe not tick timeframe.

                        in your example you call MyIndicator(lastBarHigh);in primary time frame.
                        This is great but it will be called only on primary bar completion, not on each tick as the TickHigh changes? And I want to recalculate the indicator on each HighTick increase

                        and how do I construct the indicator to tell it to overwrite High[0] with TickHight? I only want to do the overwrite in the last bar. all previous bars should remain unchanged.
                        I can not achieve that. I do not know how to identify within the indicator that I am processing last bar; how to tell that I am in bar[0] and to use TickHigh instead of High[0]
                        Last edited by astef; 12-09-2015, 03:24 PM.

                        Comment


                          #13
                          Hello astef,

                          If you are passing the primary Series as the indicator's input, then the indicator's calculations will be based upon that Series' bar closing.

                          I have attached a sample strategy and indicator that demonstrates this. In the strategy, I add a tick Series and call the indicator on BarsInProgress == 1. You will see that despite that, the indicator will only ever output anything when the primary Series' bar closes as I pass in BarsArray[0] to the indicator's input argument. If you comment this out and un-comment the indicator call that passes BarsArray[1], you will see the indicator will output upon every new tick.

                          Can you please clarify what you mean by overwriting High[0] with TickHigh? Are you trying to access the tick Series' current high? You'd do this with Highs[1][0]: http://ninjatrader.com/support/helpG...-us/?highs.htm
                          Attached Files
                          Zachary G.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by koganam View Post
                            So what you are asking then that you want the indicator to be able to calculate intrabar, regardless the strategy calculation method?

                            Why not just use proper OOP principles? That would translate to:
                            1. Create a named instance of the indicator within the strategy.
                            2. Change that instance's CalculateOnBarClose property to false.
                            3. Call Update() on the indicator, or else set that COBC property every tick in the strategy if necessary.
                            thank you for your suggestion, but the intra-bar values are not exposed until the bar is completed; in fact in back testing, the fully completed bar is send before the underlying tik data for that bar, which causes all those problems that you need to code differently for live and back test scenarios

                            I honesty think that the ninja platform in this respect is very bad; how hard it would be for them to make a change that aspect in v8 and send the same bars in the same order in back testing like in live? let us access the higher time frame bar at any time and see uncompleted data for this bar?

                            Comment


                              #15
                              Originally posted by astef View Post
                              thank you for your suggestion, but the intra-bar values are not exposed until the bar is completed; in fact in back testing, the fully completed bar is send before the underlying tik data for that bar, which causes all those problems that you need to code differently for live and back test scenarios

                              I honesty think that the ninja platform in this respect is very bad; how hard it would be for them to make a change that aspect in v8 and send the same bars in the same order in back testing like in live? let us access the higher time frame bar at any time and see uncompleted data for this bar?
                              What is the COBC property value of your Strategy ?

                              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