MA_RSI_BB
Download scriptThis script is a custom technical analysis tool designed to provide a multi-layered view of market momentum and volatility. Rather than relying on raw price action alone, it processes data through three distinct mathematical stages to create a comprehensive visual profile in a separate window on your trading platform.
1. The Core Momentum Foundation (SMA & RSI)
The logic begins by analyzing price movement using a Simple Moving Average (SMA). However, instead of calculating the Relative Strength Index (RSI) based directly on the price (which can be "noisy"), this script calculates the RSI based on the changes in the Moving Average.
By doing this, the tool smooths out minor price fluctuations, ensuring that the momentum readings are derived from established trends rather than instantaneous spikes. The resulting RSI value represents the strength of the upward or downward trend relative to its own historical average.
2. The Dynamic Envelope (Bollinger Bands)
The script takes this smoothed RSI data and applies a Bollinger Band logic to it. Normally, Bollinger Bands are applied to price; here, they are applied to the momentum index itself.
- The Middle Line: This acts as the "equilibrium" for the momentum. In this specific script, it is set as a fixed horizontal level (50), representing a neutral state.
- The Upper and Lower Bands: These lines expand and contract based on the volatility of the RSI. They are calculated by measuring how much the RSI fluctuates away from the middle line over a specific period.
3. Visual Interpretation for the User
When viewing this indicator, you are looking at a "momentum channel." Here is how to interpret the logic visually:
- The Central Line (Gold): This represents the primary smoothed momentum (the RSI). It shows you the current direction and strength of the trend.
- The Boundaries (Aqua & Lime): These represent volatility limits. When the central momentum line pushes toward or outside these bands, it indicates that the market is moving with significant strength or is reaching an extreme state of over-extension.
- Reference Levels: The script includes predefined levels (typically 70 and 30). When the momentum line interacts with these levels in conjunction with the volatility bands, it provides a clearer picture of whether the market is "overbought" or "oversold" relative to its smoothed trend.
Summary of Logic Flow
- Smooth the Price: Convert raw prices into a Moving Average.
- Calculate Momentum: Measure the change in that Moving Average to create an RSI.
- Measure Volatility: Apply Bollinger Bands to that RSI to create a dynamic "trading channel."
- Display: Plot all three components simultaneously so you can see where current momentum sits relative to historical volatility and trend strength.
//æææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
// MA_RSI_BB.mq4 Èíäèêàòîð.
// Ïîñòðîåí íà îñíîâå ñòàíäàðíûõ èíäèêàòîðîâ RSI è ÂÂ îò MetaQuotes Software Corp.
// ÌÀ ñòðîèòñÿ ïî öåíàì çàêðûòèÿ. RSI ñòðîèòñÿ íà îñíîâå ÌÀ.
// Ëèíèè BB ñòðîÿòñÿ íà îñíîâå ìàññèâà RSI.
// Ñåðãåé Êîâàë¸â, Äíåïðîïåòðîâñê, sk@autograf.dp.ua, ICQ 64015987, http://autograf.dp.ua
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ 0 ææ
#property copyright "Copyright SK AutoGraf © 2008"
#property link "http://autograf.dp.ua/"
#property indicator_separate_window // Èíäèêàïòîð â îòäåëüíîì îêíå
#property indicator_minimum 0 // Óðîâåíü ìèíèìóì
#property indicator_maximum 100 // Óðîâåíü ìàêñèìóì
#property indicator_buffers 6 // Êîëè÷åñòâî áóôåðîâ 6
//================================================================================== 1 ==
#property indicator_color1 Gold // Öâåò äëÿ RSI
extern int MA_period= 2; // Ïåðèîä ÌÀ (ðàñ÷¸ò íå ïî Close,à ïî ÌÀ)
extern int RSIPeriod=14; // Ïåðèîä äëÿ ðàñ÷¸òà RSI
extern int Level_1 = 70; // Óðîâåíü 1
extern int Level_2 = 30; // Óðîâåíü 2
double RSIBuffer[]; // Áóôåð äëÿ ðàñ÷¸òà ëèíèè RSI
double PosBuffer[]; // Òåõíè÷åñêèé áóôåð
double NegBuffer[]; // Òåõíè÷åñêèé áóôåð
//---------------------------------------------------------------------------------- 2 --
#property indicator_color4 Aqua // Öâåò âåðõíåé ëèíèè ÂÂ
#property indicator_color5 Lime // Öâåò ñðåäíåé ëèíèè ÂÂ
#property indicator_color6 Aqua // Öâåò íèæíåé ëèíèè ÂÂ
extern int BandsPeriod=20; // Ïåðèîä äëÿ ðàñ÷¸òà ÂÂ
extern double K_Dev=1.5; // Êîýôôèöèåíò óâåëè÷. äëÿ âíåøíèõ ëèíèé
double Up_Buffer[]; // Áóôåð äëÿ ðàñ÷¸òà âåðõíåé ëèíèè ÂÂ
double MovingBuffer[]; // Áóôåð äëÿ ðàñ÷¸òà ñðåäíåé ëèíèè ÂÂ
double Dn_Buffer[]; // Áóôåð äëÿ ðàñ÷¸òà íèæíåé ëèíèè ÂÂ
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ 3 ææ
int init()
{
//================================================================================== 4 ==
string short_name="MA_RSI_BB("+MA_period+","+RSIPeriod+","+BandsPeriod+","+K_Dev+")";
IndicatorShortName(short_name); // Óñòàíîâêà êîðîòêîãî èìåíè
SetLevelValue(1, Level_1); // Óñòàíîâêà óðîâíÿ 1
SetLevelValue(2, Level_2); // Óñòàíîâêà óðîâíÿ 2
//---------------------------------------------------------------------------------- 5 --
SetIndexStyle(0,DRAW_LINE); // Ñòèëü ëèíèè
SetIndexBuffer(0,RSIBuffer); // Ñâÿçü íîìåðà áóôåðà ñ íàçâ. ìàññèâà
SetIndexDrawBegin(0,RSIPeriod); // Íà÷àëî îòðèñîâêè ëèíèè RSI
SetIndexBuffer(1,PosBuffer); // Ñâÿçü íîìåðà áóôåðà ñ íàçâ. ìàññèâà
SetIndexBuffer(2,NegBuffer); // Ñâÿçü íîìåðà áóôåðà ñ íàçâ. ìàññèâà
//---------------------------------------------------------------------------------- 6 --
SetIndexStyle(3,DRAW_LINE); // Ñòèëü ëèíèè
SetIndexBuffer(3,Up_Buffer); // Ñâÿçü íîìåðà áóôåðà ñ íàçâ. ìàññèâà
SetIndexDrawBegin(3,BandsPeriod); // Íà÷àëî îòðèñîâêè âåðõíåé ëèíèè BB
SetIndexStyle(4,DRAW_LINE); // Ñòèëü ëèíèè
SetIndexBuffer(4,MovingBuffer); // Ñâÿçü íîìåðà áóôåðà ñ íàçâ. ìàññèâà
SetIndexDrawBegin(4,BandsPeriod); // Íà÷àëî îòðèñîâêè ñðåäíåé ëèíèè BB
SetIndexStyle(5,DRAW_LINE); // Ñòèëü ëèíèè
SetIndexBuffer(5,Dn_Buffer); // Ñâÿçü íîìåðà áóôåðà ñ íàçâ. ìàññèâà
SetIndexDrawBegin(5,BandsPeriod); // Íà÷àëî îòðèñîâêè íèæíåé ëèíèè BB
//================================================================================== 7 ==
return;
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ 8 ææ
int start()
{
//================================================================================== 9 ==
if(Bars<=RSIPeriod || Bars<=MA_period || Bars<=BandsPeriod) // Åñëè íåäîñòàòî÷íî áàðîâ
return; // Óõîäèì
int counted_bars=IndicatorCounted(); // Êîëè÷åñòâî íåèçìåí¸ííûõ áàðîâ
int i=Bars-counted_bars-1; // Èíäåêñ ïîñëåäíåãî íåïîñ÷èòàííîãî áàðà
//--------------------------------------------------------------------------------- 10 --
while(i>=0) // Öèêë äëÿ âû÷èñëåíèÿ áóôåðîâ
{
double sumn=0.0,sump=0.0; // Òåõíè÷åñêèå ïåðåìåííûå
double MA_n = iMA(NULL, 0, MA_period, 0, MODE_SMMA, PRICE_CLOSE, i);// Òåêóùèé áàð
double MA_n1= iMA(NULL, 0, MA_period, 0, MODE_SMMA, PRICE_CLOSE, i+1);// Ïðåäûäóùèé
double rel = MA_n - MA_n1; // Ðàçíèöà ÌÀ
if(rel>0) sump=rel; // Äâèæåíèå ââåðõ
else sumn=-rel; // Äâèæåíèå âíèç
double positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;// Ìåòîä ðàñ÷¸òà íà
double negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;// îñíîâå ñòàíä. RSI
PosBuffer[i]=positive; // Òåõíè÷. áóôåð íå âûâîäèòñÿ â âèäå ëèíè
NegBuffer[i]=negative; // Òåõíè÷. áóôåð íå âûâîäèòñÿ â âèäå ëèíè
if(negative==0.0) RSIBuffer[i]=0.0; // Àíàëèç äåëåíèÿ íà 0 ïðè âû÷èñë. RSI
else RSIBuffer[i]=100.0-100.0/(1+positive/negative);// Âû÷èñëåíèå RSI
//--------------------------------------------------------------------------------- 11 --
MovingBuffer[i]= 50; // Ïðèíÿòûé âàðèàíò - ñðåäíÿÿ ãîðèçîíàëüí
// MovingBuffer[i]= RSIBuffer[i]; // 2é âàðèàíò - ñðåäíÿÿ = RSI
double sum=0.0; // Òåõí. ïåðåìåííàÿ
int k = i+BandsPeriod-1; // Èíäåêñ ïîñëåäíåãî áàðà äëÿ ðàñ÷¸òà
while(k>=i) // Öèêë äëÿ âû÷èñë. ñóììû êâàäðàòîâ îòêë.
{
double newres = RSIBuffer[k] - MovingBuffer[i]; // Îòêëîíåíèå
sum += newres*newres; // Ñóììà êâàäðàòîâ îòêëîíåíèé
k--;
}
double deviation=K_Dev*MathSqrt(sum/BandsPeriod); // Ñðåäíåå îòêëîíåíèå
Up_Buffer[i]= MovingBuffer[i] + deviation;// Âåðõíÿÿ ëèíèÿ
Dn_Buffer[i]= MovingBuffer[i] - deviation;// Íèæíÿÿ ëèíèÿ
i--;
}
//================================================================================= 12 ==
return;
}
//ææææææææææææææææææææææææææææææææææææ Êîíåö ìîäóëÿ æææææææææææææææææææææææææææææææ 13 ææ
Comments