This script is designed as a visual trading assistant for the MetaTrader platform. It functions by analyzing price momentum to help traders identify when a currency pair might be overextended or when a trend shift is occurring.
Core Functionality
The tool calculates two primary data lines, commonly known as "K" and "D" lines, which track the speed and direction of price movements. These lines oscillate between 0 and 100 on a dedicated sub-window beneath your main chart.
Key Features and Logic
1. Overbought and Oversold Detection The script constantly monitors the primary data line (K) against two specific boundaries:
- Overbought Zone: If the line rises above the upper limit (default 80.0), the tool identifies the market as being "overextended" to the upside.
- Oversold Zone: If the line drops below the lower limit (default 20.0), the tool identifies the market as being "exhausted" to the downside.
2. Signal Identification (Crossovers) Beyond just looking at limits, the script watches for "crossovers"—moments where the two lines intersect.
- Long Signals: When the primary line crosses upward over the signal line within a specific range, it identifies a potential bullish move.
- Short Signals: When the primary line crosses downward under the signal line, it identifies a potential bearish move.
3. Real-Time Visual Feedback To make these calculations easy to read at a glance, the script provides immediate visual updates on your screen:
- On-Screen Text: It dynamically displays labels such as "LONG," "SHORT," "OVERBOUGHT," or "OVERSOLD" directly on the chart.
- Color Coding: The text changes color automatically to alert you visually—typically shifting to one color for bullish signals and another for bearish signals.
4. Automated Alerts The script can be configured to notify you actively rather than requiring you to watch the screen constantly. It includes a built-in notification system that can trigger:
- An alert when the price enters an overbought or oversold state.
- An alert the moment a trend crossover occurs in either direction.
Summary for the User
In simple terms, this tool acts as an automated observer. It filters out the "noise" of the market to highlight three specific things: where the price is too high, where it is too low, and exactly when the momentum is shifting from one direction to another.
#property copyright "xbox forex"
#property link "http://community.strangled.net"
#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 100.0
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
extern int K = 5;
extern int D = 3;
extern int Slowing = 3;
extern bool Alert_Over = FALSE;
extern bool Alert_Cross = FALSE;
extern double Overbuy_Level = 80.0;
extern double Oversell_Level = 20.0;
extern double Crossover_Gap = 0.0;
extern int Shift_Bars = 0;
extern int Bars_Count = 0;
extern int MA_Mode = 0;
double g_ibuf_132[];
double g_ibuf_136[];
string gs_140 = "";
string gs_148 = "XB4 Stochastic";
int gi_156;
int gi_160;
int init() {
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1);
SetIndexDrawBegin(0, K + Slowing);
SetIndexBuffer(0, g_ibuf_132);
SetIndexLabel(0, "K");
SetIndexStyle(1, DRAW_LINE, STYLE_DOT, 1);
SetIndexDrawBegin(1, K + D + Slowing);
SetIndexBuffer(1, g_ibuf_136);
SetIndexLabel(1, "D");
SetLevelValue(0, Oversell_Level);
SetLevelValue(1, Overbuy_Level);
SetLevelValue(2, 50);
IndicatorShortName(gs_148);
return (0);
}
int start() {
int li_0;
int l_shift_4;
int li_8 = IndicatorCounted();
if (li_8 > 0) li_8--;
if (Bars_Count > 0 && Bars_Count <= Bars) li_0 = Bars_Count - li_8;
else li_0 = Bars - li_8;
creataalltext();
int li_12 = 16777215;
while (li_0 >= 0) {
l_shift_4 = li_0 + Shift_Bars;
g_ibuf_132[li_0] = iStochastic(Symbol(), Period(), K, D, Slowing, MA_Mode, 0, MODE_MAIN, l_shift_4);
g_ibuf_136[li_0] = iStochastic(Symbol(), Period(), K, D, Slowing, MA_Mode, 0, MODE_SIGNAL, l_shift_4);
Print(g_ibuf_132[li_0]);
li_0--;
}
gs_140 = "";
if (g_ibuf_132[0] >= Overbuy_Level) {
gs_140 = "OVERBOUGHT";
if (Alert_Over == TRUE && gi_156 != 1) {
gi_156 = 1;
Alert("xStoch Overbought K: ", Symbol(), " ", g_ibuf_132[0]);
}
} else {
if (g_ibuf_132[0] <= Oversell_Level) {
gs_140 = "OVERSOLD";
if (Alert_Over == TRUE && gi_156 != -1) {
gi_156 = -1;
Alert("xStoch Oversold K: ", Symbol(), " ", g_ibuf_132[0]);
}
}
}
if (g_ibuf_132[1] < g_ibuf_136[0] + Crossover_Gap && g_ibuf_132[0] >= g_ibuf_136[0] + Crossover_Gap) {
if (g_ibuf_132[0] >= Oversell_Level && g_ibuf_132[0] <= Overbuy_Level) gs_140 = "LONG";
if (Alert_Cross == TRUE && gi_160 != 1) {
gi_160 = 1;
Alert("xStoch crossed - Direction Long ", Symbol());
}
} else {
if (g_ibuf_132[1] > g_ibuf_136[0] - Crossover_Gap && g_ibuf_132[0] <= g_ibuf_136[0] - Crossover_Gap) {
if (g_ibuf_132[0] >= Oversell_Level && g_ibuf_132[0] <= Overbuy_Level) gs_140 = "SHORT";
if (Alert_Cross == TRUE && gi_160 != -1) {
gi_160 = -1;
Alert("xStoch crossed - Direction Short ", Symbol());
}
}
}
if (gs_140 == "OVERSOLD" || gs_140 == "SHORT") li_12 = 255;
if (gs_140 == "OVERBOUGHT" || gs_140 == "LONG") li_12 = 65280;
settext("xboxforex_stoch", gs_140, 12, li_12, 10, 35);
return (0);
}
void creataalltext() {
createtext("xboxforex_stoch");
settext("xboxforex_stoch", " ", 12, White, 10, 35);
}
void createtext(string a_name_0) {
ObjectCreate(a_name_0, OBJ_LABEL, WindowFind(gs_148), 0, 0);
}
void settext(string a_name_0, string a_text_8, int a_fontsize_16, color a_color_20, int a_x_24, int a_y_28) {
ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_24);
ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_28);
ObjectSetText(a_name_0, a_text_8, a_fontsize_16, "Arial", a_color_20);
}
Comments