Combined Strategy Trading Bot (RSI ADX 20SMA)Trading Bot V1, This code implements a combined trading strategy that uses several indicators and strategies to make buy and sell decisions in the market. The code is written in Pine Script™, which is a programming language used in the TradingView platform. By BraelonWhitfield.Eth
The strategy uses the Average Directional Movement Index (ADX) and the Pine SuperTrend indicator to identify trends and price movements in the market. The SuperTrend indicator is a popular technical analysis tool that helps to identify the direction of the current trend and provides entry and exit points for trades.
The strategy also uses the Relative Strength Index (RSI) to identify overbought and oversold conditions in the market. The RSI is a momentum indicator that measures the speed and change of price movements in the market.
The first part of the code defines the inputs for the ADX and DI Length, which are used to calculate the ADX and DI values. The dirmov() function is used to calculate the positive and negative directional indicators (plusDM and minusDM) based on the high and low prices. The truerange variable is then calculated using the True Range (TR) formula. Finally, the plus and minus variables are calculated using the smoothed moving average of the plusDM and minusDM values.
The adx() function is then used to calculate the ADX values based on the plus and minus variables. The Pine SuperTrend indicator is defined using the pine_supertrend() function. This function uses the high-low average (hl2) and the Average True Range (ATR) to calculate the upper and lower bands for the indicator. The direction of the current trend is then determined based on whether the current price is above or below the upper or lower bands.
The RSI values are then calculated using the ta.rsi() function, with the inputs for the close price and the RSI period. The overbought and oversold conditions are defined using the OB and OS inputs, which specify the threshold values for the RSI. The upTrend and downTrend variables are defined based on the direction of the Pine SuperTrend indicator.
The next part of the code defines the 20-period Simple Moving Average (SMA) using the ta.sma() function. The os and ob variables are then calculated based on the RSI values and the OB and OS inputs. The strategy.entry() function is used to define the buy and sell orders based on the upTrend and downTrend variables, as well as the Pine SuperTrend indicator, the 20-period SMA, and the os variable.
The final part of the code defines the Channel Breakout Strategy using the ta.highest() and ta.lowest() functions to calculate the upper and lower bounds of the channel. The strategy.entry() function is then used to define the buy and sell orders based on whether the current price is above or below the upper or lower bounds.
In summary, this code implements a combined trading strategy that uses several indicators and strategies to make buy and sell decisions in the market. The strategy is designed to identify trends and price movements in the market, as well as overbought and oversold conditions, to provide entry and exit points for trades. The strategy uses the Pine SuperTrend indicator, the ADX and DI indicators, the RSI, and the 20-period SMA, as well as the Channel Breakout Strategy to make informed trading decisions.
20sma
P-MACD by DGTPrice and Moving Averages Convergence/Divergence, shortly named as P-MACD
P-MACD is a trend-following momentum indicator that shows the relationship between Price and Long-term Moving Average (PMACD), and the relationship between two Moving Averages (MAMACD). P-MACD is composed of two lines, and an histogram, showing price distance (convergence/divergence) to its Long-term MA (PMACD), showing short-term MA distance (convergence/divergence) to long-term MA (MAMACD), and a histogram showing the difference (momentum) between the PMACD and MAMACD
The PMACD is calculated by dividing the Price to Long-term Moving Average (200-period SMA/EMA) and finally smoothed with 9-period SMA/EMA
- PMACD Line Formula : (Price / SlowMovingAverage -1) * 100 and smoothed with 9-period SMA/EMA
The MAMACD is calculated by dividing the Short-term Moving Average (such as 20 SMA/EMA) to the Long-term Moving Average (such as 200-period SMA/EMA)
- MAMACD Line Formula : (FastMovingAverage / SlowMovingAverage -1) * 100
The Histogram is calculated by subscripting PMACD and MAMACD
- Formula : PMACD - MAMACD
Optional
Trend Cloud calculated based on fast and slow version of MAMACD
What to look for:
- Line Crosses : PMACD Line can function as a trigger(signal) for buy and sell signals. Buy when the PMACD crosses above the MAMACD line and sell - or short - when the PMACD crosses below the MAMACD line
- Base Crosses : PMACD and/or MAMACD crosses above or below Baseline is another way to indicate the trend and momentum. MAMACD crosses of Baseline, MAMACD positive or negative, reflects short-term moving average crosses the long-term moving average and similarly, PMACD crosses of BaseLine, PMACD positive or negative, reflects price crosses a long-term moving average
- Momentum : P-MACD helps investors understand whether the bullish or bearish movement in the price is strengthening or weakening displayed with a histogram which graphs the distance between the PMACD and MAMACD. Additionally, upward momentum is confirmed with a bullish crossover, which occurs when PMACD and/or MAMACD crosses above Baseline. Conversely, downward momentum is confirmed with a bearish crossover, which occurs when PMACD and/or MAMACD crosses below Baseline
- Distance : Prices high above the moving average (MA) or low below it are likely to be remedied in the future by a reverse price movement. The more distant the PMACD is above or below its baseline indicates that the distance between the Price and its SMA is growing (regarding PMACD, You may find a detailed article explained in “Price Distance to its MA” indicator by DGT) . Similarly the more distant the MAMACD is above or below its baseline indicates that the distance between the two SMAs is growing
- Trend : A rising P-MACD indicates an uptrend, while a declining P-MACD indicates a downtrend
MACD vs. P-MACD
MACD measures the relationship between two MAs, while the P-MACD measures both the relationship between price and its MA, and the relationship between two MAs. MAMACD Line of P-MACD If set to same moving average type and same lengths as in MACD will produce the same line as MACD line, only values are represented as percentage with MAMACD. Both measure momentum in a market, but, because they measure different factors, they differentiate from each other even if they have similarities in presentation. P-MACD provides additional insights, not only to MA relation but also to Price and MA relation
Warning : Moving Average are calculated based on past prices, so they are lagging. The longer the time period for the moving average, the greater the lag as well as less sensitive to price changes. This study implements usage of 200-period long-term moving average, which implies that the P-MACD will provide insight especially for long-term trades, more suited for long-term trades, usage of P-MACD for short-term trades is recommend with lower timeframes (1H or lower).
Indicators aim to generate a potential signal/indication of an upcoming opportunity, but, the Indicators themselves do not guarantee the future movement of a given financial instrument, and are most useful when used in combination with other techniques.
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
Disclaimer : The script is for informational and educational purposes only. Use of the script does not constitutes professional and/or financial advice. You alone the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd tradingview user liable for any possible claim for damages arising from any decision you make based on use of the script