Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing indicator plot data within a strategy

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

    Accessing indicator plot data within a strategy

    Hi,

    I have run across a seemingly simple issue but the solution eludes me. I may be missing something. Any suggestions/advice would be greatly appreciated. Thank you.

    I have created a custom indicator with a fair number of arguments.
    PBTD(arg1, arg2, ...). The indicator creates and draws three plots: TS, TSE, and OS. The plots DO NOT contain calculated data for every bar. CalculateOnBarClose = true for the indicator.

    I add this indicator to my strategy and it plots correctly in the chart tab of the Strategy Analyzer. The CalculateOnBarClose for the strategy is set to true.
    Here is the issue. When I try to access the plot TS of the indicator, I test if it contains a calculated value with PBTD().TS.ContainsValue(0). The result is always false even though the indicator and the Startegy Analyzer chart indicate that the answer should be true. Furthermore, if I try to print the values PBTD().TS[0] incorrect values are printed. The values are the Closing prices of the bar. I have also tried this using the previous bar. It seems that none of the indicator plot information is coming through to the strategy. This is very odd as the indicator seems to have been added properly to the strategy.

    As an aside, is there a need to use Update() to ensure the indicator is up to date before it is used in the strategy?

    Thank you.

    #2
    Hello Zeos6,

    Thank you for your post.

    Update() would not resolve this matter for the Plot. Can you provide the full condition and code when setting the plot value?

    Comment


      #3
      Hi Patrick_H


      I am not sure what you are asking. The indicator code is complex and works fine. As it is being developed for someone, I would prefer not to send it.This seems to be a simple question. Why are the indicator plot values showing up correctly in the Strategy analyzer but I am not able to access the plot values?

      Comment


        #4
        Hello Zeos6,

        Thank you for your response.

        Is the plot conditional? Meaning the value of the plot is not set on every bar? Can you send me a screenshot of the plot on the chart versus the output window?

        Comment


          #5
          Hi Patrick_H,

          Yes, the plot is conditional. Are you looking to see a pic on the chart and on the chart in the Strategy Analyzer?
          Attached Files
          Last edited by Zeos6; 08-04-2014, 12:31 PM. Reason: Adding pics.

          Comment


            #6
            Hello Zeos6,

            Thank you for your patience.

            Unfortunately, a simple answer to this inquiry escapes me. Without additional information on the structure of the code and plot I can not say for certain why the plot is not printed as plotted on the chart.
            When a plot value prints as the price it means there is no set value. Have you tried setting the plot to 0 when the condition to set the plot is not true?

            Comment


              #7
              Hi Patrick,

              The issue I am having is strange. It seems that the indicator is being added properly via the Add() but yet it cannot be accessed in the OnBarUpdate() section.

              Comment


                #8
                Hello Zeos6,

                Thank you for your response.

                Do you have a testable scenario and/or script illustrating this issue?

                Comment


                  #9
                  Hi Patrick,

                  I will create one. One quick question. Suppose my indicator requires 12 arguments. Do I need to set all these argument values in the strategy when adding the indicator? Is there a way to default the values to the default values used in the indicator? Please advise. Thank you.

                  Comment


                    #10
                    Hello Zeos6,

                    Thank you for your response.

                    Any parameters that you would normally need to set in the Indicators menu of the Chart or Market Analyzer will require you to set them in when calling the indicator method in NinjaScript.

                    Comment


                      #11
                      Hi Patrick_H,

                      What about global public enums used by the indicator. Are those available inside strategies, or do those have to be specified as well? Thanks for letting me know.

                      Comment


                        #12
                        Hello Zeos6,

                        Those will need to be specified as well in your script. You would have direct access to the enum but you would need to create the variable in the script if you plan on changing it or you can directly call it in the syntax line when you call the indicator.
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Cal,

                          Thank you for your reply. Can you please clarify something for me. Why would an indicator work properly when added to a strategy via Add() and yet not be accessible in the OnBarUpdate(). This does not make sense, yet this is what is happening. The indicator is being added properly, and it charts correctly in the chart tab of the Strategy Analyzer, yet it does not pass any values of the Plot series to the strategy. Can you give me any idea what might cause this? Thank you.

                          Comment


                            #14
                            Zeos6,

                            What are you using to test and get the values of the indicator?
                            Print()?

                            Does this occur with just trying to get SMA(14)[0]?
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #15
                              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.
                              Last edited by Zeos6; 08-06-2014, 02:30 PM. Reason: Additional Information

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              670 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