Australian (ASX) Stock Market Forum

Trend Detection Indicator

Joined
9 July 2006
Posts
193
Reactions
0
Hi all,

Just looking for some assistance with the formulation of an indicator which shows when a chart is in an uptrend, in a horizontal trading range or in a down trend.

Just looking at a chart, these different zones are obvious, but coding an indicator is a little more tricky. When you overlay a 200day MA over the chart, it becomes clearer again. So I figured if I could calculate the slope of the MA, it will give me the answer, ie a slope of 0 - means flat trading range, positive slope means uptrend and negative slope means downtrend. I had very limited success with the linregslope function and have not been happy with the results. Just curious as to what the others use for this purpose.
 
Hi bingk6, I'm looking for the same thing. Some indicators I've found on the web :

Average Peak Excursion

(Incidentally, if you simply change the month/year on the web address above, you can trawl through about 8 years of monthly amibroker/tradestation/etc. indicators)

Vertical Horizontal Filter

I haven't had a good look at them yet, tho - For now I've been filtering stocks using a very simplistic rate of change. I'm not keen on wading through piles of stocks that are on an ever downward slope, so I simply check that the rate of change is at least +20% over the last year.

Let me know if you find some others!
 
Just looking at a chart, these different zones are obvious, but coding an indicator is a little more tricky.

How are these zones obvious? If you can "see" them, you can code them.

Don't get stuck on the one idea, like using MA etc. You will probably have to combine many different bits of code together to achieve the right results.

Listen very closely to what your eyes and brain are telling you when you look at a chart. Try looking at a chart for five seconds then close your eyes and tell yourself what the chart is doing and how you came to that conclusion. Then code up your ideas, test and refine.


wabbit :D
 
How are these zones obvious? If you can "see" them, you can code them.

Don't get stuck on the one idea, like using MA etc. You will probably have to combine many different bits of code together to achieve the right results.

Listen very closely to what your eyes and brain are telling you when you look at a chart. Try looking at a chart for five seconds then close your eyes and tell yourself what the chart is doing and how you came to that conclusion. Then code up your ideas, test and refine.


wabbit :D

KISS
 
This is an AFL for trend detection/direction using a 140, 60 and 8 period MA.
1) find stock in trend 2) assess chart/apply further analysis 3) make decision.
Also available at the website.
 

Attachments

  • Trend Search .txt
    3.4 KB · Views: 262
Wysiwyg,

Nice code, love some of the comments, lol.

How do you apply this code, as it just brings up every stock in the watchlist you are scanning?

Do you filter it someway? Or just quickly scan every stock in a trend?
 
Here is what I use as a trend filter. It is FrankD's channels.

Keep in mind these channels are worked out as the last trading day of each time frame is completed and then projected forward before the next trading period begins.

1st chart is monthly channels.
2nd chart is weekly & monthly together.
3rd is monthly zoomed out.

The arrows are not buy or sell signals - only alert signals.
 

Attachments

  • Sample.png
    Sample.png
    16.3 KB · Views: 35
  • Sample (2).png
    Sample (2).png
    18.3 KB · Views: 25
  • Sample (3).png
    Sample (3).png
    18.1 KB · Views: 27
Wysiwyg,

Nice code, love some of the comments, lol.

How do you apply this code, as it just brings up every stock in the watchlist you are scanning?

Do you filter it someway? Or just quickly scan every stock in a trend?
Only found the code 19 days ago myself and I`m new to Amibroker too. Perhaps removing some code so only the up trending stock are displayed would work. I don`t know code. I open the up trending chart and make an assessment on my perceived trend longevity, look for patterns, certain candles, liquidity (though not overly important) and if there is promise I peruse the company fundamentals.
 
Only found the code 19 days ago myself and I`m new to Amibroker too. Perhaps removing some code so only the up trending stock are displayed would work. I don`t know code. I open the up the trending chart and make an assessment on my perceived trend longevity, look for patterns, certain candles, liquidity (though not overly important) and if there is promise I peruse the company fundamentals.

Ok thanks, was just curious.

I'm sure you could refine the code to narrow it down for you but instead of removing something from the code it might be better to add a basic buy signal when all 3 MA's are in an up trend and then run it through the scan function instead of the explore function, this should bring up all the strong up trends. This might remove the comments though and only come up buy/sell. Might play around with it if I get time this weekend(probably unlikely though).
 
