Buy / Sell Fractal Algorithm with SL Line Generation

aidenhawkins2004 Actualizado   
This algorithm is designed for usage across indices.

How it works?

The algorithm uses a variation of fractals, momentum, RSI and LRSI to determine a trends direction.

The Relative Strength Index (RSI) is a momentum-based oscillator used to measure the speed (velocity) and change (magnitude) of directional price movements. It provides a visual means to monitor both the current and historical strength and weakness of a particular market. The strength or weakness is based on closing prices over the duration of a specified trading period, creating a reliable metric of price and momentum changes

Momentum in trading refers to the direction and magnitude of price. Momentum plays a key role in assessing trend strength, and it is important to know when a trend is slowing down. Less momentum does not always lead to a reversal, but it does signal that something is changing, and the trend may consolidate or reverse

Fractals are patterns within price changes which are repeated across thousands of bars. Examples of fractals include the golden ratio, PHI and the spirals of the milk way. They are quite literally a universal concept.

Basics of usage:

When a bullish trend is detected; the algorithm will generate a green "SL Line" at a calculated point, which can be interpreted as an invalidation line.

If the price goes below this line, the bullish trend is invalidated. So long as it holds, the bullish trend is true until the next detection change.

When a bearish trend is detected; the algorithm will generate a red "SL Line", at a calculated point, which can be interpreted as an invalidation line.

If the prices goes above this line, the bearish trend is invalidated. So long as it holds, the bearish trend is true until the next detection change.

When a given trend is invalidated, the SL Line turns yellow and you enter a "pause zone", where neither a bearish nor bullish trend is calculated.
This resets itself on the next trend detection.

Additional information:

I have coded my own backtest to this algorithm, along with plotting the profit / loss of each generated trade.

The profit is calculated by the difference between the open bar of the trade after a long ( or short ) and the following trade.
If we are calculating a short, the resulting value is then multiplied by -1 to get a positive integer.

For calculating a loss we take the value of the open bar of the trade that generates a long, and take the difference between this and the SL line, and similarly for short positions. The code assumes the user is placing their SL at the indicated line.

Within the input settings there are a few customisation options:

Alpha & Fractal Energy Length & Source - Should not be changed.

Highly bands crossover? - Has no visible effect whether on or off. It refers to the fractal chart which in this iteration is not visible and rather a backend mechanic.

Apply fractal energy? - Should generally be left turned on. This is a noise reduction. Disabling will result in over-trading.

Apply normalization? - Has no impact, is solely used to make the fractal values more human-readable rather than decimal format.

Offset - refers to the offset value of the SL Line generations. This should be set to a value that gives you enough breathing room, and remember to include any spreads! Default is 0.2, written in %

Trading hours - This simply gives a session input for the trading hours you want to trade within, and then colours the background green for that session. Trading 24/7 is never a wise strategy, stick to whatever is most optimal for you.

Leverage - Whatever leverage you are using. Default is x20. This will affect the profit / loss calculations accordingly.

Start equity - refers to the equity value you want to backtest with. Some assets will generate NA for this in the backtest label explained later.

Label customisation options.

Note that the backtest label is by default hidden, and appears when you hover over the black label at the current bar. When enabled to visible, it will show a large text label that may cover your chart screen more than you wish.

Alerts -

There are dozens of alert functionalities here; first are the timeframe assignments for each alert, set by default to 2hrs.
These timeframes then affect the asset you select in the corresponding setting.

In total there are 8 additional assets you can set alerts for.
Once you have assigned the timeframe and asset for an alert, you can then check the tick box for that individual alert.

Once done, you set the alert as normal through the tradingview alerts window. Remember to set "alert function calls only"



I have added some functionality for timers to be set, values are in minutes. These work on the exact time of placement. Do not change the extra symbol formula option.


Note that this backtest is not intended as a replacement for tradingview backtest, nor is there a guarantee that historical results are to be replicated in the future. Trading is inherently risky.
Notas de prensa:
Fixing auth error
Notas de prensa:
Updated image
Notas de prensa:
//Update contains:
//1. Secondary Chart overlay, displaying the last 9 bars of a custom asset according to a custom timeframe
//2. A calculation for the probability a bar goes up / down according to historical data, fib points, pivots etc. As well as a backtest for this probability to ensure reliability
//3. An embedded tradingview rating for buy/sells according to their own rating public rating system, converted into a label.
//4. Confirmation for values before loading algorithm, to get around some strange errors - Also a confirmation that life does.
//5. Volume indicators MTF

As well as some optimisations.
Notas de prensa:
Cleaned up code to "tradingview standards"
Notas de prensa:
Removed some useless rubbish
Notas de prensa:
Updated to change a delisted asset provider
Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar este script en un gráfico?