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 FrancisMorro, Today, 03:24 AM
        0 responses
        1 view
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,770 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        944 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        11 views
        0 likes
        Last Post Max238
        by Max238
         
        Working...
        X