Announcement

Collapse
No announcement yet.

Calculating the High from a MA Study

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

  • Calculating the High from a MA Study

    I would like to calculate the delta on a bar daly bar chart.The calculation should be the distance from todays high to a given line. For testing the system I will use the 10 day moving average line. Any ideas?

  • #2
    Here is some help..

    First...

    open an EFS EDITOR window (TOOLS, EFS, EDITOR), then click on the OPEN FORMULA button...

    Now, open the BuiltinMA.efs (located in the BUILTIN folder). This is a basic Moving Average formula. It will look like this..

    PHP Code:
    /*********************************************************
    Alexis C. Montenegro © July 2003                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      
    **********************************************************/

    var vMA null;

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("MA");
        
    setCursorLabelName("MA"0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(1,0);
            
        var 
    fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(10); //Edit this value to set a new default
        
        
    var fp2 = new FunctionParameter("Offset"FunctionParameter.NUMBER);
        
    fp2.setDefault(0); //Edit this value to set a new default
        
        
    var fp3 = new FunctionParameter("Source"FunctionParameter.STRING);
        
    fp3.setName("Source");
        
    fp3.addOption("Close");
        
    fp3.addOption("High");
        
    fp3.addOption("Low");
        
    fp3.addOption("Open");
        
    fp3.addOption("HL/2");
        
    fp3.addOption("HLC/3");
        
    fp3.addOption("OHLC/4");
        
    fp3.setDefault("Close"); //Edit this value to set a new default    
        
        
    var fp4 = new FunctionParameter("Type"FunctionParameter.STRING);
        
    fp4.setName("Type");
        
    fp4.addOption("MAStudy.SIMPLE");
        
    fp4.addOption("MAStudy.EXPONENTIAL");
        
    fp4.addOption("MAStudy.WEIGHTED");
        
    fp4.addOption("MAStudy.VOLUMEWEIGHTED");
        
    fp4.setDefault("MAStudy.SIMPLE"); //Edit this value    to set a new default

    }

    function 
    main(Length,Offset,Source,Type) {
       
        if (
    vMA == nullvMA = new MAStudy(LengthOffsetSource, eval(Type));
     
    /*****************************************
    Insert your code following this text block
    Use vMA.getValue(MAStudy.MA) for your code
    ******************************************/

        
        
    return vMA.getValue(MAStudy.MA);

    Now, comparing the recent high to the MA value is as simple as adding one line.

    PHP Code:
    var HighfromMA high()-vMA.getValue(MAStudy.MA); 
    you would add it here (for most uses).

    PHP Code:
    /*********************************************************
    Alexis C. Montenegro © July 2003                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      
    **********************************************************/

    var vMA null;

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("MA");
        
    setCursorLabelName("MA"0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(1,0);
            
        var 
    fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(10); //Edit this value to set a new default
        
        
    var fp2 = new FunctionParameter("Offset"FunctionParameter.NUMBER);
        
    fp2.setDefault(0); //Edit this value to set a new default
        
        
    var fp3 = new FunctionParameter("Source"FunctionParameter.STRING);
        
    fp3.setName("Source");
        
    fp3.addOption("Close");
        
    fp3.addOption("High");
        
    fp3.addOption("Low");
        
    fp3.addOption("Open");
        
    fp3.addOption("HL/2");
        
    fp3.addOption("HLC/3");
        
    fp3.addOption("OHLC/4");
        
    fp3.setDefault("Close"); //Edit this value to set a new default    
        
        
    var fp4 = new FunctionParameter("Type"FunctionParameter.STRING);
        
    fp4.setName("Type");
        
    fp4.addOption("MAStudy.SIMPLE");
        
    fp4.addOption("MAStudy.EXPONENTIAL");
        
    fp4.addOption("MAStudy.WEIGHTED");
        
    fp4.addOption("MAStudy.VOLUMEWEIGHTED");
        
    fp4.setDefault("MAStudy.SIMPLE"); //Edit this value    to set a new default

    }

    function 
    main(Length,Offset,Source,Type) {
       
        if (
    vMA == nullvMA = new MAStudy(LengthOffsetSource, eval(Type));
     
    /*****************************************
    Insert your code following this text block
    Use vMA.getValue(MAStudy.MA) for your code
    ******************************************/

    var HighfromMA high()-vMA.getValue(MAStudy.MA);

        
        return 
    vMA.getValue(MAStudy.MA);


    Now, if you wanted to SUM the values for multiple bars, you would have to create a function (the most logical way to handle this...

    PHP Code:
    function GetMAHighValue(length) {
    var 
    x;
    var 
    MAHighSum 0;

       for(
    x=0;x<(length-1);x++) {
         
    MAHighSum += high(-x)-vMA.getValue(MAStudy.MA,-x);
       }
     return 
    MAHighSum;

    You would use this function as shown here..

    PHP Code:
    /*********************************************************
    Alexis C. Montenegro © July 2003                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.                      
    **********************************************************/

    var vMA null;

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("MA");
        
    setCursorLabelName("MA"0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(1,0);
            
        var 
    fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(10); //Edit this value to set a new default
        
        
    var fp2 = new FunctionParameter("Offset"FunctionParameter.NUMBER);
        
    fp2.setDefault(0); //Edit this value to set a new default
        
        
    var fp3 = new FunctionParameter("Source"FunctionParameter.STRING);
        
    fp3.setName("Source");
        
    fp3.addOption("Close");
        
    fp3.addOption("High");
        
    fp3.addOption("Low");
        
    fp3.addOption("Open");
        
    fp3.addOption("HL/2");
        
    fp3.addOption("HLC/3");
        
    fp3.addOption("OHLC/4");
        
    fp3.setDefault("Close"); //Edit this value to set a new default    
        
        
    var fp4 = new FunctionParameter("Type"FunctionParameter.STRING);
        
    fp4.setName("Type");
        
    fp4.addOption("MAStudy.SIMPLE");
        
    fp4.addOption("MAStudy.EXPONENTIAL");
        
    fp4.addOption("MAStudy.WEIGHTED");
        
    fp4.addOption("MAStudy.VOLUMEWEIGHTED");
        
    fp4.setDefault("MAStudy.SIMPLE"); //Edit this value    to set a new default

    }

    function 
    main(Length,Offset,Source,Type) {
       
        if (
    vMA == nullvMA = new MAStudy(LengthOffsetSource, eval(Type));
     
    /*****************************************
    Insert your code following this text block
    Use vMA.getValue(MAStudy.MA) for your code
    ******************************************/

    var HighfromMA GetMAHighValue(5);

        
        return 
    vMA.getValue(MAStudy.MA);
    }



    function 
    GetMAHighValue(length) {
    var 
    x;
    var 
    MAHighSum 0;

       for(
    x=0;x<(length-1);x++) {
         
    MAHighSum += high(-x)-vMA.getValue(MAStudy.MA,-x);
       }
     return 
    MAHighSum;

    Brad Matheny
    eSignal Solution Provider since 2000

    Comment

    Working...
    X