Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Plotting

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

    Strategy Plotting

    I like the ability to add plots to a strategy, this solves the problem I had before where I created a separate Indicator with public exposed variables so I could update the Indicator running below a strategy with information about the strategy.

    I am trying to learn how to use this feature under NT8.

    There are things I want to plot On the Price panel and some I would like to be separate Panels. I am not sure I know how to do this with NT8.

    Thanks

    #2
    Hello NJA_MC,

    Thank you for your post.

    Use ChartIndicators[int index] to change values as you would with StrategyPlot in NinjaTrader 7.

    Comment


      #3
      Hi Patrick,

      I am not that familiar with that feature but when I try to explore the feature after adding plots to a strategy, it tells me there a 0 elements:
      Historical ChartIndicators.Length=0

      I have tried this in the Configure, DataLoaded and Historical state change sections with no luck.

      Should this array have been created?

      Comment


        #4
        Sorry for the confusion - ChartIndicators would only contain members if you were using AddChartIndicator() to add an already created indicator for visual purposes.

        If you're adding a Plot series to the strategy, you can control the panel just like you do with an Indicator by using the IsOverlay option:

        Code:
        if (State == State.SetDefaults)
        {
        	IsOverlay = false;
        	AddPlot(Brushes.Orange, "MyPlot");
        }
        If you're trying to get plots on two different panels from the same strategy, this is not possible using a strategy calculated plot - you'd have to break you plots out to separate strategies.

        If you implemented your plots as indicators you could then control through the ChartIndicators[0].Panel property as Patrick had suggested.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Hi, I am not clear on how we do Strategy plotting like we did in NT7 in NT8.

          In NT7, I created a blank indicator called: MFStrategyPlotScore. I have created the same in NT8 now.

          QUESTION: What do I replace this code with in NT8, and where do I put it please??

          NT7 - INITIALIZE
          Add(MFStrategyPlotScore(plotScore)); // add the new plot for the score
          Add(MFStrategyPlotScore(plotScoreZero));
          // pen width
          MFStrategyPlotScore(plotScore).Plots[0].Pen.Width = 1;

          // colour
          MFStrategyPlotScore(plotScore).Plots[0].Pen.Color = Color.Black; // color the line Total line

          // Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
          // MFStrategyPlotScore(plotScore).PanelUI = 6; // score
          // MFStrategyPlotScore(plotScoreZero).PanelUI = 6; // Score Zero line


          NT7 - BarsInProgress==0
          // MFStrategyPlotScore(plotScore).Value.Set(scoreTota l);
          // MFStrategyPlotScore(plotScoreZero).Value.Set(0.0);


          QUETION 2: I want to do 2 indicators: The above one on the price, and a new indicator in a NEW panel NOT on the price panel. How do I do that as well?


          Thanks in advance.
          Last edited by DaFish; 09-01-2015, 11:20 AM.

          Comment


            #6
            Hello DaFish,

            Thank you for your post.

            We have updated the reference samples for NinjaTrader 8. Please take a look at the following link for the NinjaTrader 8 version of the Plotting From Within A Strategy sample: http://ninjatrader.com/support/forum...ead.php?t=6651

            Comment


              #7
              Hi Patrick, this link takes me to NT7, not NT8. I have it working in NT7, is there updated docs for NT8? Specifically, how do I port from NT7 to NT8?

              The reason I created this thread is to explore how the advanced features of NT8. Although I need to get this working, I would also like to explore how NT8 allows me to take this to the next level. For example.

              I have a number of indicators that I wrote to plot envelopes, and trend lines. Can the strategy load those indicators on the chart and then REFERENCE the public variables in that indicator so I don't have to recreate the same code in the strategy? This would significantly reduce my complexity in my strategy, and I wouldn't have to have duplicate code running in an Indicator and a Strategy.

              Please advise, Thanks

              Originally posted by NinjaTrader_PatrickH View Post
              We have updated the reference samples for NinjaTrader 8. Please take a look at the following link for the NinjaTrader 8 version of the Plotting From Within A Strategy sample: http://ninjatrader.com/support/forum...ead.php?t=6651

              Comment


                #8
                We intentionally did not update that reference sample due to the new implementation of AddChartIndicator() in NinjaTrader 8.

                You should be able to accomplish all of that much more efficient with the combination of AddChartIndicator() and ChartIndicators[], like so:

                Code:
                               //OnStateChange
                		if (State == State.Configure)
                		{
                                MyCustomIndicator indi = new MyCustomIndicator();
                                AddChartIndicator(indi);
                		}
                
                               	protected override void OnBarUpdate()
                		{
                                ChartIndicators[0].PlotBrushes[0][0] = Brushes.Blue;
                                ChartIndicators[0].Panel = 2;
                                }
                By using AddChartIndicator(), you will have direct access to an object, and you can change its properties directly.
                Dave I.NinjaTrader Product Management

                Comment


                  #9
                  Hello DaFish,

                  Thank you for your response.

                  Plotting in strategies is the same as indicators now in NinjaTrader 8.

                  You can AddChartIndicator() and then call the indicator's method in your code as you would in NinjaTrader 7. I highly recommend reviewing the Help Guide documentation.

                  Comment


                    #10
                    Hi that is great that NT8 plots like indicators now. Perfect.

                    One more question:

                    Scenario:
                    1) Add a chart - say APPL
                    2) Add say a Simple Moving Average - SMA(14) to the chart - in that indicator, declare a PUBLIC double SMA_VALUE and assign it to the calculated value for SMA(14)
                    3) Create a new strategy

                    QUESTION 1: Is there a way the Strategy can access the PUBLIC double SMA_VALUE from the indicator in step 2 ?

                    This would be pretty efficient. I could have all my indicators calculate the values I need and then just reference them in the Strategy saving processing power of trying to put them in the indicator and in the strategy (for example SMA, CCI and FisherTransform)

                    please advise if this is possible in NT8. Thanks

                    Comment


                      #11
                      Originally posted by DaFish View Post
                      Hi that is great that NT8 plots like indicators now. Perfect.

                      One more question:

                      Scenario:
                      1) Add a chart - say APPL
                      2) Add say a Simple Moving Average - SMA(14) to the chart - in that indicator, declare a PUBLIC double SMA_VALUE and assign it to the calculated value for SMA(14)
                      3) Create a new strategy

                      QUESTION 1: Is there a way the Strategy can access the PUBLIC double SMA_VALUE from the indicator in step 2 ?

                      This would be pretty efficient. I could have all my indicators calculate the values I need and then just reference them in the Strategy saving processing power of trying to put them in the indicator and in the strategy (for example SMA, CCI and FisherTransform)

                      please advise if this is possible in NT8. Thanks
                      There will be no savings. The indicator class will still have to be loaded in order for it to do any calculations. It does not matter how or where you load it.
                      Last edited by koganam; 09-04-2015, 07:31 AM.

                      Comment


                        #12
                        Originally posted by koganam View Post
                        There will be no savings. The indicator class will still have to be .loaded in order for it to do any calculations. It does not matter how or where you load it.
                        I think the issue here is around optimization. I believe DaFish is try to only load one copy of the indicator and use it for visualization (on chart, pre-loaded) and within the strategy. So rather than creating another copy of the indicator with another calculation, use the single copy already in memory.

                        I don't know if NT8 does this optimization by itself (if it sees the same indicator, reference the instance already in memory rather than creating another copy). I thought NT7 had some features along that line to only have a single copy of an indicator in memory (same parameters have to be used).

                        Comment


                          #13
                          Hi yes there will be savings.

                          My indicators I am adding on the chart are:

                          DoubleStochastics
                          EMA
                          CCI
                          FisherTransform

                          If I add these as indicators - AND - the strategy needs needs them too, so I am RECALCULATING the same indicators each time.

                          If I can access the pubilc ISERIES from the strategy, then that is all I need. I don't need to recalculate them so I am saving CPU cycles by only doing it once.

                          Comment


                            #14
                            I have not found a solution for this so far. There is a collection of IndicatorRenderBase objects in the "ChartControl.Indicators" collection, but these do not seem to carry the current values of the indicators in the collection. I will continue looking a bit further and see if I can dig up a solution for you.
                            Dave I.NinjaTrader Product Management

                            Comment


                              #15
                              I've got an update for you. We are well into undocumented and unsupported code territory on this one, but we were able to figure out a way to obtain the current value of the existing indicator instance already applied to a chart. There are a few key pieces here that must be in place, so I've attached a sample script including all of the necessary pieces.

                              Key #1) You must create a new object of the same type as the indicator you are looking for, then instantiate that object by assigning a reference to the chart-applied indicator's index within the ChartControl.Indicators[] collection. At this point, the object defined in your strategy will contain a reference to the indicator on your chart, NOT a new instance. We were able to verify this by comparing an internal instance ID which you will not be able to access. This ID is unique for each instance, and we verified that both the indicator on the chart and the one held by reference in the object created by the strategy do indeed share the same instance ID.

                              Key # 2) You must call .SetInput(Input) on the object created in your strategy before trying to access its values. Without this, the object's values appear to only be set once, during Bar # 1, and are not updated again.

                              You will be able to see both of these keys in play in the attached sample scripts. Keep in mind that this is not a process designed and intended to be used in NinjaScript, so I cannot guarantee that it will not cause unexpected results down the road. But it should do the trick of limiting the number of redundant instances you are creating via your strategy.

                              Another thing to keep in mind -- a supported method of accomplishing the goal of limiting the number of instances would be to use AddChartIndicator() in your strategy, and just let the strategy handle plotting the indicator on the chart, rather than applying a separate instance to the chart manually.
                              Attached Files
                              Last edited by NinjaTrader_DaveI; 09-04-2015, 02:18 PM.
                              Dave I.NinjaTrader Product Management

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Mizzouman1, Today, 07:35 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post Mizzouman1  
                              Started by philmg, Today, 01:17 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by cre8able, Today, 01:01 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by manitshah915, Today, 12:59 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by ursavent, Today, 12:54 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X