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

SMA with variable period

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

    SMA with variable period

    Hi there,

    Newbie here.....

    I am trying to setup an indicator for a Simple Moving Average where the period is the value of another indicator which has been already created (and which therefore can be itself variable).

    Can somebody please point me in the right direction? The SMA requires to input the period, but in this case that would come already from an existing script.

    Many thanks
    BC.
    Last edited by bondcrash; 10-21-2011, 03:28 AM.

    #2
    Welcome to our forums bondcrash, you could then just call the other indicator supplying the needed period in your SMA script.

    double mySMAValue = SMA(Close, myVarPeriod[0])[0];
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Bertrand. Have a couple of errors when compiling, and I think they are somehow related.

      - CS1503: where it seems the argument of MyVarPeriod cannot be converted from double to int. I have applied a MathRound to MyVarPeriod so to get rid of decimals

      -CS1502:where it seems there are invalid arguments for MyVarPeriod.

      This is the structure I am using:

      double MyAvg = SMA (Close, MyVarPeriod()[0])[0];
      and

      double MyVarPeriod = Math.Round(....,0);

      Is the conversion to integer the issue? The MyVarPeriod seems to be compiling fine

      Many thanks
      Last edited by bondcrash; 10-21-2011, 05:48 AM.

      Comment


        #4
        Yes, that's likely the case here, try casting that to an int :

        double MyAvg = SMA (Close, (int)MyVarPeriod()[0])[0];
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks a lot Bertrand - worked. Cheers!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          180 views
          0 likes
          Last Post jeronymite  
          Working...
          X