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 Zinger357, 07-01-2024, 06:24 PM
      12 responses
      98 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by SteenLeold, Today, 06:25 AM
      0 responses
      1 view
      0 likes
      Last Post SteenLeold  
      Started by CMENDOZA878, Yesterday, 04:21 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by algospoke, 05-13-2024, 06:53 PM
      15 responses
      154 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by llanqui, Yesterday, 05:56 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X