OPEN-SOURCE SCRIPT
Updated

Optimized Smart Money Concept for BTCUSD

This indicator is designed to detect breakouts based on a simplified version of the Smart Money Concept (SMC) for BTCUSD and uses risk/reward calculations for trade management. Here's how it works:

1. Input Parameters:
Risk/Reward Ratio: This determines the target profit relative to the stop loss. For BTCUSD, the default is set to a 2:1 ratio (i.e., for every dollar risked, the target profit is two dollars).
Lookback Period for Swing High/Low: This is the number of bars used to look back to identify the highest high and lowest low, which help in determining the stop-loss levels. A larger lookback is used to account for BTCUSD's volatility.

2. Breakout Pattern:
Bullish Breakout Condition:
The first candle (index 2) is bearish (close < open).
The second candle (index 1) is bullish (close > open).
The third candle is also bullish (close > open), and it closes higher than the second candle.
Bearish Breakout Condition:
The first candle (index 2) is bullish (close > open).
The second candle (index 1) is bearish (close < open).
The third candle is also bearish (close < open), and it closes lower than the second candle.

3. Swing Points for Stop Loss:
Lowest Low (Long Stop Loss): The lowest low over the defined lookback period.
Highest High (Short Stop Loss): The highest high over the defined lookback period.

4. Stop Loss and Take Profit Calculation:
For Long (Buy) Trades:
Stop Loss is placed at the lowest low over the lookback period.
Take Profit is calculated by adding the difference between the entry price (current close) and the stop loss, multiplied by the risk/reward ratio (e.g., 2:1).
For Short (Sell) Trades:
Stop Loss is placed at the highest high over the lookback period.
Take Profit is calculated by subtracting the difference between the entry price and the stop loss, multiplied by the risk/reward ratio.

5. Conditions for Buy and Sell:
A buy condition is triggered when the bullish breakout pattern occurs.
A sell condition is triggered when the bearish breakout pattern occurs.

6. Plotting Buy/Sell Signals:
When a long (buy) condition is met, a label is placed below the candlestick with the entry price, take-profit (TP), and stop-loss (SL) levels. A line is drawn connecting the label to the low of the candlestick.
When a short (sell) condition is met, a label is placed above the candlestick with the entry price, TP, and SL levels. A line is drawn connecting the label to the high of the candlestick.

7. Breakout Debugging:
The indicator uses plotshape() to visually mark where bullish and bearish breakout patterns are detected on the chart with green (bullish) and red (bearish) shapes, respectively.

In Summary:
The indicator looks for specific bullish and bearish breakout patterns, calculates the stop-loss and take-profit levels based on swing points and a risk/reward ratio, and then plots buy/sell labels on the chart with the corresponding entry, TP, and SL values. It also provides a visual marker for each breakout pattern detected for debugging or confirmation purposes.
Release Notes
Trend Table added

A table is displayed in the upper-right corner of the chart showing the current market trend:
Uptrend: When the price is above the blue EMA.
Downtrend: When the price is below the yellow EMA.
Sideways: When neither of the above conditions are met.

Disclaimer