Lemrin

Awesome Oscillator with AntiStep Correction

Lemrin מעודכן   
Here is the well-known Awesome Oscillator (AO), which I use to present the real purpose of this post: a function that provides step correction for simple moving averages (SMAs).

We all know that any indicator based on moving averages lags real-time movement. Normally this is fine, but just after large ("step") changes in level, the pre-step values that are still within the SMA window cause the result to falsely reflect continued movement, even when real-time values remain flat.

To counter this, when a step change of a configurable size is detected, I temporarily shrink the SMA window size to include only those values occurring since the step change, and then allow the size to increase to normal length as we move away from the step change. This is accomplished within the antistep_sma() function.

Note that this will cause SMAs of different lengths (e.g. those used in the AO) to be temporarily equal, until the shorter of the two reaches its normal size and begins to leave the longer one behind again. You can see this above, where the AO, which is the difference of two SMAs, goes to 0 immediately after a sufficiently large step change--configured to 0.5% in this case.
הערות שחרור:
I have generalized all flavors of exponential moving average (you may create your own alpha using my function) and used it to implement anti-step versions of the TradingView EMA and RMA, in addition to the SMA from version 1.

Also, following a very good idea from Tracks, I added the option to base step detection on stochastic level (change the value from ~1% up to perhaps 50% for decent results). This still needs some work, though, so I am leaving that option disabled by default. Please feel free to toy with it, and let me know if you have any suggestions!
הערות שחרור:
Came up with an easier way to generalize step threshold for any tickerid or resolution.
Removed stochastic method.
סקריפט קוד פתוח

ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יכולים להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בסקריפ זה בגרף?