Try googling
"Trend direction & force index (TDF Index)"
and see if this indicator meets your needs. There are metastock and amibroker codes available at least. Seems to work well on a weekly time scale for me but you may need to tune it depending on your personal trading habits.
 
Here is what I use as a trend filter. It is FrankD's channels.

Keep in mind these channels are worked out as the last trading day of each time frame is completed and then projected forward before the next trading period begins.

1st chart is monthly channels.
2nd chart is weekly & monthly together.
3rd is monthly zoomed out.

The arrows are not buy or sell signals - only alert signals.

Any chance that you could post the code for that? Or do you know where I can get the code from?
 
Im also having trouble making some code for Amibroker so that I can make a buy condition that suits the following.

Buy when the slope of a moving average is at a % gradient pointing up. Ive tried having a reference to the moving average being greater than it was 2 days ago but it doesnt really help . Even a minor rise makes it buy.

I really want it to be related to the slope of the moving average. I think there is a slope function in amibroker but I have no idea how to do it.

Can anyone please help me

Thanks
:banghead::confused:
 
Buy when the slope of a moving average is at a % gradient pointing up. Ive tried having a reference to the moving average being greater than it was 2 days ago but it doesnt really help . Even a minor rise makes it buy.

I really want it to be related to the slope of the moving average. I think there is a slope function in amibroker but I have no idea how to do it.

Can anyone please help me

Thanks
:banghead::confused:
Try using a rising RSI or Stochastic slope on normal range. So you have a long EMA maybe 100 or 200 to get a trend and a short range indicator to narrow the field down again. Here is a basic for exploration mode.

PHP:
TS = TSF(C,200) > Ref(TSF(C,200), -5);
DE = DEMA(C,100) > Ref(DEMA(C, 100), -5);
ST = StochD(15) > Ref(StochD(15), -1);
SB = StochD(15) < 30;

Buy = TS && DE && ST && SB;
Sell = 0;

Filter = Buy;
AddColumn(Buy, "BUY CHECK", 1.2, 29, 54, -1);
 
Im also having trouble making some code for Amibroker so that I can make a buy condition that suits the following.

Buy when the slope of a moving average is at a % gradient pointing up. Ive tried having a reference to the moving average being greater than it was 2 days ago but it doesnt really help . Even a minor rise makes it buy.

I really want it to be related to the slope of the moving average. I think there is a slope function in amibroker but I have no idea how to do it.

Can anyone please help me

Thanks
:banghead::confused:

The gradient problem is a fair problem because you have no frame of reference, If you adjust from 5min to 10min the gradient halves. Using a longer MA will be deceptive because if the underlying trends well, that MA will have a decent gradient.
 
For EOD exploration and using a long moving average. The problem with the long MA is the share price can be on it's way down before the long MA starts to decline. However, issues with this exploration can be chopped at discretion.

You may want to move away from a MA as trending tool but most tools have their use.

PHP:
DE = DEMA(C, 200) > Ref(DEMA(C, 200), -1);
SH = StochK() > 20; 
SL = StochK() < 30;
SU = StochK() > Ref(StochK(), -1);

Buy = DE && SH && SL && SU;
Sell = 0;

Filter = Buy;
AddColumn(Buy, "Let's Rock", 1.2, 24, 43, -1);
 
Thanks for that. That helped heaps.

Im finding AFL writing very hard even with the wizard.

Can someone please tell me how to code this.

Buy = 2 consecutive closes above an EMA

Sell = 2 consecutive closes below an EMA

I tried this but it didnt work.

Buy = Close > Ref( EMA( Close , 20 ) , -2 );


It is price related and not number of bars.





If I can push my luck a little could someone also please tell me why this gives me 2 buy signals 1 day apart. I want it to buy when price is above the 20 day SMA and the SMA is pointing up. Ive spent hours on this and I really need some help.

http://i409.photobucket.com/albums/pp175/pennies_08/20 SMA/20SMA.png



Range1=Optimize("range1",20,20,50,1);


Buy = Close > Ref( MA( Close , Range1 ) , -2 )
AND MA( Close , 20 ) > Ref( MA( Close , 20 ) , -1 ) ;


Sell = MA( Close , 20 ) < Ref( MA( Close , 20 ) , -2 ) ;


Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);


Thank you:)
 
Top