Adaptive Lookback period
Author: Eugene
Creation Date: 3/6/2009 3:57 AM
profile picture

Eugene

#1
We've set up a page illustrating an interesting technique that can turn many a traditional, fixed-period indicator into a dynamic, adaptive one -

with the help of the Adaptive Lookback period finder (already available in Community.Indicators).
profile picture

Yury

#2
QUOTE:
With the fastSwing option enabled, it takes two consecutive bars before the swing point and just one after - for faster detection

CODE:
Please log in to see this code.

I think this code is necessary to alter the following:
CODE:
Please log in to see this code.

Here's the code to check
CODE:
Please log in to see this code.
profile picture

Eugene

#3
I appreciate your suggestion Yury. However, I believe I've made a mistake in the documentation which should sound like this:
QUOTE:
(With the ''fastSwing'' option enabled, it takes just one bar before the swing point and just one after - for faster detection).

Thanks for the heads-up.
profile picture

Yury

#4
QUOTE:
(With the ''fastSwing'' option enabled, it takes just one bar before the swing point and just one after - for faster detection).

For such variant would be the code
CODE:
Please log in to see this code.
profile picture

Eugene

#5
You're right, I stand corrected. The only difference in my version vs. yours is that my version can detect a swing high condition when two highs are equal, and a swing low when two lows are equal.

CODE:
Please log in to see this code.


I'm grateful to you for spotting the inconsistency. While your version is precise, but I also like how my rendition catches some swings missed by your formula.

Therefore for now, let's fix the documentation as follows:

QUOTE:
With the fastSwing option enabled, it takes two consecutive bars before the swing point and just one after - for faster detection. The high of the bar preceding a swing high or the low of the bar preceding a swing low can be equal to the swing bar's high/low, respectively.


I'll add a new parameter to the fast swing calculation (e.g. "preciseDetection") that will implement your version.

Thanks again.
profile picture

Yury

#6
I think that in this version it's all right.
profile picture

Eugene

#7
Version 2013.01 of Community Indicators brings two optional overloaded method calls:

* Added new overload for parameterless adaptive lookback. For more info see the Wiki online reference.
* Added new overload for precise swing detection to accompany the "fastSwing" constructor (thanks Yuriy)
profile picture

EJoub

#8
In summary I need the volatility to trade every day but with short ( say 5 days up or or down trends) my strategy does not enter or cannot exit.

QUOTE:
This makes the variable lookback period grow in calm or trending markets, and shorten in range-bound and volatile markets. For a trend-following system you would like the opposite to prevent being whipsawed, therefore this indicator is more suitable for short-term traders and counter-trend systems.


Does this mean that if I'm short term (every day) /counter-trend trader and the markets trends for a few days, that I would remain in the trend longer after an entry for a higher exit price? Normally in a short uptrend my system doesn't enter because I must get a good down day.

What about te reverse of above, the lookback is longer if short down trends occur after an entry, and my strategy cannot exit quickly.


QUOTE:
This example illustrates how to construct and plot the "traditional" Adaptive RSI indicator. The lookback period is based on the Adaptive Lookback readings. This technique can be easily applied to other indicators such as price channels and oscillators.


How about an example of a price channels breakout strategy?...and some entry and exit rules would make it testable.

BTW Should your code in the Wiki example produce the curves shown?...I don't get curves only errors.



profile picture

Eugene

#9
QUOTE:
How about an example of a price channels breakout strategy?...and some entry and exit rules would make it testable.

There is a bands strategy published in Active Trader Magazine. You can find it among the uploaded strategies.
QUOTE:
BTW Should your code in the Wiki example produce the curves shown?...I don't get curves only errors.

Undoubtedly the sample code works. If you need assistance, be specific regarding the error messages.
profile picture

EJoub

#10
QUOTE:
"Undoubtedly the sample code works. If you need assistance, be specific regarding the error messages."

It is working now thanks.

I woul like to test one of my strategies using this parameterless lookback but I have no idea on how to integrate the two. That is why I have asked the questions in my previous post...it seems too slow to react/adapt considering that I only have EOD price feeds for backtesting.
A helping hand would be appreciated if and when you have time.
profile picture

Eugene

#11
As you could have read on the Wiki page, it was not meant for "integrating into a strategy". The purpose is to make an indicator adaptive. So, if your strategy has an indicator that seems slow to react and might benefit from making it adaptive, then the code examples there are precisely to illustrate how would one integrate Adaptive Lookback into a traditional indicator's formula like RSI.

This also applies to the example of a price channel breakout strategy you requested above. You'll have to do some basic howework to get it done. Price channels are constructed using Highest and Lowest. Again, see the Wiki for their syntax and usage examples. On how to work with
DataSeries, please re-read the WealthScript Programming Guide > DataSeries. Hope that helps.
profile picture

EJoub

#12
QUOTE:
"This makes the variable lookback period grow in calm or trending markets, and shorten in range-bound and volatile markets"


I had above in mind. This means in a volatile market I enter on day 1 and exit on day 2 or 3 or 4. In a calm or trending market I may exit on day 5 or 6 or 7 etc because of the longer lookback in calm/trending periods. I'll have another look, at the graphs this time. Thanks.
profile picture

Eugene

#13
This is a reasonable objective. Here's the code:

CODE:
Please log in to see this code.


Below is an example of price channels made adaptive:

CODE:
Please log in to see this code.


P.S. One thing to keep in mind that the adaptive lookback typically 'oscillates' from 2 to 20. It wasn't meant for trading longer-term systems.
profile picture

EJoub

#14
Thanks for all the assistance. I haven't studied the codes above...I'll do that ASAP.

My first problem re the topic before I proceed. Can the code/ indicator I have in mind benefit from and be modified with the Adaptive Lookback? I obviously lack insight. Theoretically it should be possible...I think. Herewith my code.

CODE:
Please log in to see this code.
profile picture

Eugene

#15
Take a careful look at my code posted earlier today, and don't hesitate playing with the examples and modifying them. The concept is so simple and well illustrated, so I don't see any reason for lack of insight.
profile picture

EJoub

#16
Thanks, you have answered my last question before I have asked it... when you offered the example codes.
Sorry for the long delay. I'll be back as soon as possible..
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).