Announcement

Collapse
No announcement yet.

Multiple Moving Average Indicator

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

  • Multiple Moving Average Indicator

    Hi All Members,

    I work a lot with Moving Averages.

    I have tried to program a Study that plots - in one time - 5 Moving Averages - each one based on different Source, Length, Offset and Type).

    I worked on the base of the basicMAx2 code of Alexis C. Montenegro from ACM Test Group in Files Sharing.

    My code called 'Five MAs.efs' attached.

    The problem is : vMA3 not defined of referenced.

    Can any EFS Moderator help me ?

    If I could also choose different colors for each MA, it would be nice too.

    Thanks.

    Olivier - Belgium
    Attached Files

  • #2
    I beleive you need to add more info to this line...

    function main(MA1Length,MA1Offset,MA1Source,MA1Type,MA2Leng th,MA2Offset,MA2Source,MA2Type)

    add ma3, ma4 and ma5 info

    Change


    setDefaultBarFgColor(Color.blue, 1);

    to


    setDefaultBarFgColor(Color.red, 1); for coloring

    Comment


    • #3
      Made changes still not working

      Hi L. Doomis,

      Made suggested changes but still not working.

      Other ideas.

      Who can help ?

      Included modified code.

      Olivier
      Attached Files

      Comment


      • #4
        Olivier
        In line 196 you have an incorrect definition. You added M42Source instead of MA4Source
        That is why if you run a Syntax Check you will get an error in line 201 since the required MA4Source parameter is not defined. Once you fix that the efs will work correctly
        Alex

        Comment


        • #5
          Still not working after correction

          Dear Mr. Montenegro,

          Still not working after suggested syntax correction.

          Now, this is the MA4Source that seems to be not defined !

          Read my codes many times and not found anything incorrect.

          Can you help me again ?

          Code attached.

          Thank you.

          Olivier
          Attached Files

          Comment


          • #6
            Olivier
            You only partially corrected the prior error. In line 196 the definition is M4Source instead of MA4Source
            Alex

            Comment


            • #7
              Lasts enhancements needed

              Alexis,

              Thank you for your expertise.

              I would like to add a last enhancement.

              I would like to get the possibility in this study to move the 5 MAs of a certain percentage.

              So, for example if we take 5 %, as the mathematical result of EMA ( 20, (Close*1.05) ) is equal to EMA ( 20, Close ) *1.05 ;
              I only have to modify the last code line as follows :

              return new Array (vMA1.getValue(MAStudy.MA)*1.05, vMA2.getValue(MAStudy.MA)*1.05, vMA3.getValue(MAStudy.MA)*1.05, vMA4.getValue(MAStudy.MA)*1.05, vMA5.getValue(MAStudy.MA)*1.05);

              And it works as all displayed 5 MAs have moved by 5 %.

              But I would like more (2 code versions may be needed ?) :

              Version 1 :

              The possibility to choose the percentage manually for each of the 5 MAs when Editing the Study from the Study Properties Window.

              I have tried by creating a new NUMBER FUNCTION and insert this function value in place of 1.05 but it did not work.

              Version 2 :

              The possibility to base this percentage on 25%, 33%, 50%, 66%, 75 % or 100 % of the Average Daily Range (H+L/2) of the last 21 market days of the stock/indice displayed.

              Same idea : the possibility to choose one of the available percentages of the stock/indice ADR (21) manually for each of the 5 MAs when Editing the Study from the Study Properties Window.

              Waiting for your reply,

              Yours sincerely,

              Olivier
              Attached Files

              Comment


              • #8
                Olivier
                To make the percentage a user defined variable you need to first create a FunctionParameter. In the example shown in the following image I set the default to 1.05



                Once you have done that you need to add the definition of that parameter to the main() definition



                Replace the percentage value in the return statement with the variable name.



                At that point you can modify the value through Edit Studies. If you need each average to have its own percentage repeat the above process as many times as necessary giving each variable its unique name
                Alex

                Comment


                • #9
                  Version 2 ?

                  Thank you Alexis.

                  Done as you suggested and it works.

                  Now how can I intergrated my version 2 by :

                  1. Calculating different ADR(21) of the stock or index displayed.

                  2. Calculate adequate percentages of the ADR(21).

                  3. Integrate these in the MAPercent values.

                  Version 2 :

                  The possibility to base this percentage on 25%, 33%, 50%, 66%, 75 % or 100 % of the Average Daily Range (H+L/2) of the last 21 market days of the stock/indice displayed.

                  Same idea : the possibility to choose one of the available percentages of the stock/indice ADR (21) manually for each of the 5 MAs when Editing the Study from the Study Properties Window.

                  Waiting for your reply,

                  Yours sincerely,

                  Olivier

                  Comment

                  Working...
                  X