SuperTrend Candles_source
Download scriptThe SuperTrend Candles script is a visual trading tool designed to enhance your charting experience by dynamically recoloring price candles based on trend momentum. Instead of just providing a standard line on your chart, this tool translates complex trend data into a clear, color-coded visual language that helps you identify market direction at a glance.
How the Logic Works
The script functions by analyzing two distinct types of "SuperTrend" data simultaneously: an upward trend component and a downward trend component. By comparing these two values, the script determines the prevailing market sentiment and applies specific colors to the candles on your screen.
1. Trend Detection The core logic relies on calculating a baseline for both buying and selling pressure. It looks at the historical price action (defined by the period and multiplier settings) to decide which direction is currently dominant:
- Bullish Environment: When the upward trend data exceeds the downward trend data, the script identifies a positive market bias.
- Bearish Environment: When the downward trend data takes precedence, the script identifies a negative market bias.
2. Dynamic Visual Rendering Once the trend is identified, the script automatically adjusts the appearance of the candles:
- Color Switching: The candles are assigned specific colors (typically Green/Lime for upward trends and Red for downward trends). This allows you to see the "flow" of the market without having to manually interpret overlapping indicators.
- Custom Styling: The tool is designed to distinguish between different visual elements, such as the main candle body and the wicks, ensuring that the information remains readable and doesn't clutter your workspace.
3. Real-Time Processing The script continuously scans recent historical bars (up to a user-defined limit) to ensure the colors stay synchronized with the live price action. As new candles form, the script re-evaluates the SuperTrend values and updates the candle colors instantly, providing you with a real-time heat map of market volatility and direction.
Summary for the User
Essentially, this script acts as a "visual filter." It takes the complex math behind the SuperTrend indicator and simplifies it into a high-visibility display. If the candles turn one color, the trend is bullish; if they shift to another, the trend has turned bearish. This allows you to stay aligned with the market's primary direction while maintaining a clean and organized chart.
#property copyright "SuperTrend Candles by cja"
#property link ""
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
extern int Nbr_Periods = 10;
extern double Multiplier = 3.0;
extern int BARS = 300;
extern string IIIIIIIIIIIIIIIIIIIIIIIII = ">>> Candle/Wick Display Settings >>>>>>>>>>>>>>>>>";
extern int BarWidth = 1;
extern int CandleWidth = 3;
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double gda_124[];
double gda_128[];
double gda_132[];
double gda_136[];
int init() {
IndicatorShortName("SuperTrend Candles");
IndicatorBuffers(4);
SetIndexBuffer(0, g_ibuf_108);
SetIndexBuffer(1, g_ibuf_112);
SetIndexBuffer(2, g_ibuf_116);
SetIndexBuffer(3, g_ibuf_120);
SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, BarWidth);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, BarWidth);
SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, CandleWidth);
SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, CandleWidth);
return (0);
}
int deinit() {
return (0);
}
double Super_UP(int ai_0 = 0) {
return (iCustom(NULL, 0, "SuperTrend", Nbr_Periods, Multiplier, 0, 0, ai_0));
}
double Super_DN(int ai_0 = 0) {
return (iCustom(NULL, 0, "SuperTrend", Nbr_Periods, Multiplier, 0, 1, ai_0));
}
void SetCandleColor(int ai_0, int ai_4) {
double ld_24 = MathMax(Open[ai_4], Close[ai_4]);
double ld_32 = MathMin(Open[ai_4], Close[ai_4]);
double l_high_8 = High[ai_4];
double l_low_16 = Low[ai_4];
g_ibuf_108[ai_4] = l_low_16;
g_ibuf_116[ai_4] = ld_32;
g_ibuf_112[ai_4] = l_low_16;
g_ibuf_120[ai_4] = ld_32;
g_ibuf_108[ai_4] = l_low_16;
gda_124[ai_4] = ld_32;
g_ibuf_112[ai_4] = l_low_16;
gda_128[ai_4] = ld_32;
g_ibuf_108[ai_4] = l_low_16;
gda_132[ai_4] = ld_32;
g_ibuf_112[ai_4] = l_low_16;
gda_136[ai_4] = ld_32;
switch (ai_0) {
case 1:
g_ibuf_108[ai_4] = l_high_8;
g_ibuf_116[ai_4] = ld_24;
return;
case 2:
g_ibuf_112[ai_4] = l_high_8;
g_ibuf_120[ai_4] = ld_24;
return;
case 3:
g_ibuf_108[ai_4] = l_high_8;
gda_124[ai_4] = ld_24;
return;
case 4:
g_ibuf_112[ai_4] = l_high_8;
gda_128[ai_4] = ld_24;
return;
case 5:
g_ibuf_108[ai_4] = l_high_8;
gda_132[ai_4] = ld_24;
return;
case 6:
g_ibuf_112[ai_4] = l_high_8;
gda_136[ai_4] = ld_24;
return;
return;
}
}
int start() {
double ld_4;
double ld_12;
for (int li_0 = MathMax(BARS - 1 - IndicatorCounted(), 1); li_0 >= 0; li_0--) {
ld_4 = Super_UP(li_0);
ld_12 = Super_DN(li_0);
if (ld_4 > ld_12) SetCandleColor(2, li_0);
else
if (ld_4 <= ld_12) SetCandleColor(1, li_0);
}
return (0);
}
Comments