This Pine Script is a TradingView indicator that checks the size of the previous candle's body (difference between the open and close prices) and triggers an alert if it exceeds a certain threshold.
Breakdown of the Script
1. Indicator Declaration
//version=5
indicator("Candle Size Alert (Open-Close)", overlay=true)
//version=5: Specifies that the script is using Pine Script v5.
indicator("Candle Size Alert (Open-Close)", overlay=true):
Creates an indicator named "Candle Size Alert (Open-Close)".
overlay=true: Ensures the script runs directly on the price chart (not in a separate panel).
2. User-Defined Threshold
candleThreshold = input.int(500, title="Candle Size Threshold")
input.int(500, title="Candle Size Threshold"):
Allows the user to set the threshold for candle body size.
Default value is 500 points.
3. Calculate Candle Size
candleSize = math.abs(close[1] - open[1])
close[1] and open[1]:
close[1]: Closing price of the previous candle.
open[1]: Opening price of the previous candle.
math.abs(...):
Takes the absolute difference between the open and close price.
This gives the candle body size (ignoring whether it's bullish or bearish).
4. Check If the Candle Size Meets the Threshold
sizeCondition = candleSize >= candleThreshold
If the previous candle’s body size is greater than or equal to the threshold, sizeCondition becomes true.
5. Determine Candle Color
isRedCandle = close[1] < open[1]
isGreenCandle = close[1] > open[1]
Red Candle (Bearish):
If the closing price is less than the opening price (close[1] < open[1]).
Green Candle (Bullish):
If the closing price is greater than the opening price (close[1] > open[1]).
6. Generate Alerts
if sizeCondition
direction = isRedCandle ? "SHORT SIGNAL (RED)" : "LONG SIGNAL (GREEN)"
alertMessage = direction + ": Previous candle body size = " + str.tostring(candleSize) +
" points (Threshold: " + str.tostring(candleThreshold) + ")"
alert(alertMessage, alert.freq_once_per_bar)
If the candle body size exceeds the threshold, an alert is triggered.
direction = isRedCandle ? "SHORT SIGNAL (RED)" : "LONG SIGNAL (GREEN)":
If the candle is red, it signals a short (sell).
If the candle is green, it signals a long (buy).
The alert message includes:
Signal type (LONG/SHORT).
Candle body size.
The user-defined threshold.
How It Works in TradingView:
The script does not plot anything on the chart.
It monitors the previous candle’s body size.
If the size exceeds the threshold, an alert is generated.
Alerts can be used to notify the trader when big candles appear.
How to set alerts in Trading view:
Add the Indicator: Apply this indicator to your BTCUSD chart.
Set Time Frame: Choose your preferred time frame (e.g., 15 minutes).
Open Alerts: Click on the "Alerts" tab.
Create a New Alert: Click on the "+" symbol to add a new alert.
Select Condition: Choose "Candle Size Alert" as the condition.
Alert Function: The default condition is the "Any Alert() Function Call."
Set Expiration & Name: Choose an expiration date and name your alert.
Configure Notifications: Select your preferred notification method.
Create Alert: Click "Create," and you're done!
Now, whenever the condition is met, the alert will notify you automatically. Happy trading! 🚀