OPEN-SOURCE SCRIPT

MACD_RSI_trend_following

Aktualisiert
INFO:
This indicator can be used to build-up a strategy for trading of assets which are currently in trending phase.
My preference is to use it on slowly moving assets like GOLD and on higher timeframes, but practice may show that we find more usefull cases.
This script uses two indicators - MACD and RSI, as the timeframe that those are extracted for is configurable (defaults with the Chart TF, but can be any other selected by the user).
The strategy has the following simple idea - buy if any if the conditions below is true:
  • The selected TF MACD line crosses above the signal line and the TF RSI is above the user selected trigger value
  • The selected TF MACD line is above the signal line and the TF RSI crosses above the user selected trigger value

Once we're in position we wait for the selected TF MACD line to cross below the signal line, and then we set a SL at the low of that bar

DETAILS and USAGE:
In the current implementation I find two possible use cases for the indicator:
  • as a stand-alone indicator on the chart which can also fire alerts that can help to determine if we want to manually enter/exit trades based on them
  • can be used to connect to the Signal input of the TTS (TempalteTradingStrategy) by jason5480 in order to backtest it, thus effectively turning it into a strategy (instructions below in TTS CONNECTIVITY section)
    In the example below we see a position opened at the bar after the buy indicator from the script has been triggered, and then later after the SL indicator from the script has been triggered a SL has been set on the lower wick of the closing candle, and the position eventually got closed once the price hit that level. Note that most of the drawing on the example snapshot below are from the TTS indicator following the buy/sell/SL conditions themseves:
    Snapshot

Trading period can be selected from the indicator itself to limit to more interesting periods.
Arrow indications are drawn on the chart to indicate the trading conditions met in the script - green arrow for a buy signal indication and orange for LTF crossunder to indicate setting of SL.

SETTINGS:
Leaving all of the settings as in vanilla use case, as both the MACD and RSI indicator's settings follow the default ones for the stand-alone indicators themselves.
The start-end date is a time filter that can be extermely usefull when backtesting different time periods.
Pesonal preference is using the script on a D/W timeframe, while the indicator is configured to use Monthly chart.
The default value of the RSI filter is left to 50, which can be changed. I.e. if the RSI is above 50 we have a regime filter based on the MACD criteria.

EXTERNAL LIBRARIES:
The script uses a couple of external libraries:
  • HeWhoMustNotBeNamed/enhanced_ta/14 - collection of TA indicators
  • jason5480/tts_convention/3 - more details about the Template Trading Strategy below

I would like to highly appreciate and credit the work of both HeWhoMustNotBeNamed and jason5480 for providing them to the community.

TTS SETTINGS (NEEDED IF USED TO BACKTEST WITH TTS):
The TempalteTradingStrategy is a strategy script developed in Pine by jason5480, which I recommend for quick turn-around of testing different ideas on a proven and tested framework
I cannot give enough credit to the developer for the efforts put in building of the infrastructure, so I advice everyone that wants to use it first to get familiar with the concept and by checking
by checking jason5480's profile tradingview.com/u/jason5480/
The TTS itself is extremely functional and have a lot of properties, so its functionality is beyond the scope of the current script -
Again, I strongly recommend to be thoroughly epxlored by everyone that plans on using it.
In the nutshell it is a script that can be feed with buy/sell signals from an external indicator script and based on many configuration options it can determine how to execute the trades.
The TTS has many settings that can be applied, so below I will cover only the ones that differ from the default ones, at least according to my testing - do your own research, you may find something even better :)
The current/latest version that I've been using as of writing and testing this script is TTSv48
Settings which differ from the default ones:
  • from - False (time filter is from the indicator script itself)
  • Deal Conditions Mode - External (take enter/exit conditions from an external script)
  • 🔌Signal 🛈➡ - MACD_RSI_trend_following: 🔌Signal to TTSv48 (this is the output from the indicator script, according to the TTS convention)
  • Sat/Sun - true (for crypto, in order to trade 24/7)
  • Order Type​​ - STOP (perform stop order)
  • Distance Method​​ - HHLL (HigherHighLowerLow - in order to set the SL according to the strategy definition from above)

The next are just personal preferenes, you can feel free to experiment according to your trading style
  • Take Profit Targets - 0 (either 100% in or out, no incremental stepping in or out of positions)
  • Dist Mul|Len Long/Short- 10 (make sure that we don't close on profitable trades by any reason)
  • Quantity Method - EQUITY (personal backtesting preference is to consider each backtest as a separate portfolio, so determine the position size by 100% of the allocated equity size)
  • Equity %         - 100 (note above)

Versionshinweise
updated the plot shapes to be better associated with price action been attached to bars
Moving Average Convergence / Divergence (MACD)Relative Strength Index (RSI)Trend Analysis

Open-source Skript

Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun das Script auch andere Trader verstehen und prüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Möchten Sie dieses Skript auf einem Chart verwenden?

Haftungsausschluss