Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AddChartIndicator isn't working now.

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

    AddChartIndicator isn't working now.

    Over the past few days, I've been using AddChartIndicator to add a separate panel with a custom indicator from a strategy. It was working fine. Today, it won't compile. Not sure why.

    I have a global created by:
    MyIndicator myIndicator;

    I try to initialize it in State.DataLoaded:
    MyIndicator myIndicator = MyIndicator( stuff, morestuff);

    I then tell it to be in a separate panel:
    myIndicator.IsOverlay = false;
    AddChartIndicator(myIndicator);

    I get the error "Cannot implicitly convert type 'NinjaTrader.NinjaScript.Indicators.MyIndicator' to 'NinjaTrader.NinjaScript.Strategies.MyIndicator'". The Code is CS0029
    and
    The name 'myIndicator' does not exist in the current context" Code CS0103

    What am I doing wrong?

    #2
    Hello mark0761,

    In this code you defined a local variable instead of setting the class variable, the following code is a problem:

    MyIndicator myIndicator = MyIndicator( stuff, morestuff);

    This needs to be

    myIndicator = MyIndicator( stuff, morestuff);

    The error is also saying that the name myIndicator does not exist in the context where you used it meaning there may be a misspelling somewhere. Basically the variable named myIndicator does not exist. I would suggest using the strategy builder in this case just to generate the correct code. In the builder you can create a condition that uses your indicator and click the plot on chart checkbox then click view code. That will generate the variables and AddChartIndicator code and you can then copy it into your other strategy.

    Comment


      #3
      Opps. Ha ha. I added a strategy that had the same name as the indicator.

      Evey thing works, if you let it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      48 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X