Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Trend detection function for Amibroker (AFL)

Rating:
3 / 5 (Votes 5)
Tags:
amibroker, trend, function

This AFL function Trend(Price,Length) checks if there is trend in given number of data bars in the array. Returns 1 for increasing trend, -1 for decreasing and 0 for none. Uses Mann-Kendall method and detects trend with 95% probability

Similar Indicators / Formulas

Percent Rank
Submitted by genkumag almost 13 years ago
Trend Following Indicator
Submitted by trek over 14 years ago
PROFIT TRADING SYSTEM
Submitted by Muralikrishna over 11 years ago
Adaptive Laguerre Filter from John Ehlers
Submitted by kaiji almost 15 years ago
Time Left for each bar
Submitted by novicetraders over 14 years ago
Vertical Horizontal Filter
Submitted by mahesh.aranake over 14 years ago

Indicator / Formula

Copy & Paste Friendly
function Trend(Price,Length) {

	Result = 0;

	

	for (k=Length;k<BarCount;k++) {

		S = 0;

		for (i=k-Length+1;i<k;i++) {			
			for (j=k-Length;j<i-1;j++) {
				Signum = sign(Price[i]-Price[j]);
				S += Signum;
			}			
		}
		
		Variance =( Length*(Length-1.0)*(2*Length+5.0))/18.0;		
		StdDev = sqrt(Variance);

		zScore = 0;
		if (S >= 0) {
			zScore=((S-1)/StdDev);
		}else {
			zScore=(S+1)/StdDev;
		}

		Result[k] = 0; //0- no trend, -1 - decreasing trend, 1 - increasing trend

		isTrend = False;
		if ((zScore>=1.65)||(zScore<=-1.65)) { 
			isTrend=True;
		}

		if (isTrend)	{		
			if (S<0){
				Result[k] = -1;
			}else {
				Result[k] = 1;
			}
		}

	}

	return Result;
}

13 comments

1. anandnst

THIS AFL IS NOT WORKING IN 5.4 AMIBROKER

2. rajagopal_ctr

AFL is not working

3. sam21

YUP Afl is not working…though no error but nothing is displayed in Price chart

4. morgen

Hei ISOZAKI!
Explain that!
Or delete!

5. halfman

How come this get 3 stars whereas it’s not working?

6. wisewisely

Hey, this is good, thanks a lot
For the others complaining about the script, this is just a function, you need to add your own statement.

7. morgen

wisewisely, be so kind, please, explain how “to add your own statement”.
With an example, please.

8. JaNa

You complaining guys are so dumb it’s unbelievable. Learn AFL before complaining!! Jesus Christ.

9. investor_tr
_SECTION_BEGIN("Mann-Kendall");
Length= Param( "Period", 21, 5, 200, 1 ); 
function Trend(Price,Length) {
 Price=C;
    Result = 0;
 
     
 
    for (k=Length;k<BarCount;k++) {
 
        S = 0;
 
        for (i=k-Length+1;i<k;i++) {         
            for (j=k-Length;j<i-1;j++) {
                Signum = sign(Price[i]-Price[j]);
                S += Signum;
            }           
        }
         
        Variance =( Length*(Length-1.0)*(2*Length+5.0))/18.0;       
        StdDev = sqrt(Variance);
 
        zScore = 0;
        if (S >= 0) {
            zScore=((S-1)/StdDev);
        }else {
            zScore=(S+1)/StdDev;
        }
 
        Result[k] = 0; //0- no trend, -1 - decreasing trend, 1 - increasing trend
 
        isTrend = False;
        if ((zScore>=1.65)||(zScore<=-1.65)) { 
            isTrend=True;
        }
 
        if (isTrend)    {       
            if (S<0){
                Result[k] = -1;
            }else {
                Result[k] = 1;
            }
        }
 
    }
 
    return Result;
}
Plot(C,"",colorRed,styleCandle);
Plot(Trend(C,Length),"",colorRed,styleLine+styleThick|styleOwnScale);
_SECTION_END();
10. kuzukapama

incorrect formula ( this afl ) does not work

11. isozaki

Thanks investor_tr for making this an indicator. I din’t add this 3 lines, thought it was obvious, sorry.

12. morgen

JaNa !
“Thank You kindly for your precious help!”

13. ole

Very nice. Thanks.

Leave Comment

Please login here to leave a comment.

Back