Announcement

Collapse
No announcement yet.

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];

    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];

        Comment


          #5
          Thanks a lot Bertrand - worked. Cheers!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X