Priliv_001
Download scriptThe following description outlines the logical framework and functional behavior of the "Priliv" indicator.
Overview
This indicator is designed to provide traders with a multi-layered visualization of market trends by analyzing moving averages. It works by calculating standard trend lines and then applying a sophisticated mathematical "offset" or "momentum" calculation to generate three distinct visual paths on the chart. These paths help in identifying the speed, strength, and potential reversal points of price movements across different timeframes.
Dynamic Timeframe Adaptation
One of the primary logical features of this script is its ability to automatically adjust its internal parameters based on the chart's timeframe. The logic includes a predefined switch: depending on whether you are viewing 1-minute, 5-minute, hourly, or daily charts, the indicator changes its internal multipliers (K2 and K3). This ensures that the visual data remains relevant and properly scaled regardless of whether you are day trading or swing trading.
Core Calculation Logic
The script operates using four primary visual buffers (lines):
1. The Base Trend Line: The first line is a standard Linear Weighted Moving Average (LWMA). It serves as the foundational baseline for the other calculations, providing a smooth representation of the current price action.
2. Momentum and Velocity Offsets: The three remaining lines are not simple moving averages. Instead, they are generated through a "sliding window" calculation:
- Difference Analysis: The script looks at a specific moving average and compares it to several historical versions of itself shifted backward in time (using a decreasing coefficient).
- Summation: It calculates the difference between these various points and sums them up.
- Weighting: This sum is then factored back into a final calculation that combines the current trend with the calculated "momentum" of the previous price action.
Multi-Layered Analysis
By creating these three different variations (Buf_2, Buf_3, and Buf_4), the indicator allows for a tiered analysis:
- Short-term behavior: One line reacts more quickly to immediate price changes.
- Medium-term behavior: Another provides a balanced view of current momentum.
- Long-term behavior: The final line captures the broader trend, smoothed out by much larger internal multipliers.
Summary of Operation
The logic essentially "scans" backward from the current price to see how the trend has been evolving over time. By measuring the gap between where the trend is and where it was (and applying specific weights to those gaps), the indicator creates a visual representation of market "energy." When these lines move in harmony or diverge significantly, they provide a visual cue regarding the strength and direction of the current market move.
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
// Priliv.mq4
// Ðàçâîðîòíûé èíäèêàòîð.
// Ðàñïðîñòðàíÿåòñÿ áåñïëàòíî áåç îãðàíè÷åíèé.
// Ñåðãåé Êîâàë¸â, Äíåïðîïåòðîâñê, sk@mail.dnepr.net
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
//
//
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 White
#property indicator_color2 Wheat
#property indicator_color3 DarkSeaGreen
#property indicator_color4 DarkSalmon
//--------------------------------------------------------------------------------------------------------------------
double Buf_1[]; // Áóôôåð îïîðíîé MA
double Buf_2[]; // Áóôôåð èíäèêàòîðà òåêóùåãî ÒÔ
double Buf_3[]; // Áóôôåð èíäèêàòîðà áëèæàéøåãî áîëüøåãî ÒÔ
double Buf_4[]; // Áóôôåð èíäèêàòîðà ñëåäóþùåãî áîëüøåãî ÒÔ
double MA_0, MA_11, MA_12, MA_13, MA_14;
double Polzun_1[21],Polzun_2[21],Polzun_3[21],Line[21];
double KK=1.2;
double K=5;
//--------------------------------------------------------------------------------------------------------------------
int i,n,k, counted_bars, K2, K3, Period_MA_2, Period_MA_3;
int Period_MA_0 = 8;
int Period_MA_1 = 21;
int Kol_Line=20;
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
int init()
{
switch(Period())
{
case 1: K2=5; K3=15; break;
case 5: K2=3; K3= 6; break;
case 15: K2=2; K3= 4; break;
case 30: K2=2; K3= 8; break;
case 60: K2=4; K3=24; break;
case 240: K2=6; K3=42; break;
case 1440: K2=7; K3=30; break;
case 10080: K2=4; K3= 0; break;
case 43200: K2=0; K3= 0; break;
}
Polzun_1[1]=20;
Polzun_2[1]=Polzun_1[1]*K2; Period_MA_2=Period_MA_1*K2;
Polzun_3[1]=Polzun_1[1]*K3; Period_MA_3=Period_MA_1*K3;
//--------------------------------------------------------------------------------------------------------------------
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer(0,Buf_1);
//--------------------------------------------------------------------------------------------------------------------
SetIndexStyle (1,DRAW_LINE);
SetIndexBuffer(1,Buf_2);
//--------------------------------------------------------------------------------------------------------------------
SetIndexStyle (2,DRAW_LINE);
SetIndexBuffer(2,Buf_3);
//--------------------------------------------------------------------------------------------------------------------
SetIndexStyle (3,DRAW_LINE);
SetIndexBuffer(3,Buf_4);
//--------------------------------------------------------------------------------------------------------------------
return(0);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
int start()
{
counted_bars=IndicatorCounted();
i=Bars-counted_bars-1;
//--------------------------------------------------------------------------------------------------------------------
for (n=2;n<=Kol_Line;n++)
{
k=n-1;
Polzun_1[n]=Polzun_1[k]/KK;
Polzun_2[n]=Polzun_2[k]/KK;
Polzun_3[n]=Polzun_3[k]/KK;
}
//====================================================================================================================
while(i>=0)
{
//--------------------------------------------------------------------------------------------------------------------
MA_0 = iMA( NULL, 0, Period_MA_0, 0, MODE_LWMA, PRICE_TYPICAL, i );
Buf_1[i]=MA_0; // Îïîðíàÿ ÌÀ
//--------------------------------------------------------------------------------------------------------------------
Buf_2[i]= 0;
MA_11 = iMA( NULL, 0, Period_MA_1, 0, MODE_LWMA, PRICE_TYPICAL, i );
for (n=1;n<=Kol_Line;n++)
{
MA_12 = iMA( NULL, 0, Period_MA_1, 0, MODE_LWMA, PRICE_TYPICAL, i +Polzun_1[n]);
Line[n] = MA_11-MA_12;
Buf_2[i] = Buf_2[i]+Line[n];
}
Buf_2[i]= MA_0 + K*Buf_2[i]/Kol_Line;
//--------------------------------------------------------------------------------------------------------------------
Buf_3[i]= 0;
MA_11 = iMA( NULL, 0, Period_MA_2, 0, MODE_LWMA, PRICE_TYPICAL, i );
for (n=1;n<=Kol_Line;n++)
{
MA_12 = iMA( NULL, 0, Period_MA_2, 0, MODE_LWMA, PRICE_TYPICAL, i +Polzun_2[n]);
Line[n] = MA_11-MA_12;
Buf_3[i] = Buf_3[i]+Line[n];
}
Buf_3[i]= iMA( NULL, 0, Period_MA_0*K2, 0, MODE_LWMA, PRICE_TYPICAL, i) + K*Buf_3[i]/Kol_Line;
if (K2==0)Buf_3[i]=0;
//--------------------------------------------------------------------------------------------------------------------
Buf_4[i]= 0;
MA_11 = iMA( NULL, 0, Period_MA_3, 0, MODE_LWMA, PRICE_TYPICAL, i );
for (n=1;n<=Kol_Line;n++)
{
MA_12 = iMA( NULL, 0, Period_MA_3, 0, MODE_LWMA, PRICE_TYPICAL, i +Polzun_3[n]);
Line[n] = MA_11-MA_12;
Buf_4[i] = Buf_4[i]+Line[n];
}
Buf_4[i]= iMA( NULL, 0, Period_MA_0*K3, 0, MODE_LWMA, PRICE_TYPICAL, i) + K*Buf_4[i]/Kol_Line;
if (K3==0)Buf_4[i]=0;
//--------------------------------------------------------------------------------------------------------------------
i--;
}
//====================================================================================================================
return(0);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
int deinit()
{
return(0);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
Comments