_StochSlave
Download scriptThis technical indicator functions as a dynamic, self-adjusting trading tool that creates a "Master-Slave" relationship between two different types of market analysis. Instead of using fixed settings for every trade, the script automatically changes its own internal parameters based on real-time market behavior.
The Core Logic: Dynamic Adaptation
The system operates in two primary layers:
1. The Master Controller (The "Brain") The "Master" component is responsible for analyzing the overall health and momentum of the market. It monitors specific price data (such as price deviations or volatility) over a defined period. Based on this analysis, it generates a continuous signal score. This score isn't just a simple "up" or "down" move; it acts as a master key that dictates how the rest of the indicator should behave at any given second.
2. The Slave Indicator (The "Executor") The "Slave" component is a Stochastic Oscillator—a common tool used to identify when a market is overbought or oversold. However, unlike standard oscillators that use static numbers, this version is "Slave" to the Master.
How They Work Together
The unique logic of this script lies in how the Master influences the Slave:
- Variable Sensitivity: As the Master signal moves, it automatically recalculates the technical settings of the Stochastic Oscillator (specifically its period and slowing factors).
- Fluid Thresholds: The script dynamically adjusts the "Overbought" and "Oversold" boundaries. When market conditions change, these lines shift to ensure they remain relevant to current price action.
- Seamless Transition: Because these parameters are being recalculated on every new price tick, the indicator "stretches" or "contracts" its sensitivity automatically.
Summary for the User
In plain terms, this script solves the problem of "static" trading. Usually, a trader has to decide if an oscillator is too fast or too slow. This script makes that decision for you in real-time: it uses one set of logic to sense the market's mood and then automatically reconfigures its second set of logic to match that mood perfectly.
When the market is volatile, the indicator adjusts its parameters to be more responsive; when the market is calm, it smooths out to avoid "noise." This creates a more fluid visual representation of price momentum that adapts as the market evolves.
#property indicator_separate_window // â ïîäîêíå
#property indicator_buffers 6
#property indicator_color1 Blue // ñòîõàñòèê
#property indicator_color2 Magenta // óïðàâëÿþùèé ñèãíàë
#property indicator_color3 Green // óðîâåíü ïåðåêóïëåííîñòè
#property indicator_color4 Red // óðîâåíü ïåðåïðîäàííîñòè
#property indicator_maximum 100
#property indicator_minimum 0
// Âîõîäíûå ïàðàìåòðû MasterSlave
extern int Source=1; // 0 - îáúåì; 1 - ñò.äåâèàöèÿ öåíû; 2 - ATR; 3 - öåíà;
extern int SourcePeriod=88; // ïåðèîä âõîäíîãî èíäèêàòîðà
extern int Window=111; // äëèíà âûáîðêè íîðìèðîâàíèÿ
extern double Sensitivity=0; // ÷óâñòâèòåëüíîñòü
extern int Signal=55; // ñãëàæèâàíèå íîðìèðîâàííîãî èíäèêàòîðà (ñèãíàëüíàÿ)
// Âõîäíûå ïàðàìåòðû ñòîõàñòèêà
extern int KperiodFrom=22; // íà÷àëüíîå çíà÷åíèå %K
extern int KperiodTo=5; // êîíå÷íîå
extern int SlowingFrom=12; // íà÷àëüíîå çíà÷åíèå Slowing
extern int SlowingTo=3; // êîíå÷íîå
extern int OverSoldFrom=3; // íà÷àëüíîå çíà÷åíèå óðîâíÿ ïåðåïðîäàííîñòè
extern int OverSoldTo=22; // êîíå÷íîå
// èíäèêàòîðíûå áóôåðû
double Stoch[]; // ñòîõàñòèê
double Master[]; // óïðàâëÿþùèé ñèãíàë
double OB[]; // óðîâåíü ïåðåêóïëåííîñòè
double OS[]; // óðîâåíü ïåðåïðîäàííîñòè
double K[]; // %Ê ñòîõàñòèêà
double Slow[]; // Slowing ñòîõàñòèêà
bool first=1; // ôëàã ïåðâîãî çàïóñêà èíäèêàòîðà
int init() {
SetIndexBuffer(0,Stoch); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"Stoch");
SetIndexBuffer(1,Master); SetIndexStyle(1,DRAW_LINE); SetIndexLabel(1,"Master");
SetIndexBuffer(2,OB); SetIndexStyle(2,DRAW_LINE,2); SetIndexLabel(2,"OB");
SetIndexBuffer(3,OS); SetIndexStyle(3,DRAW_LINE,2); SetIndexLabel(3,"OS");
SetIndexBuffer(4,K); SetIndexStyle(4,DRAW_NONE); SetIndexLabel(4,"%K");
SetIndexBuffer(5,Slow); SetIndexStyle(5,DRAW_NONE); SetIndexLabel(5,"Slow");
return(0);
}
int start() {
int ic=IndicatorCounted();
if(!first && Bars-ic>2) ic=reinit(); // åñëè åñòü ïðîïóùåííûå áàðû íå íà ïîäêëþ÷åíèè (â ðàáîòå)
int limit=Bars-ic-1;
for(int i=limit; i>=0; i--) {
// óïðàâëÿþùèé ñèãíàë
double k=iCustom(NULL,0,"_MasterSlave",Source,SourcePeriod,Window,Sensitivity,Signal, 0,i); Master[i]=100*k;
// Óïðàâëÿåìûå ïàðàìåòðû Ñòîõàñòèêà
int Kperiod=KperiodFrom+k*(KperiodTo-KperiodFrom); K[i]=Kperiod; // %K ñòîõàñòêà
int Slowing=SlowingFrom+k*(SlowingTo-SlowingFrom); Slow[i]=Slowing; // Slowing ñòîõàñòèêà
OS[i]=OverSoldFrom+k*(OverSoldTo-OverSoldFrom); OB[i]=100-OS[i]; // óðîâíè ÏÏ/ÏÊ
// Ñòîõàñòèê
Stoch[i]=iStochastic(NULL,0,Kperiod,1,Slowing,0,0, 0,i);
}
first=0; // ñáðîñ ôëàãà ïåðâîãî ïîäêëþ÷åíèÿ
return(0);
}
//+------------------------------------------------------------------+
int reinit() { // äîïîëíèòåëüíàÿ èíèöèàëèçàöèÿ
ArrayInitialize(Stoch,0.0);
ArrayInitialize(Master,0.0);
ArrayInitialize(OB,0.0);
ArrayInitialize(OS,0.0);
ArrayInitialize(K,0.0);
ArrayInitialize(Slow,0.0);
return(0);
}
Comments