Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using indicator as a type in a strategy

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

    Using indicator as a type in a strategy

    This line
    Stochastics myStoch = Stochastics(Closes[tf1], stochLineD_Period, stochLineK_Period, stochSmooth);
    complies and operates ok in an indicator.
    The same line gets gets an error 118 in a strategy "Stochastics is a method but is used as a type."
    What do I need to change to get this line to compile in a strategy?
    Thanks

    #2
    Hello roland_nt,

    This is because the Strategy is going to see it as a Strategy component that is used to add an Indicator to a chart like in the following reference


    You may do something like the following to be able to create your Indicator object, but note this is not something that we can support.

    Code:
    Indicator.SMA mySMA = new Indicator.SMA();
       
    protected override void OnStartUp()
    {
    	mySMA = mySMA.SMA(Input, 14);
    }
    
     protected override void OnBarUpdate()
    {
    		
    		if(CurrentBar < BarsRequired) return;
    		
    		Print("mySMA: "+mySMA[0]);
    }
    JCNinjaTrader Customer Service

    Comment


      #3
      using indicator as a type

      JC:
      thanks.
      this is very helpful.
      Roland_nt

      Comment


        #4
        indicator as type

        JC:
        This all occurred because I am converting an indicator into a strategy.
        The indicator code was originally written as in the initial entry of this post.
        Because I wanted to make the code between the two consistent. I chnaged
        the indicator code to match your sample.
        Now, in the variables section, for example
        Indicator.Stochastics myStoch = new Indicator.Stochastics();
        gets a compile error in the indicator with the same c118 message about using an indicator as type..
        Are the usage rules different for this idea in each context?
        Thanks again
        Roland

        Comment


          #5
          Hi Roland.nt,

          Could you provide the whole code setup you have for the indicator object variable?
          Cal H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          5 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X