Announcement

Collapse
No announcement yet.

macd (simple average) highest...

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

  • macd (simple average) highest...

    Hi, this indicator calculates the highest value in the last 20 days macd (exponential moving average). I would like to calculate the highest value in the last 20 days macd (simple moving average). How can I do?
    Thank you very much for the help!

    Code:
    var bInit = false; 
    var xMacd = null; 
    var xHighMacd = null; 
    
    function main() { 
        if (bInit == false) { 
            xMacd = macd(3, 10, 15); 
            xHighMacd = highest(20, xMacd); 
            bInit = true; 
        } 
    
        return xHighMacd.getValue(0); 
    }

  • #2
    luca73
    You need to create your own oscillator since the macd() function uses only exponential averages. To do this create a separate function in your formula in which you calculate the difference between two simple moving averages. Then call that function from the main() function using the efsInternal() function. This will create a series that you can then pass to the highest() function [in the same way you are doing with the macd() function in your code example]
    For the description of the efsInternal() function see this article in the EFS KnowledgeBase. Also see this and this thread for more examples of its use.
    An alternative [and simpler] way is to use the Price Oscillator function I provide in this thread and pass that to the highest() function.
    Alex


    Originally posted by luca73 View Post
    Hi, this indicator calculates the highest value in the last 20 days macd (exponential moving average). I would like to calculate the highest value in the last 20 days macd (simple moving average). How can I do?
    Thank you very much for the help!

    Code:
    var bInit = false; 
    var xMacd = null; 
    var xHighMacd = null; 
    
    function main() { 
        if (bInit == false) { 
            xMacd = macd(3, 10, 15); 
            xHighMacd = highest(20, xMacd); 
            bInit = true; 
        } 
    
        return xHighMacd.getValue(0); 
    }

    Comment


    • #3
      Thank you very much for your help ...
      My knowledge of programming is very basic, as my English, but I have been able to solve the problem as you suggest:

      Code:
      function preMain() {
        
          setStudyTitle("HighSL")
          setCursorLabelName("Hsl",0);
          setPriceStudy(false);
          setDefaultBarFgColor(Color.blue,0);
          setDefaultBarThickness(1,0);
         
      
      } 
      
      var bInit       = false; 
      var xMacd       = null; 
      var xHighMacd   = null;
      
      function main() {
      
      if (bInit == false) { 
              xMacd = efsInternal("SL"); 
              xHighMacd = highest(20, xMacd); 
              bInit = true; 
          } 
      
          return (xHighMacd.getValue(0)); 
      }
      
      
      function SL()  {
      var xFast = sma(3);
      var xSlow = sma(10);
      
      return(xFast-xSlow);
        }
      Best regards,
      Luca

      Comment


      • #4
        Luca
        You are welcome
        FWIW if you are not returning the macd values to the chart then you can simplify your script and nest the efsInternal() call in the highest() function as shown in the following screenshot



        Also FWIW if you are running 11.6 you can achieve the same exact results without the need of an efs by using just the built-in studies.
        To do this you would first load the built-in MACD study [which you can set to use simple moving averages] and then using the study on study functionality you would load the built-in Donchian study basing it on the MACD. Once you have done that you can hide whatever plots you do not wish to see
        In the following screenshot the indicator in the top pane was created using only the built-in studies while the indicator on the bottom pane is the result of your script. As you can see the two are identical



        See this article in the eSignal KnowledgeBase for information on how to use the functionality I described above
        Alex


        Originally posted by luca73 View Post
        Thank you very much for your help ...
        My knowledge of programming is very basic, as my English, but I have been able to solve the problem as you suggest:

        Code:
        function preMain() {
          
            setStudyTitle("HighSL")
            setCursorLabelName("Hsl",0);
            setPriceStudy(false);
            setDefaultBarFgColor(Color.blue,0);
            setDefaultBarThickness(1,0);
           
        
        } 
        
        var bInit       = false; 
        var xMacd       = null; 
        var xHighMacd   = null;
        
        function main() {
        
        if (bInit == false) { 
                xMacd = efsInternal("SL"); 
                xHighMacd = highest(20, xMacd); 
                bInit = true; 
            } 
        
            return (xHighMacd.getValue(0)); 
        }
        
        
        function SL()  {
        var xFast = sma(3);
        var xSlow = sma(10);
        
        return(xFast-xSlow);
          }
        Best regards,
        Luca

        Comment

        Working...
        X