This indicator identifies a "Three Bar Reversal" pattern and provides buy/sell signals along with stop-loss (SL), take-profit (TP), and entry prices based on mean reversion. Here’s a breakdown of how it works:
Inputs:
Text Size: The user can choose the size of the label text displayed on the chart, with options like tiny, small, normal, large, and huge. Buy/Sell Label Colors: Users can set the colors for the buy and sell labels. Buy/Sell Text Colors: The user can set the text color for the buy and sell labels. Identifying Reversal Patterns:
Bullish Reversal: The indicator looks for a bullish reversal pattern where: The first bar (index 2) is bullish (close > open). The second bar (index 1) has a low price lower than the first bar. The close of the current bar is higher than the high of the second bar. Bearish Reversal: A bearish reversal is identified when: The first bar (index 2) is bearish (close < open). The second bar (index 1) has a high price higher than the first bar. The close of the current bar is lower than the low of the second bar. Mean Reversion (SMA) Calculation:
The script calculates a 20-period simple moving average (SMA) of the close prices (mean_price), which is used as a reference for setting stop-loss and take-profit levels. Risk to Reward Ratio (1:1.5):
The risk-to-reward ratio is set at 1.5:1. This means the take-profit target is 1.5 times the distance from the entry price to the stop-loss. Stop-Loss and Take-Profit Calculation:
Buy Signal: Stop-Loss is placed 1% below the mean price. Take-Profit is calculated based on the risk-to-reward ratio from the entry price. Sell Signal: Stop-Loss is placed 1% above the mean price. Take-Profit is calculated similarly based on the risk-to-reward ratio. Creating Labels:
When a bullish or bearish reversal pattern is detected: A label is drawn on the chart showing the entry price, TP, and SL for the trade. Alerts are triggered when a buy or sell signal is detected, displaying the relevant entry, TP, and SL levels. Line Drawing:
A blue line is drawn at the low price of the reversal pattern to visually represent the reversal point.
In summary, the indicator combines a reversal pattern detection (Three Bar Reversal) with mean reversion, setting stop-loss and take-profit levels based on the 20-period moving average and a defined risk-to-reward ratio. Labels with the trade details (entry, TP, SL) are plotted, and alerts are triggered whenever a reversal pattern is identified.