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

Transforming an indicator into a strategy by killing graphics, redefining arrays

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

    Transforming an indicator into a strategy by killing graphics, redefining arrays

    I developed a strategy from an indicator which defined a <double> series down in the properties region, like below, but only as a means (obviously) to return the array to the chart via an AddPlot() function:

    #region Properties
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> myRSI
    {
    get { return Values[0]; }
    }

    The problem with using the internals of an indicator for a strategy is that the Addplot()'s must be used with *all* the "return Value[0]", "return Value[1]", "return Value[2]",..., "return Value[n]" for all the indicator array data that's fed to the chart for drawing via the AddPlot() functions.

    The goal, however, for the strategy is to kill all the drawing of the indicator array data on the chart (this is a strategy), and only show the default NT8 Execution order information for trades (#shares, magenta and blue arrows for longs and shorts) on the price panel to which the strategy was added.

    So as an attempt to kill the drawing of the arrays on the chart, I tried moving the double array early on in the class, i.e.:

    public class myStrat : Strategy
    {
    private Series<double> myRSI;

    and then commented out the AddPlot and all the code shown below:

    // [Browsable(false)]
    // [XmlIgnore]
    // public Series<double> myRSI
    // {
    // get { return Values[0]; }
    // }

    But the compiler goes bonkers over this.

    Overall, the strategy is correctly posting Executions with the NT8 default long and short #shares and arrows, but I can't seem to kill the AddPlot() functions, the Value[0] returns which send the indicator arrays to the chart, and redefine the <double> series e.g. myRSI somewhere else without a compile error.

    FYI - the SampleMACrossOver strategy has no AddPlot or Value[0] returns in the properties, so how can I move a <double> series defined in the #region Properties up into the class, and then kill the indicator graphics?
    Last edited by pel11; 06-19-2018, 09:39 AM.

    #2
    Hello pel11,

    Thank you for your note.

    I've attached a sample strategy and indicator which demonstrates how this can be done. You would want to reference the GapUpPresentSeries and GapDownPresentSeries within the indicator and how that's referenced in the strategy.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks very nice! RESOLVED

      FYI - in your strategy, if you comment out the two Value returns at the bottom of OnBarUpdate:

      //Values[0][0] =GapIndicatorVar.GapDownPresentSeries[0];
      //Values[1][0] =GapIndicatorVar.GapUpPresentSeries[0];

      the results won't population the price panel with the vectors whose range is [0,1], which force the lower bound of the price panel to be zero. With these commands commented out, the range of price is set by the min and max price bars visible in the chart -- much better and more typical.
      Last edited by pel11; 06-19-2018, 06:32 PM.

      Comment


        #4
        Hello pel11,

        Glad to hear it was resolved.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Just learned that very rarely, my custom indicator will yield a signal value that's out of range. Therefore, in the OBU of the custom indicator I will need to:
          1. change the value of an input parameter, and then rerun all the bars based on the new parameter value. (Can't I just trap out the error inside OBU, change the param value, and then "goto" before the OBU?)
          2. make sure the new parameter value gets drawn in the param values in the chart's indicator display
          3. return the new parameter value to the strategy so that it know the parameter value that was sent to the indicator is now different for this iteration of optimization.

          I successfully can call the custom indicator with param values from the strategy, so what must be done to sync everything if I need to change a sent param value inside the indicator.
          Last edited by pel11; 06-25-2018, 12:55 PM.

          Comment


            #6
            Hello pel11,

            You could use a Try Catch in OnBarUpdate.

            I put together a sample. Strategy will call indicator and pass it a value of 4, which indicator will use to try and print the close from 4 bars ago. On Current Bar 2, this will be caught by the Try/Catch, and the variable of 4 will then be changed to 1, which will not get a Index error. This variable is then set to a plot, which the strategy can reference.

            I believe this would satisfy all your needs.

            Please let us know if you need further assistance.
            Attached Files
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              What you showed is for ensuring the revised signal value makes it to the chart and the strategy. Recall, I am using the strategy optimizer, and am changing a param value like going from SMA(CLose,6) to SMA(Close,7) inside OBU of the custom indicator.


              When I catch the error, I think I need to start at the 0 bars ago and loop to CurrentBar:


              for (int index = 0; index < CurrentBar; ++index)
              {
              myPlot[index] = newValue;
              }


              Either that, or just change the param value, and use a goto that forces the code to the before OBU so all the bars are recalculated?


              Next, will the new param value appear in the param value *settings* for the indicator on the chart (I know that the signal is updated on the chart because I have seen it).


              Last, I need the altered param value to be returned to the strategy, since i am in the middle of optimizing with the strategy. If I detected a param value needed to be changed in the called indicator, then I can't burn in the original parameter values sent to the indicator because the signal returned won't be synced with the param value.

              Comment


                #8
                Hello pel11,

                Dynamically handling the input parameter in such a way would not be the supported method of dealing with index out of error exceptions and instead you should use a current bar check to prevent these errors.

                Please see the following section of our forum on current bar checks,


                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Alan,

                  Let's back up a little. My example of the SMA was probably a bad one. The param1 value that needs to be changed inside the OBU of the custom indicator (which is called by a strategy) is a math function input not a period of length (#bars) type of input. This is a function approximation issue that has to be dealt with.

                  What I observed with the indicator is that, for a given chart, if the value of param1 is to low, my custom RSI signals (lower, middle, and upper bound signals) can be greater than 100. So if I slightly bump it up param1 by using "param1+=1;", the upper bound of 100 won't be breached.

                  So inside the OBU of the indicator, I test for myRSI>100, and if it is I need to add a 1 to param1 (i.e., param1+=1; ), then recalculate the signals over all the bars. (FYI - there are no "not enough bars available errors" when this is done). After this, if I see anywhere over the same bars that myRSI>100, then I simply do param+=1; and recalculate the signals over all bars again. On charts where I have seen this rare occasion for a few bars, I have already been able to fix it so the chart looks normal -- I just need to confirm how to send the new param1 values back to the strategy and also show the param *settings* values in the indicator (the signal displayed in the indicator is already updated).

                  In conclusion, assume you are inside an OBU of a custom indicator which is called by a strategy. On very rare occasions, you need to change a math param value [like log(3x) instead of log(2x)], and need to recalculate the signals over all bars again, until there's no error.

                  During typical C# programming you could do anything like this you want, and in fact this is merely logical (if-then) as you know. The issue is that you need to do this math function output trapping via C# and happen to be inside another program called NT8. How does one make this work with no snags? Hope you are now seeing the goal.
                  Last edited by pel11; 06-26-2018, 09:05 AM.

                  Comment


                    #10
                    Hello pel11,

                    show the param *settings* values

                    This would not be possible on the fly without refreshing NinjaScript.

                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DJ888, 04-16-2024, 06:09 PM
                    4 responses
                    12 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by terofs, Today, 04:18 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by nandhumca, Today, 03:41 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post nandhumca  
                    Started by The_Sec, Today, 03:37 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post The_Sec
                    by The_Sec
                     
                    Started by GwFutures1988, Today, 02:48 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X