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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      65 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      139 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X