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

attaching indicators in code

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

    attaching indicators in code

    Hi

    Not sure if this question should be here or in coding...

    I have created a strategy that uses the following code;

    Strategy name : 'Elliot3rdWaveStratV1001

    else if (State == State.DataLoaded)
    {
    // Charts the indicator to the chart
    AddChartIndicator( Elliot3rdWaveV1006(20,5,10000,20,0,1,0,0));
    }

    This creates no problem in my NT8 setup or on another colleagues NT8.

    But when we run this on my bosses NT8 then he gets the following error;
    Strategy 'Elliot3rdWaveStratV1001': Error on calling 'OnStateChange' method: 'AddChartIndicator' cannot be called from this state. Please see the Help Guide article on 'AddChartIndicator' for more information.

    any help appreciated
    Cheers

    #2
    Hello fishbed,

    Thank you for the post.

    I am reviewing your inquiry and will be back with a reply shortly.

    I look forward to assisting further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello fishbed,

      Thank you for your patience.

      This error is due to the indicator calling AddDataSeries(); When we dynamically call a BarsPeriod in State.Configure the data may not have loaded yet and thus the BarsPeriod has not information and fails to call.

      To fix this, pass your own variables for the BarsPeriodType and period. For the BarsPeriodType I would recommend an enum to select the PeriodType and then use the switch and case in the indicator to determine the call to AddDataSeries().

      If questions come up please let me know.
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Hi Chris

        Thanks for this.

        However, I am not sure what you mean by this.

        I am not calling AddDataSeries(); from anywhere, is this automatically done when the strategy is loaded and "forces" the indicator to call the AddDataSeries() method? I use this method in other scripts when trying to work in multiple timeframes.

        In my strategy I iniate a call in ")State == State.DataLoaded)" for the indicator the strategy should use and this is what your documents say.

        I need to understand why it is doing what it is doing else I think I will run into this problem again and again. Are you able to provide any sort of example that may clarify this for me.

        Also why would this work on 2 other setups, surely it should be correct or not?

        Thanks

        Comment


          #5
          Hello fishbed,

          Thank you for the follow-up.

          You are adding the indicator correctly, you are also correct in that the indicator you are trying to add is the one calling AddDataSeries().

          If you are able to look at the code for Elliot3rdWaveV1006, please let me know what is happening in State.DataLoaded in the OnStateChange() method.

          I will also need to see the log and trace files for the machine it is not working on.

          Please send the log and trace folders to*platformsupport[at]ninjatrader[dot]com.*
          You can do this by going to the Control Center-> Help-> Mail to Platform Support.
          Please reference the following in the email body:*ATTN CHRISL <paste the forum link here>*

          I look forward to your reply.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Hi Chris

            With regards your question

            "If you are able to look at the code for Elliot3rdWaveV1006, please let me know what is happening in State.DataLoaded in the OnStateChange() method."

            I have no code in this area.

            Will send the log / trace files over later....

            Thanks

            Comment


              #7
              Hello fishbed,

              Under Control Center>Help>About, what version of NT is your bosses computer running?

              I look forward to the log and trace files.
              Alan P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mizzouman1, Today, 07:35 AM
              3 responses
              17 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by RubenCazorla, Today, 09:07 AM
              2 responses
              13 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by i019945nj, 12-14-2023, 06:41 AM
              7 responses
              82 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by timmbbo, 07-05-2023, 10:21 PM
              4 responses
              158 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by tkaboris, Today, 08:01 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X