Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing indicator plot data within a strategy

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

    #16
    Zeos6,

    Is there any chance that I can get a copy of both strategy and indicator to test on my end?
    Cal H.NinjaTrader Customer Service

    Comment


      #17
      Hi Cal,

      That is going to be difficult as this is a custom indicator being coded for someone. Can you tell me if there is still the issue with COBC true and false between the indicator and the strategy? Could this be an issue?

      Comment


        #18
        Zeos6,

        There could be a syncing issue here between the two.

        To help with the debugging my advice would be to add some print statements to your script, include time stamps, CurrentBar, and any indicator values for comparison
        Cal H.NinjaTrader Customer Service

        Comment


          #19
          Hi Cal,

          I have printed time stamps, bars, indicator info ...
          When you say a syncing issue, what do you mean? Also, why would this not show up when the indicator is added via Add()?

          Comment


            #20
            Originally posted by Zeos6 View Post
            Hi Cal,

            Thanks for your response. I am using Print() to get values. The SMA(14)[0] works fine. The SMA plots on the chart in the chart tab and the values are coming through fine. My indicator plots fine in the chart tab as well but no values are coming through.

            Incidentally, I created a secondary series in my indicator (not a plot). I exposed the series properly and I cannot even get the value of that series in the strategy. This is very odd.

            =====

            I have debugged the strategy with VS and have come across something. It appears that my custom input DataSeries is not calculating during strategy testing. I am not sure what I have missed here. Any insight would be appreciated. Thank you.

            In the indicator, Variable section, I create the variable
            private DataSeries inputSeries;

            In the Initialize() section I write
            inputSeries = new DataSeries(this, MaximumBarsLookBack.Infinite);

            In the OnBarUpdate() section I have
            switch(InputType)
            { ...
            case InputDataSource.Median: // (H+L)/2
            inputValue = 0.5*(High[0]+Low[0]);
            inputSeries.Set (Instrument.MasterInstrument.Round2TickSize(inputV alue));
            break;

            ...
            }

            Yes, I am aware that I can get this using Input () but I use it to create some other custom type inputs.

            This code works fine in the indicator but in the strategy this seems to be generating the value 0. Am I missing something here?

            Thanks for any insight you may be able to provide.
            You are using an enum in the Indicator. What happens when you call that Indicator from a Strategy will depend on how that enum is accessed and passed to the Indicator and how you call any entities of the Indicator from the Strategy.

            Comment


              #21
              Thank you for your reply koganam.

              Yes I understand that what happens when I call the Indicator from the Strategy will depend on how that enum is accessed and passed to the Indicator. However, the signature of the Indicator involves a number of other global public enums and those seem to be coming across correctly. Only this specific one, InputType, seems to be having an issue. And, all the enums are being called the same way. As an aside, why would the indicator add and plot correctly in the chart tab if the enum parameters were not being specified correctly?

              Comment


                #22
                Hello Zeos6,

                Thank you for your response.

                The following code, this is from the indicator, correct?
                Originally posted by Zeos6 View Post
                In the indicator, Variable section, I create the variable
                private DataSeries inputSeries;

                In the Initialize() section I write
                inputSeries = new DataSeries(this, MaximumBarsLookBack.Infinite);

                In the OnBarUpdate() section I have
                switch(InputType)
                { ...
                case InputDataSource.Median: // (H+L)/2
                inputValue = 0.5*(High[0]+Low[0]);
                inputSeries.Set (Instrument.MasterInstrument.Round2TickSize(inputV alue));
                break;

                ...
                }
                Can you provide the lines from your Strategy in Initialize() and OnBarUpdate() that are working to plot the indicator but not call it's values?

                Comment


                  #23
                  Found the Issue But ...

                  Hi Patrick_H,

                  Thank you for your reply. The relevant strategy code is:

                  Variables region:
                  private int td_fP = 2;
                  private int td_sP = 6;
                  private int td_p = 0;
                  private double td_pS = 10;
                  private double td_g = 0.3;
                  private Color td_tColor = Color.Cyan;
                  private Color td_oColor = Color.Blue;
                  private PBTD_InputDataSource inputType = PBTD_InputDataSource.Median;
                  private PBTD TrD;

                  Initialize():
                  Add(PBTD(PBTD_MovingAverageType.SMA, td_fP, td_g, PBTD_InputDataSource.Median, td_oColor, td_p,
                  td_pS, PBTD_PriceUnitType.Ticks, PBTD_MovingAverageType.SMA, td_sP, td_tColor));

                  This part is working correctly.

                  OnStartUp() section
                  TrD = PBTD(PBTD_MovingAverageType.SMA, td_fP, td_g, PBTD_InputDataSource.Median, td_oColor, td_p,
                  td_pS, PBTD_PriceUnitType.Ticks, PBTD_MovingAverageType.SMA, td_sP, td_tColor);

                  OnBarUpdate() section:
                  bool TrDStarted0 = TrD.TS.ContainsValue(0);
                  bool TrDStarted1 = TrD.TS.ContainsValue(1);
                  Print("=================");
                  Print("Strategy Time[0] = "+Time[0]);
                  Print("TrD.InputSeries[0] = "+TrD.InputSeries[0]);
                  Print("median = "+(High[0]+Low[0])/2);
                  Print("TrDStarted 0 = "+TrDStarted0);
                  Print("TrDStarted 1 = "+TrDStarted1);
                  Print("TrD.TS[0] = "+TrD.TS[0]);
                  Print("TrD.TS[1] = "+TrD.TS[1]);

                  The indicator TrD, (or PBTD) creates three plots: TS, TSE, OS. I have also included, as a simple test, a series that is not a plot that gets exposed. This is called InputSeries in the indicator.

                  Thank you for your insight and any help/guidance you may be able to offer.

                  ================================================== =

                  FOUND THE ISSUE BUT ...

                  Hi Patrick_H,

                  I have found the problem. The indicator and the strategy are now communicating properly. The problem issue is the following few lines of code I had placed at the start of the OnBarUpdate() section of my indicator:

                  if (
                  ChartControl ==
                  null// Check for ChartControl object.
                  || Instrument == null// Check for Instrument object.
                  || Bars == null// Check if any bars exist for the chart.
                  || Bars.Count < 0// Check if any bars have been loaded into the chart.
                  )
                  return;

                  When I remove this code, everything works properly. When I include this code, the strategy and the indicator fail to communicate. The code creates no problems in the indicator on its own. I am not really sure what is going on here but if you can shed some light on this I would greatly appreciate it. Thank you.
                  Last edited by Zeos6; 08-07-2014, 03:04 PM. Reason: Found the issue but need clarification

                  Comment


                    #24
                    Originally posted by Zeos6 View Post
                    Hi Patrick_H,

                    Thank you for your reply. The relevant strategy code is:

                    Variables region:
                    private int td_fP = 2;
                    private int td_sP = 6;
                    private int td_p = 0;
                    private double td_pS = 10;
                    private double td_g = 0.3;
                    private Color td_tColor = Color.Cyan;
                    private Color td_oColor = Color.Blue;
                    private PBTD_InputDataSource inputType = PBTD_InputDataSource.Median;
                    private PBTD TrD;

                    Initialize():
                    Add(PBTD(PBTD_MovingAverageType.SMA, td_fP, td_g, PBTD_InputDataSource.Median, td_oColor, td_p,
                    td_pS, PBTD_PriceUnitType.Ticks, PBTD_MovingAverageType.SMA, td_sP, td_tColor));

                    This part is working correctly.

                    OnStartUp() section
                    TrD = PBTD(PBTD_MovingAverageType.SMA, td_fP, td_g, PBTD_InputDataSource.Median, td_oColor, td_p,
                    td_pS, PBTD_PriceUnitType.Ticks, PBTD_MovingAverageType.SMA, td_sP, td_tColor);

                    OnBarUpdate() section:
                    bool TrDStarted0 = TrD.TS.ContainsValue(0);
                    bool TrDStarted1 = TrD.TS.ContainsValue(1);
                    Print("=================");
                    Print("Strategy Time[0] = "+Time[0]);
                    Print("TrD.InputSeries[0] = "+TrD.InputSeries[0]);
                    Print("median = "+(High[0]+Low[0])/2);
                    Print("TrDStarted 0 = "+TrDStarted0);
                    Print("TrDStarted 1 = "+TrDStarted1);
                    Print("TrD.TS[0] = "+TrD.TS[0]);
                    Print("TrD.TS[1] = "+TrD.TS[1]);

                    The indicator TrD, (or PBTD) creates three plots: TS, TSE, OS. I have also included, as a simple test, a series that is not a plot that gets exposed. This is called InputSeries in the indicator.

                    Thank you for your insight and any help/guidance you may be able to offer.

                    ================================================== =

                    FOUND THE ISSUE BUT ...

                    Hi Patrick_H,

                    I have found the problem. The indicator and the strategy are now communicating properly. The problem issue is the following few lines of code I had placed at the start of the OnBarUpdate() section of my indicator:

                    if (
                    ChartControl ==
                    null// Check for ChartControl object.
                    || Instrument == null// Check for Instrument object.
                    || Bars == null// Check if any bars exist for the chart.
                    || Bars.Count < 0// Check if any bars have been loaded into the chart.
                    )
                    return;

                    When I remove this code, everything works properly. When I include this code, the strategy and the indicator fail to communicate. The code creates no problems in the indicator on its own. I am not really sure what is going on here but if you can shed some light on this I would greatly appreciate it. Thank you.
                    Do the standard isolation thing by removing those terms one at a time until you find the culprit. I have an inkling that it might be the ChartControl, as the indicator is not directly applied to a chart, but for now, that is merely speculation on my part.

                    Comment


                      #25
                      Hi koganam,

                      Thank you for the reply. Will test it out and post here.

                      Comment


                        #26
                        Hi koganam,

                        You were correct. The issue is that the statement ChartControl == null; does not work with a strategy. It is likely as you said: the indicator is not being applied directly to a chart.

                        Comment


                          #27
                          Originally posted by Zeos6 View Post
                          Hi koganam,

                          You were correct. The issue is that the statement ChartControl == null; does not work with a strategy. It is likely as you said: the indicator is not being applied directly to a chart.

                          Thanks for letting us know. I will make sure to take note of it for reference, just in case I am making the same ?mistake(?).

                          Comment


                            #28
                            I'm going to post in this thread since I'm having the same problem in this thread, but my cause is different. I wasn't using the ChartControl test.

                            I have attached the indicator and the strategy. Here's what I see, for the first 265 bars, ContainsValue works as expected, but it appears that the DataSeries items are reused as things progress and it doesn't appear to be clearing the ContainsValue flag. Here's my output.

                            strategy running on 1 min bars, indicator only populates every 5th DataSeries item, I use ContainsValue and it's only showing 1 of 5 to start of, which is as expected

                            Start of Console output
                            1/1/2015 9:27:00 PM CurrentBar: 266 FiveBarLower: 10
                            1/1/2015 9:32:00 PM CurrentBar: 271 FiveBarLower: 15
                            1/1/2015 9:37:00 PM CurrentBar: 276 FiveBarLower: 20
                            ....
                            .... more log lines here and so far working as expected, here's where it deviates from the expected
                            ....
                            1/6/2015 1:24:00 AM CurrentBar: 496 FiveBarLower: 240
                            1/6/2015 1:29:00 AM CurrentBar: 501 FiveBarLower: 245
                            1/6/2015 1:34:00 AM CurrentBar: 506 FiveBarLower: 250
                            1/6/2015 1:39:00 AM CurrentBar: 511 FiveBarLower: 255
                            1/6/2015 1:44:00 AM CurrentBar: 516 FiveBarLower: 260
                            1/6/2015 1:49:00 AM CurrentBar: 521 FiveBarLower: 265
                            1/6/2015 1:50:00 AM CurrentBar: 522 FiveBarLower: 10 <--------
                            1/6/2015 1:54:00 AM CurrentBar: 526 FiveBarLower: 270
                            1/6/2015 1:55:00 AM CurrentBar: 527 FiveBarLower: 15 <--------
                            1/6/2015 1:59:00 AM CurrentBar: 531 FiveBarLower: 275
                            1/6/2015 2:00:00 AM CurrentBar: 532 FiveBarLower: 20 <--------
                            1/6/2015 2:04:00 AM CurrentBar: 536 FiveBarLower: 280
                            1/6/2015 2:05:00 AM CurrentBar: 537 FiveBarLower: 25 <--------

                            Thanks for your help
                            Attached Files

                            Comment


                              #29
                              I have an update on this, I got it working when I changed the indicator code from using a DataSeries to the Plot DataSeries.

                              If you can tell me what I did wrong, I think it might help everyone.

                              from
                              if (CurrentBar % 5 == 0)
                              lower.Set(2, CurrentBar);

                              to
                              if (CurrentBar % 5 == 0)
                              Values[1][2] = CurrentBar;
                              Last edited by dynoweb; 01-17-2015, 05:45 PM.

                              Comment


                                #30
                                More information, I tried to apply this code back into my strategy and it didn't work. Even using the working indicator. Here's what I found out. If I have both "if" statements below in my strategy it works and it prints using the second Print statement since the data is added two bars back. If I only have the second statement, it doesn't work. I think the first one is doing something to by testing [0] which enables the second test to work.

                                Still confused.

                                if (FiveBarSample().FiveBarLower.ContainsValue(0))
                                Print(Time + " 0 - CurrentBar: " + CurrentBar + " FiveBarLower: " + FiveBarSample().FiveBarLower[0]);

                                if (FiveBarSample().FiveBarLower.ContainsValue(2))
                                Print(Time + " 2 - CurrentBar: " + CurrentBar + " FiveBarLower: " + FiveBarSample().FiveBarLower[2]);

                                Also, I realized that I still need the DataSeries since it will contain information that isn't plotted. The array element that will be populated will be the same bar where the indicator will plot. So I still need help getting the previously attached sample code to work.
                                Last edited by dynoweb; 01-17-2015, 08:33 PM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                672 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                379 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                111 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                575 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                582 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X