TradingView
LucF
22 kwi 2019 11:39

5 MAs w. alerts [LucF] 

S&P 500SP

Opis

Is this gazillionth MA indicator worth an addition to the already crowded field of contenders? I say yes! This one shows up to 5 MAs and 6 different marker conditions that can be used to create alerts, among many other goodies.

Features
  • MAs can be darkened when they are falling.
  • MAs from another time frame can be displayed, with the option of smoothing them.
  • Markers can be filtered to Longs or Shorts only.
  • EMAs can be selected for either all or the two shortest MAs.
  • The background can be colored using any of the marker states except no. 3.
  • Markers are:
  • 1. On crosses between any two user-defined MAs,
  • 2. When price is above or below an MA,
  • 3. On Quick Flips (a specific setup involving a cross, multiple MA states and increasing volume, when available),
  • 4. When the difference between two MAs is within a % of its high/low historic values,
  • 5. When an MA has been rising/falling for n bars,
  • 6. When the difference between two MAs is greater than a multiple of ATR.

Some markers use similar visual cues, so distinguishing them will be a challenge if they are used concurrently.

Alerts
Alerts can be created on any combination of alerts. Only non-consecutive instances of markers 5 and 6 will trigger the alert condition. Make sure you are on the interval you want the alert to run at. Using the “Once Per Bar Close” trigger condition is usually the best option.

When an alert is created in TradingView, a snapshot of the indicator’s settings is saved with the alert, which then takes on a life of its own. That is why even though there is only one alert to choose from when you bring up the alert creation dialog box and choose “5 MAs”, that alert can be triggered from any number of conditions. You select those conditions by activating the markers you want the alert to trigger on before creating the alert. If you have selected multiple conditions, then it can be a good idea to record a reminder in the alert’s message field. When the alert triggers, you will need the indicator on the chart to figure out which one of your conditions triggered the alert, as there is currently no way to dynamically change the alert’s message field from within the script.

Background settings will not trigger alerts; only marker configurations.

Notes
MAs are just… averages. Trader lure would have them act as support and resistance levels. I’m not sure about that, and not the only one thinking along these lines. Adam Grimes has studied moving averages in quite a bit of detail. His numbers point to no evidence indicating they act as support/resistance, and to specific MA lengths not being more meaningful than others. His point of view is debated by some—not by me. Mean reversion does not entail that price stops when it reaches its MA; rather, it makes sense to me that price would often more or less oscillate around its MA, which entails the MA does not act as support/resistance. Aren’t the best mean reversion opportunities when price is furthest away from its MA? If so, it should be more profitable to identify these areas, which some of this indicator’s markers try to do.

I think MAs can be much more powerful when thought of as instruments we can use to situate price events in contexts of various resolutions, from the instantaneous to the big picture. Accordingly, I use the relative positions and slopes of MAs in both discretionary and automated trading; but never their purported ability to support/resist.

Regardless of how you use MAs, I hope you will find this indicator useful.

Biased References
The Art and Science of Technical Analysis: Market Structure, Price Action, and Trading Strategies, Adam Grimes, 2012.
Does the 200 day moving average “work”?
Moving averages: digging deeper

Informacje o Wersji



Converted to v4.
For each of the 5 MAs, added independent choice of:
- 9 different MA types: SMA, EMA, RMA, WMA, KAMA, VWMA, ALMA, Lin Reg, HMA.
- Higher timeframe selection
- Source
You have the possibility of smoothing higher timeframe MAs.
You can choose to have higher timeframe MAs repaint or not.
You can choose to have high markers in green or red for the markers that plot dots above/below price or on MAs.

Chart shows a 5 and 15 EMA with 50, 200 and 400 KAMAs. The background is colored on the closes above/below MA3 (marker 2).
Active markers are:
- Marker 1: set to crosses between M1 and M4
- Marker 3: Quick Flips
If an alert was configured now, it would trigger on either marker 1 or 3, since they are active, and you could configure the indicator to trigger alerts on longs or shorts only.

Informacje o Wersji

Updated comments.

Informacje o Wersji

Updated comments.

Informacje o Wersji

Added possibility to define an interval for each MA above which the MA is hidden. The default for MA4 and MA5 is 1D, so they are automatically hidden on this 3D chart.

Informacje o Wersji

Fixed comments.

Informacje o Wersji

Reorganized Inputs.
Komentarze
diLiviu
great job, man!
milanx82
I like it, good job! My only wish is to be able to rename to something short. at the moment long name across the screen blocking view and at is annoying
Is anything possible to do?
LucF
@milanx82, Thx for the good words. The indicator's chart name is "5 MAs", so I suppose you are referring to the visible arguments and values appearing to the right of the indicator's name. You can control their display by right-clicking on the indicator's name on the chart and unchecking the respective "Show..." items in there.
milanx82
@LucF, thank you
I m good now, what a relief
Ithimar
I'm still fresh at actually getting into Pine. But this is a work of art for its utility alone. Will be "studying" frequently while I learn!
That said, for someone who has a grasp of the concepts but not so much the "why," can you point me to where/what I should be learning first? :S
Again though, your work is beautiful, thanks so much.
LucF
@Ithimar, Thx for the good words, and sry for the delay. The new v5 User Manual is a good place to start. I'd go with the first two sections: "Pine Primer" and "Language", and then pick from Concepts the areas you're most interested in.
tradingview.com/pine-script-docs/en/v5/primer/index.html
secretcode
Great! Thanks for sharing :)
chrisharb1987
Love it!
LucF
HEIKOTradingSystem
HOLY!! I have never seen a script like this before....you are certainly a master of pine. Because I'm a noob to pine, my script writing is not good. To automate this script trading on mt4, not only would I need to change this script to 'strategy' but I would have to add some code for long and short positions correct? Thank you for your help with educating me (all of us).....you are someone I follow so I can learn as much as possible. stay safe. Justin
Więcej