OPEN-SOURCE SCRIPT

Custom EMA Strategy

Actualizado
This script combines 3 EMAs with Bollinger Bands to build a trend based trading strategy. The 3 EMAs (I, II and III ) default lengthes come from one of the Fibonacci Phi^3/2 sub series (17, 72 and 305), but can be changed to any values, particularly to the traditionally used 20, 50 and 200. Bollinger Band length is set to the same length as EMA I. Up to my knowledge, Fibonacci Phi^3/2 sub series lengthes were first proposed by Bo Williams.

Buy Recommendations happen when src (close) > EMA I > EMA II, EMA I angle > 0 degree, EMA II angle > -1 degree and EMA III angle > -1 degree. My simulations have show that -1 degree usage results in better returns than zero degree.

Top Buy Recommendations happen when, besides Buy recommendation conditions are met, src (close) > HBand, the Bollinger Band High Band.

Sell Recommendations come in 3 flavors: Short Term (close < EMA I), Medium Term (close < EMA2) and Long Term ( EMA I < EMA II).

Angle calculation is performed by calculating the "normalized" tangent over a delta interval. Normalization is required to make the angle independent of the price range.
Notas de prensa
This update just replaces the references to the close price by the chosen data source set to src.
Notas de prensa
This update is just to fix the EMA calculation in the absence of enough candles. Instead of using TV standard zero price, I use the source (close) price.
Notas de prensa
This update adds the option for using an intermediate length MA between MA I and MA II. It also adds some thresholds to be checked before showing a buy recommendation.
Notas de prensa
This update adds a new sell indication (colored maroon) based on the decrease of the angle between the 2 smaller MAs. It also adds new parameters to adjust buy and sell conditions. For details check the source code.
Notas de prensa
This update adds a new set of 3 MAs in order to detect consolidation conditions and enhance buy recomendation decisions.
Notas de prensa
This update improves the consolidation detection algorithm.
Notas de prensa
This update just changes some parameter default values and improves buy recommendation condition detection. It also removes an unused paramter related code.
Notas de prensa
This update changes the Long Term Sell condition to src < MA III and creates the Long Long Term Sell condition to when MA I < MA II. It also adds a new Minimum Delta % parameter to set the minimum distance between MA I and MA II that allows a buy condition. It also removes the requirement of red candle to maroon sell condition and tweaks some parameter default values. It also changes the low trend definition to MA IV < MA V < MA VI.
Notas de prensa
This update just corrects the name of the parameter that drives the maroon selling condition to fit its actual meaning. It also updates its default value.
Notas de prensa
This update adjusts the buying recomendation condition when it is not in a low trend.
Notas de prensa
This update adjusts buy and sell recommendation conditions. It also adds a new orange flag, named PC, to indicate that is forbidden to buy. This PC flag is angle based and its validity should be evaluated together with other aspects that could not fit in here. We recommend coloring bars because buy flag condition transition is not very sensitive and we can see some green bars without a buy flag in the beginning.
Notas de prensa
This update adjusts buy and sell recommendation conditions.
Notas de prensa
This update adds the option to hide the EMAs, so that Buy and Sell indications can be used with other indicators without polluting the chart.
Notas de prensa
This update just optimizes some functions to use binary search and decrease average execution time from n/2 to log2(n).
Notas de prensa
This update just cleans the code a bit and adds a new option to hide term related (red) Sell indications.
Notas de prensa
This update just adds a new Simple Cross Strategy option. As it has performed much better than the previous one, it was left as default. In order to use previous behavior, just uncheck the option.
Notas de prensa
This update just changes the selling condition on the Simple Cross Strategy mode to sell when MA 0 ROC < 0, if under consolidation (src < MA 5 or src < MA6). Otherwise, Simple Cross Strategy sell condition keeps as before, when MA 0 < MA 2.
Notas de prensa
This update just fixes the low trend condition definition for the Simple Cross Strategy to match its definition (src < MA 5)
Notas de prensa
This update just changes the consolidation condition from (src < MA 5) to (src < MA 6) due to better backtesting results.
Notas de prensa
This update adds another option to trigger sell when on consolidation (src < MA6). Before, on consolidation, the Simple Cross Strategy mode did a sell when MA 0 ROC < 0. Now, we can choose a MA X, with X ranging from 0 to 3, that triggers sell if src < MA X. If X equals -1, this new cross condition is disable and the previous one (MA 0 ROC < 0) is activated.
Notas de prensa
This update just adds an extra line drawing to compensate for its disappearance when using Length shift Up or Down.
Notas de prensa
This update adds a new option named "Small Caps Behaviour" to force using consolidation behaviour on sell decisions.
Notas de prensa
This update adds a new ROC based consolidation check option and a new field to set Bollinger Bands length. The new ROC based consolidation check option considers consolidation state when the condition (ROC 2 > ROC 3 and ROC 3 > ROC 4) is false.
Notas de prensa
This update just adjusts the order of Buy/Top buy flags drawing.
Notas de prensa
This update adds angle tests to the buy condition on the Simple Cross Strategy. Now, besides requiring MA 0 > MA 2, it also tests if Angle 2 > Small Angle Threshold and if Angle 6 > Large Angle Threshold. Please note that the Length Shift affects the actual lengths of the tested MAs.
CEMASluyikaiMoving AveragesTrend Analysis

Script de código abierto

Siguiendo fielmente el espíritu de TradingView, el autor de este script lo ha publicado en código abierto, permitiendo que otros traders puedan entenderlo y verificarlo. ¡Olé por el autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la reutilización de este código en la publicación se rige por las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

¿Quiere utilizar este script en un gráfico?

Exención de responsabilidad