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

Serializing an input series for use in parameters

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

    Serializing an input series for use in parameters

    I'm trying to solve a problem to get around a limitation (at least to my perception) that causes price Open, High, Low, and Close to be set all equal to Input when calling an indicator with an Input parameter.

    I need the Input data series specified by the user. This could be Median, Open, Typical, or other input series. BUT the indicator also needs access to the Open, High, Low, and Close series.

    So I thought I'd see if I could serialize the input series, something like this:
    Code:
    private IndicatorBase inputSeries = IndicatorBase.Close; // default setting for InputSeries
    
    [XmlIgnore()]
    [Description("Input data series")]
    [Category("Parameters")]
    [Gui.Design.DisplayName("InputSeries")]
    public IndicatorBase InputSeries {
    	get { return inputSeries; }
    	set { inputSeries = value; }
    }
    [Browsable(false)]
    public string InputSeriesSerialize {
    	get { return Gui.Design.Serializable____.ToString(inputSeries); }
    	set { return Gui.Design.Serializable____.FromString(inputSeries); }
    }
    I don't even know if this is serializable. What would I substitute for the ____ above?
    -Alex

    #2
    anachronist,

    If you host the indicator from within another indicator you should still have access to all the OHLC bars just fine.

    If you are running an indicator with Typical for instance that doesn't change the OHLC values of the data.

    I am not sure what scenario you are running into. Attached is an indicator that hosts another indicator. From the hosted indicator the OHLC is still accessible and accurate to what the underlying bars are.

    Code:
    7/1/2011 12:39:00 PM 1333.25 1333.5 1333.25 1333.25
    Hosted: 7/1/2011 12:39:00 PM 1333.25 1333.5 1333.25 1333.25
    7/1/2011 12:40:00 PM 1333.25 1333.75 1333.25 1333.75
    Hosted: 7/1/2011 12:40:00 PM 1333.25 1333.75 1333.25 1333.75
    You can see the OHLC print outs from both the host and the hosted are identical for the same timestamps.
    Attached Files
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by anachronist View Post
      I'm trying to solve a problem to get around a limitation (at least to my perception) that causes price Open, High, Low, and Close to be set all equal to Input when calling an indicator with an Input parameter.

      I need the Input data series specified by the user. This could be Median, Open, Typical, or other input series. BUT the indicator also needs access to the Open, High, Low, and Close series.

      So I thought I'd see if I could serialize the input series, something like this:
      Code:
      private IndicatorBase inputSeries = IndicatorBase.Close; // default setting for InputSeries
      
      [XmlIgnore()]
      [Description("Input data series")]
      [Category("Parameters")]
      [Gui.Design.DisplayName("InputSeries")]
      public IndicatorBase InputSeries {
      	get { return inputSeries; }
      	set { inputSeries = value; }
      }
      [Browsable(false)]
      public string InputSeriesSerialize {
      	get { return Gui.Design.Serializable____.ToString(inputSeries); }
      	set { return Gui.Design.Serializable____.FromString(inputSeries); }
      }
      I don't even know if this is serializable. What would I substitute for the ____ above?
      -Alex
      It looks like you are taking the hard road to something that NinjaTrader already provides. Just use the keyword: Input. So instead of Close[0], write Input[0]. That will take the user specifed PriceType, provided you set PriceTypeSupported to true in the Initialize() method.

      Comment


        #4
        Originally posted by koganam View Post
        It looks like you are taking the hard road to something that NinjaTrader already provides. Just use the keyword: Input. So instead of Close[0], write Input[0]. That will take the user specifed PriceType, provided you set PriceTypeSupported to true in the Initialize() method.
        I know that already. The problem I'm having is this: When I pass the output from one indicator to another indicator, I no longer have access to Open, High, Low, and Close. All those become equal to the values in the passed Input series.

        Josh, thanks for your reply and I apologize for not making my problem more clear.

        Say my code for Indicator2 includes this call:

        val = Indicator1(EMA(period), period);

        Indicator1 takes an IDataSeries and an integer as parameters. But Indicator1 also requires access to the price series High, Low, Open, Close as well as the IDataSeries output of EMA(). But when Indicator1 tries to access High, Low, Open, and Close, they are all the same values as Input[].

        This is easy to verify with Print(). Indicator1 prints the correct High and Low if I simply add it to a chart. But if I call it from within another indicator and pass some other data series to it, Indicator1 no longer has access to the prices.

        I need to do this without having to specify an instrument, like I'd have to do with a multi series indicator.

        I thought I could solve this by passing other data series into Indicator1 in the parameter list, but I can't figure out how to serialize it.

        -Alex
        Last edited by anachronist; 07-06-2011, 12:46 PM.

        Comment


          #5
          Alex,

          Correct. You will run into your experienced behavior in such an event. When you make the input series not of bars, but rather of another indicator like that it does not think you are using bars anymore and it is not running off of that anymore.

          To do what you want you should reprogram Indicator1 to just use the regular IDataSeries inputs and then have a parameter switch that you can use to determine if it will be using EMA, SMA, etc. That is the only way you will be able to have access to OHLC and some other chosen DataSeries of your liking.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            To do what you want you should reprogram Indicator1 to just use the regular IDataSeries inputs and then have a parameter switch that you can use to determine if it will be using EMA, SMA, etc. That is the only way you will be able to have access to OHLC and some other chosen DataSeries of your liking.
            Yes, that's what I've been doing, but it gets kind of ugly if there are too many variations. I thought it would be more elegant to be able to write Indicator1(EMA(period1),High,Low,period2) if only I could serialize those other DataSeries parameters.

            -Alex

            Comment


              #7
              Unfortunately that method is not supported.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by anachronist View Post
                Yes, that's what I've been doing, but it gets kind of ugly if there are too many variations. I thought it would be more elegant to be able to write Indicator1(EMA(period1),High,Low,period2) if only I could serialize those other DataSeries parameters.

                -Alex
                I am not sure that I understand. Are you trying to take the EMA of the Highs (for example), and use it as an input to the Indicator1?

                Comment


                  #9
                  Originally posted by koganam View Post
                  I am not sure that I understand. Are you trying to take the EMA of the Highs (for example), and use it as an input to the Indicator1?
                  Yes. I made up that example just to show that an indicator loses all access to the price data series if the output of another indicator is passed to it.

                  My real situation is more complicated, involving nested calls between a number of custom indicators, some of which need the output of other custom indicators as well as access to the price series. I just simplified the situation in this forum to clarify my problem.

                  -Alex

                  Comment


                    #10
                    Originally posted by anachronist View Post
                    Yes. I made up that example just to show that an indicator loses all access to the price data series if the output of another indicator is passed to it.

                    My real situation is more complicated, involving nested calls between a number of custom indicators, some of which need the output of other custom indicators as well as access to the price series. I just simplified the situation in this forum to clarify my problem.

                    -Alex
                    In the hope that an answer to your simplified scenario might point the way, here is how you will call an indicator with another indicator as input, using a specific price type.

                    Code:
                    val = Indicator1(EMA([COLOR="Red"][B]High[/B][/COLOR], period), period)[0];
                    IOW, you just need to pass the desired PriceDataSeries as your primary input to the called indicator.

                    Comment


                      #11
                      Originally posted by koganam View Post
                      In the hope that an answer to your simplified scenario might point the way, here is how you will call an indicator with another indicator as input, using a specific price type.

                      Code:
                      val = Indicator1(EMA([COLOR="Red"][B]High[/B][/COLOR], period), period)[0];
                      IOW, you just need to pass the desired PriceDataSeries as your primary input to the called indicator.
                      But Indicator1 would still not have access to both the High and Low price series, or any other price series. That's what happens when you pass a non-price series to an indicator.

                      Which brings us to my post that started this thread. I was trying to come up with a way to make an indicator that can take multiple series as input parameters. Then I could (using my example) pass the EMA output to it as well as whatever price series I need, as in

                      val = Indicator1(EMA(period), High, Low, Close, another_parameter, etc);

                      However, serialization of series parameters isn't supported, so I have to go by the route Josh suggested, and do this instead:

                      val = Indicator1(indicator_id, another_parameter, etc);

                      ...where indicator_id is some integer. Then indicator1 would call some other indicator internally (like EMA, RSI, StdDev, or whatever) depending on the value of indicator_id. By not actually passing a non-price series to Indicator1, Indicator1 can still access any of the price series that it needs.

                      -Alex
                      Last edited by anachronist; 07-06-2011, 05:11 PM.

                      Comment


                        #12
                        1. If PriceTypeSupported = true; then "Input" is always going to be one of the parameters of the indicator, so you can always access whatever the user specifies as primary input: OHLC.

                        2. If you want to call the indicator with multiple input types, then you have to write the called indicator to generate multiple outputs. So create 4 dataSeries, and populate them with the OHLC respectively; expose them as public; and you should be able to call them.

                        3. Alternatively, as PriceType is an NT primitive enum you can declare variables to be of the type that you want and use branching code to select what to do. (We do not really want to do this: it is definitely unsupported). However, that is the example that I show in the attached picture.
                        Attached Files
                        Last edited by koganam; 07-06-2011, 05:54 PM.

                        Comment


                          #13
                          Thank you for the help in improving my understanding. I think I've settled on a solution although your 'unsupported' option looks interesting.
                          -A

                          Comment


                            #14
                            Gentlemen,

                            As an alternative you could give this a shot.

                            For indicators using another indicator as the input series, to access the underlying Bars data try something like this:
                            Code:
                            BarsArray[0].GetClose(CurrentBar);
                            BarsArray[0].GetLow(CurrentBar);
                            The index of CurrentBar will get you the last bar processed in contrast to the [0] index you are familiar with for Close[0]. You would want to place this code in the "outside" indicator that is using the other indicator as the input, not the indicator being used.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks Josh, that's a good solution.
                              -A

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,604 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 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
                              13 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X