Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Indicator to Strategy not working

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

    Adding Indicator to Strategy not working

    Under what circumstances does adding an indicator to a strategy not work?...i.e. indicator does not plot nor produce values.

    I have a trend indicator which plots perfectly and prints its value perfectly.

    My strategy also accesses/calls the trend indicator and prints and uses the trend value from the indicator perfectly.

    However, when I Add() the indicator to the strategy, it shows up in panel 2 but does not plot...and the trend value is no longer produced/available.

    I add many indicators to my cs often and have never had this problem occur. What could cause this?

    At this point I have to add the indicator to my strategy chart manually to watch/check the trend triggers and I can see that the cs is using the trend values properly...no problem. For convenience I would like my cs to add the indicator, like all others, however the indicator ceases working.....with no errors in the Log.

    Thanks.

    #2
    Hello,

    It is difficult to say without seeing your code. However should the indicator be plotting on the Price panel (Panel 1)? If so, go into your indicator and put this in the initialization section: Overlay = true;
    Then compile and re-attach the indicator to your chart.

    If that does not help, please cut and paste your code so I can help further.
    DenNinjaTrader Customer Service

    Comment


      #3
      the indicator is meant to plot on panel 2 ...and it does create panel 2

      i stipulated PanelUI =2 which had not effect

      the indicator uses marketdepth code....and plots normally when added manually to a chart...could this be the problem?

      I note that it is not my cs but rather the indicator code as I added the indicator to SampleMACrossmod and had the same problem

      thought it might be the Dispose code?...so commented that out and same problem

      the indicator had the code:
      ChartControl.ChartPanel.Invalidate();
      which I commented out because it was causing a different problem earlier....
      current problem exists with or without that code

      Comment


        #4
        Hello,

        We provide support for NinjaScript. Your code is crossing into more advanced C# code that we do not provide support for. I recommend slowly stepping through your code until you figure out why it is not working.
        DenNinjaTrader Customer Service

        Comment


          #5
          actually the only code that is not standard ninjascript is the chartcontrol line which I said I commented out

          so the question remains could it be the MarketDepth code or the Dispose code?

          since I commented out the Dispose code, that eliminates it.

          if I comment out the MarketDepth code, there is no indicator

          I still need to know how and indicator can run properly when separately/manually added to a chart but not when added by Add() to a strategy

          Comment


            #6
            Hi ATI user,
            Not having seen your full code, I would suggest you remove CalculateOnBarClose from the indicator code you call with Add() and try this again.

            Comment


              #7
              thanks Bertrand...no that did not make a difference.

              I had forgotten about that fix. It has worked in other instances (wherein I was plotting from the cs)...however other indicators I Add() to the cs have CalculateOnBarClose = false; running and plot fine...even with OnMarketData running

              I will comment out all code and see if I can get a simple plot working first...then add back lines

              Will advise re fix when I have one
              Last edited by ATI user; 12-18-2008, 06:10 AM.

              Comment


                #8
                note in chart that strat 'test' adds ind 'test_ind' and ind does not plot

                ind in panel 3 is manually added ind 'test_ind' which plots fine

                strat 'test' is SampleMACrossover with Add( test_ind(10) );
                Attached Files

                Comment


                  #9
                  Hello,

                  OK, I attached the indicator and the Strategy seperately and neither work so it has nothing to do with your Add() in the strategy. It has to do with your indicator code. You will need to debug it.
                  Last edited by NinjaTrader_Ben; 12-18-2008, 09:15 AM.
                  DenNinjaTrader Customer Service

                  Comment


                    #10
                    the indicator works fine on 2 of my computers

                    did you test it on feed that has market depth info?

                    ....

                    I included my indicator code so you could review and tell me what is wrong. It is all standard ninjascript and therefore supported is it not?

                    Comment


                      #11
                      Here is the issue:
                      Code:
                      // Attach a market depth event handler (if  connected provider does not support depth, you will not get any events)
                      if (Bars != null && Bars.MarketData != null)
                      {
                          marketDepth = Bars.MarketData.Connection.MarketDepthStreams[Bars.Instrument];
                          if (marketDepth != null) 
                              marketDepth.MarketDepthItem += new MarketDepthItemEventHandler(OnMarketDepth);
                      }
                      Please move it out of the Initialize() method and into OnBarUpdate().
                      Code:
                      if (CurrentBar == 0)
                      {
                          // Attach a market...
                      }
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Excellent Josh!

                        Works perfectly. Thanks.

                        Could you please explain the Dispose method relative to the market depth code in my indicator?

                        I thought it might be causing the problem ...obviously was not.

                        I know it saves/restores resources. I need to know if I should use it in my code that uses OnMarketData code also.

                        Thanks again.

                        Comment


                          #13
                          The question boils down to why you are creating such an item to begin with. You would want to use the syntax offered in the help guide instead of creating your own.

                          If you want a bid/ask table you can see the reference sample on creating your own.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          572 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          331 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          549 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          550 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X