Announcement

Collapse
No announcement yet.

MAStudy and array custom

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

  • MAStudy and array custom

    Hi,
    I've a question
    Example:

    function main() {
    var my1= new Array();
    var my2= new Array();
    var my3= new Array();

    var AAclose = close(0);
    var AAopen = open(0);

    my1 = AAclose*0.2;
    my2 = AAOpen *0.2;
    my3 = my1 - my2;

    How to calcolate the moving average of "my3" variable???

    The code not work:
    var myav = new MAStudy(12, 0, my3.getValue(0), MAStudy.EXPONENTIAL);


    return myav;
    }
    Last edited by micman2; 02-06-2009, 06:15 AM.

  • #2
    Hi micman2 ,

    Try this:

    PHP Code:

    function preMain(){
        
    setPriceStudy(false);
    }

    function 
    main() {

        
    vAvg efsInternal("fAvg");
        
    myav ema(12vAvg);

        return 
    myav;
    }

    function 
    fAvg(){
        return (
    close(0)*0.2)-(open(0)*0.2);

    wayne
    Last edited by waynecd; 02-09-2009, 09:51 PM.

    Comment


    • #3
      Re: MAStudy and array custom

      micman
      The reason the following line of code of your script
      var myav = new MAStudy(12, 0, my3.getValue(0), MAStudy.EXPONENTIAL);
      is not working is because the MAStudy() function can only accept the OHLCV price series or another [legacy] study as the source. It cannot use a custom variable as the source
      The solution is to use the efs2 moving average functions. These can accept a custom variable as a source as long as it is a series object.
      In order to create the series object you need to calculate your custom variable in a separate function [within the same efs] or in a separate efs and then call the function using the efsInternal() function or call the efs using the efsExternal() function. For the description and syntax of these functions see the links to the corresponding articles in the EFS KnowledgeBase which also include some basic examples of their use. You can find other examples in this thread which also describes in depth their functionality and in this thread which also provides examples on how to create studies on studies and studies based on custom sources.
      The efsInternal() and efsExternal() functions will create the series object that you can then use as a source for any of the built-in studies or any other study created by you
      The example waynecd posted uses the method of creating a separate function within the same efs and then calling that function using the efsInternal() function. This then allows him to use that custom variable as the source for the ema() function (see the link to the EFS KnowledgeBase article for the description and syntax of this function)
      Alex


      Originally posted by micman2
      Hi,
      I've a question
      Example:

      function main() {
      var my1= new Array();
      var my2= new Array();
      var my3= new Array();

      var AAclose = close(0);
      var AAopen = open(0);

      my1 = AAclose*0.2;
      my2 = AAOpen *0.2;
      my3 = my1 - my2;

      How to calcolate the moving average of "my3" variable???

      The code not work:
      var myav = new MAStudy(12, 0, my3.getValue(0), MAStudy.EXPONENTIAL);


      return myav;
      }

      Comment


      • #4
        thanks you!

        Comment

        Working...
        X