Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Skiping adding same indicators to Chart from two Strategies running in the same Chart

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

    Skiping adding same indicators to Chart from two Strategies running in the same Chart

    How I can detect that the same indicators has been added to the Chart from two identical strategies running on the same chart?

    I've notice that ChartPanel.ChartObjects contains the strategies created in the Chart, and I can explore ChartIndicators container to check if the same Indicator has been declared before skippng AddChartIndicator(myindicator) call but sometimes I got System.InvalidCastException: 'Unable to cast object of type 'NinjaTrader.NinjaScript.Strategies.MyPackage.MySt rategy' to type 'NinjaTrader.NinjaScript.Strategies.Strategy

    I can not figure out when this excecptions happens as sometimes works fine.

    1. How I can "force" casting to NinjaTrader.NinjaScript.Strategies.Strategy ?
    2. Is there another simpler way to detect if the same indicators from another strategies has been added already?

    Thanks in advance.

    #2
    Hello massiel,

    Thank you for your post.

    You can check to see if ChartControl is not null, and if it's not, you can check ChartControl.Indicators collection to see if an indicator is added. If you know the names of the public properties you can see if it is identical to the one you want to add. I'm attaching a very simple example that demonstrates this - if it's added to a chart without an existing SMA(14) indicator applied, it will add it to the chart. If it is added to a chart with an SMA(14) on it already, it will not add the indicator and will instead print a message to the bottom left corner of the chart stating it was not added.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Thanks for the fast and precise answer!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 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