Announcement

Collapse
No announcement yet.

EFS Studies

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Triple3
    There are several ways a signal line can be added. The easiest way is to create a new efs in which you use the efsExternal() function to call the efs you just posted. The efsExternal() function calls that efs and creates a series which you can then use as the data source for the moving average function.
    Here is an example in its simplest form together with some comments. At this time to simplify things make sure that you save this efs in the same folder in which you have stored the one you posted.

    PHP Code:
    function preMain(){
        
    setPriceStudy(false);
        
    setStudyTitle("TDI with MA");
        
    setCursorLabelName("TDI",0);
        
    setCursorLabelName("MA",1);
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarFgColor(Color.red,1);
    }

    function 
    main(){
        
    //the following line calls the separate function and creates the series object
        
    var myStudy efsExternal("yourEFS.efs");//replace "yourEFS.efs" with the actual name of the efs

        //the following line creates a simple moving average of length 3 using myStudy as the source
        
    var myStudyAvg sma(3myStudy);

        return new Array (
    myStudymyStudyAvg);

    An alternative method is to use the efsInternal() function instead. The code is very similar to what is shown above with the exception that the two scripts are combined in a single formula. See the following example that includes some comments

    PHP Code:
    //the first part of the formula is virtually identical to the one shown above
    function preMain(){
        
    setPriceStudy(false);
        
    setStudyTitle("TDI with MA");
        
    setCursorLabelName("TDI",0);
        
    setCursorLabelName("MA",1);
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarFgColor(Color.red,1);
    }

    function 
    main(){
        
    //the following line calls the separate function and creates the series object
        
    var myStudy efsInternal("calcTDI");//this now calls a function in this same script

        //the following line creates a simple moving average of length 3 using myStudy as the source
        
    var myStudyAvg sma(3myStudy);

        return new Array (
    myStudymyStudyAvg);
    }

    //from the original formula I copy only the main function and whatever variables
    //are required.

    mom null;

    function 
    calcTDI(Period){//notice I renamed the function from main to calcTDI

        
    if(Period == null)
        
    Period 12;
        if(
    mom == nullmom = new MOMStudy(Period"Close");

        var 
    MomSum 0MomSumAbs 0MomAbsSum 0MomAbsSum2 0;

        for(
    = -Period 1i++; <= 0)
            
    MomSum += mom.getValue(MOMStudy.MOM,i);

        
    MomSumAbs Math.abs(MomSum);

        for(
    = -Period 1i++; <= 0)
            
    MomAbsSum += Math.abs(mom.getValue(MOMStudy.MOM,i));

        for(
    = -Period 1i++; <= 0)
            
    MomAbsSum2 += Math.abs(mom.getValue(MOMStudy.MOM,i));
            
    TDI MomSumAbs - (MomAbsSum2 MomAbsSum);

        return 
    TDI;

    In the following image you can see the result of either of these two methods



    For information on the efsExternal() and efsInternal() functions and their syntax see the links included earlier. For further details on the functions and sevaral examples see this thread.

    Enclosed is a complete script (that uses efsInternal()) where all the parameters are user adjustable.
    The script is also enabled for use with multiple time frames and or external symbols. All parameters can be edited through Edit Studies.
    Alex
    Attached Files

    Comment

    Working...
    X