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 usasugardefender, Today, 01:42 AM
      0 responses
      1 view
      0 likes
      Last Post usasugardefender  
      Started by haas88, 03-21-2024, 02:22 AM
      15 responses
      182 views
      0 likes
      Last Post haas88
      by haas88
       
      Started by brianfnoel, Today, 01:24 AM
      0 responses
      6 views
      0 likes
      Last Post brianfnoel  
      Started by bill2023, Yesterday, 08:21 AM
      2 responses
      14 views
      0 likes
      Last Post bill2023  
      Started by ynoldsany, Today, 01:00 AM
      0 responses
      3 views
      0 likes
      Last Post ynoldsany  
      Working...
      X