Announcement

Collapse
No announcement yet.

Need Angle of Moving Average

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

  • Need Angle of Moving Average

    What is the best method to calculate the angle/trend of a moving average? Basically I want to keep my efs from taking longs when the 8EMA is angled downwards. Thx!


    Geoff

  • #2
    Geoff
    An easy way to do that would be to calculate the slope ie (currentMA/prevMA)-1 and if the slope is greater than 0 the average is rising. Enclosed is a basic example of how you could do it.
    Alex

    PHP Code:
    function preMain(){
        
    setPriceStudy(true);
        
    setShowCursorLabel(false);
    }
     
    var 
    Avg null;
     
    function 
    main(){
     
        if(
    Avg==nullAvg sma(8);
     
        if(
    Avg.getValue(-1)==null) return;
     
        var 
    Slope = (Avg.getValue(0)/Avg.getValue(-1))-1;
     
        if(
    Slope>0setBarBgColor(Color.lime);
     
        return 
    Avg.getValue(0);

    Comment


    • #3
      Willis

      Thats what I'm talking about! Thanks. I'm going to incorporate that in to one of my scripts. This is nice. It allows you to 'wait' for pullbacks for longs..

      Comment

      Working...
      X