Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the fast and precise answer!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by adeelshahzad, Today, 03:54 AM
      5 responses
      32 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by stafe, 04-15-2024, 08:34 PM
      7 responses
      32 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by merzo, 06-25-2023, 02:19 AM
      10 responses
      823 views
      1 like
      Last Post NinjaTrader_ChristopherJ  
      Started by frankthearm, Today, 09:08 AM
      5 responses
      20 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      43 views
      0 likes
      Last Post jeronymite  
      Working...
      X