Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to plot an indicator that returns multiple values

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

    How to plot an indicator that returns multiple values

    Hi,

    I have coded an indicator 'MyCapFloor' that returns two different DataSeries:
    - MyCapFloor.Resistance
    - MyCapFloor.Support

    I would like to add each of these series to a strategy as plots that I can inspect in the Strategy Analyzer Chart.

    I have added the following code in the Initialize() method of my strategy:

    MyCapFloor.Resistance.Indicator.Panel=0;
    Add(MyCapFloor
    .Resistance.Indicator);
    MyCapFloor
    .Resistance.Indicator.Plots[0].Pen.Color=Color.Blue;

    It compiles without errors but it doesn't plot to the Chart after backtesting the strategy.

    In order to investigate this I have crated another indicator 'MyResistance' which returns the same values as in 'MyCapFloor.Resistance' but under a unique dataseries. Now my code looks like:

    MyResistance.Indicator.Panel=0;
    Add(My
    Resistance.Indicator);
    My
    Resistance.Indicator.Plots[0].Pen.Color=Color.Blue;

    It compiles and it does show the plot I was expecting in the Chart of the strategy analyser.

    How can I get each of the dataseries returned by MyCapFloor indicator plotted in a strategy?

    thanks

    Maese




    #2
    Hi Maese, if you have those series defined as regular Plots in the originating indicator, please just add the complete indicator in for display and not just one series. With the Add() technique you could only really add the complete study in and not pick a specific plot to use.

    Same concept you could for example test using a default multiplot indicator like our Bolliger Bands.

    Add(Bollinger(2, 20));

    ... would add in the complete study with it's 3 expected plots.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand,

      I have added the entire hosted indicator as you suggested and it works as I was expected.
      For those who may be interested here is how the code in the Initialize() method of my hosted indicator looks:

      Add(new Plot(Color.Red, "MyCap"));
      Add(new Plot(Color.Black, "MyFloor"));

      and in the Initialize() method of my hosting strategy looks:

      MyCapFloor().Panel=0;
      Add(MyCapFloor(
      ));
      MyCapFloor(
      ).Plots[0].Pen.Color=Color.Blue; //MyCap
      MyCapFloor(
      ).Plots[1].Pen.Color=Color.Green; //MyFloor

      When I backtest the strategy I can visualize the two plots in the 'Chart' tab of the results. I can also see them in the DataBox with the name that was given to each plot in the hosted indicator (MyCap and MyFloor).

      One final question: is there a way to refer to the plot names when coding the hosting strategy?
      In my example above I don't know that Plots[0] contains the 'MyCap' series unless I look into the code of the hosted indicator.

      regards

      Maese

      Comment


        #4
        Glad to hear Maese. You would need to refer to the Plots collection to change the Pen properties like in your example, this could not happen by plot name as the collection is based on the index where the plot is stored.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        57 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        35 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        19 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        9 views
        0 likes
        Last Post cre8able  
        Working...
        X