TREND_alexcud_Sig_En
Download scriptThis script is a trend-following technical indicator designed for the MetaTrader trading platform. Its primary purpose is to identify market momentum by analyzing multiple timeframes simultaneously and providing visual cues (arrows) on the chart to signal potential shifts in price direction.
Core Logic Overview
The indicator operates on a multi-layered analysis system. Rather than looking at just one timeframe, it evaluates three different timeframes (defined by the user) to ensure that the trading signals are consistent across short, medium, and long-term views.
Analysis Components
To determine the current market trend, the script processes two main types of data:
1. Moving Average Alignment: The script monitors five different Simple Moving Averages (SMAs) across all three selected timeframes. It checks whether these averages are currently sloping upward or downward. If the majority of these averages are trending in the same direction, it adds "weight" to that trend.
2. Awesome Oscillator (AC) Analysis: The script incorporates the Awesome Oscillator logic to detect momentum shifts. It looks for specific patterns in the AC values—specifically identifying "peak" or "valley" formations where the momentum is accelerating or decelerating. When these conditions are met, they significantly increase the weight of the trend signal.
Signal Generation
The indicator uses a weighted scoring system (represented as "ResUp" and "ResDown").
- Bullish Signals: If the combined weight of the moving averages and the oscillator signals across all three timeframes favors an upward move, the script identifies a bullish trend.
- Bearish Signals: Conversely, if the weights favor a downward move, it identifies a bearish trend.
The script specifically looks for "trend flips." It will only display a visual arrow when the market transitions from one state to another (e.g., from a confirmed downtrend to a confirmed uptrend). This helps filter out "noise" and ensures that arrows are only plotted at significant turning points.
Visual Features and Information
- Chart Arrows: The tool places blue arrows for potential buy signals and red arrows for potential sell signals directly on the price chart.
- On-Screen Commentary: If enabled, the script provides a real-time text readout on the chart. This display includes:
- The current trend direction (Up or Down).
- The number of bars since the last trend change.
- A calculated score for both upward and downward momentum across the various timeframes analyzed.
Summary for the User
In essence, this tool acts as a "confluence" indicator. It avoids making a decision based on a single piece of data; instead, it waits until multiple moving averages and momentum oscillators across different timeframes all agree on a direction before notifying you with an arrow.
//+------------------------------------------------------------------+
//| based on: |
//| Èíäèêàòîð íà îñíîâå èíäèêàòîðà âçÿòîãî îòñþäà |
//| http://codebase.mql4.com/ru/1729 |
//| TREND_alexcud v_2. mq4 |
//| Copyright © 2007, Aleksander Kudimov |
//| alexcud@rambler.ru |
//| plots arrows in chart window |
//| Ðèñóåò ñòðåëêè â îñíîâíîì îêíå |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Sergej Solujanov"
#property link "irasol@bk.ru"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
// Äëÿ TF1 - TF3 äîïóñòèìî óñòàíîâèòü
// ñëåäóþùèå çíà÷åíèÿ: TF1-3 folowing values:
// 1 1 ìèíóòà min
// 5 5 ìèíóò
// 15 15 ìèíóò
// 30 30 ìèíóò
// 60 1 ÷àñ hour
// 240 4 ÷àñà
// 1440 1 äåíü day
// 10080 1 íåäåëÿ week
// 43200 1 ìåñÿö mnth
//
extern int TF1 = 15;
extern int TF2 = 60;
extern int TF3 = 240;
extern int maTrendPeriodv_1 = 5;
extern int maTrendPeriodv_2 = 8;
extern int maTrendPeriodv_3 = 13;
extern int maTrendPeriodv_4 = 21;
extern int maTrendPeriodv_5 = 34;
extern int CountBars = 2000; // max bars to count Êîëè÷åñòâî áàðîâ äëÿ ïðîðèñîâêè ñòðåëîê
extern bool showComment = true;
double UPBuffer[];
double DOWNBuffer[];
int Shift;
int TFperiod[], MAperiod[];
int ResUP[], ResDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("asd");
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 228); // arrow buy ñòðåëêà äëÿ áàé
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 230); // arrow sell ñòðåëêà äëÿ ñåëë
SetIndexBuffer(0,UPBuffer);
SetIndexBuffer(1,DOWNBuffer);
SetIndexDrawBegin(0, Bars - CountBars);
SetIndexDrawBegin(1, Bars - CountBars);
ArrayResize (TFperiod,3);
ArrayResize (MAperiod,5);
ArrayResize (ResUP,3);
ArrayResize (ResDown,3);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, i00;
int limit,shift,shi1;
datetime Tbar;
int counted_bars = IndicatorCounted();
int iTF, iPer;
int UP, Down;
int uptrend, old;
double MaSUR, MaPrev;
string gotrend;
if(Bars <= CountBars + 1) return(0);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars-1;
if (limit>CountBars) limit=CountBars;
TFperiod[0] = TF1; TFperiod[1] = TF2; TFperiod[2]=TF3;
MAperiod[0]=maTrendPeriodv_1; MAperiod[1]=maTrendPeriodv_2;
MAperiod[2]=maTrendPeriodv_3; MAperiod[3]=maTrendPeriodv_4;
MAperiod[4]=maTrendPeriodv_5;
UPBuffer[CountBars-1] = Close[CountBars-1];
uptrend = 1;
for(shift = limit; shift >= 0; shift--)
{
UP=0; Down=0;
for(iTF=0; iTF<=2; iTF++)
{
UP=0; Down=0;
for(iPer=0; iPer<=4; iPer++)
{
Tbar= iTime(NULL,0,shift);
shi1=iBarShift(NULL,TFperiod[iTF],Tbar,false);
MaSUR=iMA(NULL,TFperiod[iTF],MAperiod[iPer],0,MODE_SMA,PRICE_CLOSE, shi1);
MaPrev=iMA(NULL,TFperiod[iTF],MAperiod[iPer],0,MODE_SMA,PRICE_CLOSE,shi1+1);
if (MaSUR>MaPrev) UP++;
if (MaSUR<MaPrev) Down++;
}
double ac0v = iAC(NULL, TFperiod[iTF], 0);
double ac1v = iAC(NULL, TFperiod[iTF], 1);
double ac2v = iAC(NULL, TFperiod[iTF], 2);
double ac3v = iAC(NULL, TFperiod[iTF], 3);
if ((ac1v>ac2v && ac2v>ac3v && ac0v<0 && ac0v>ac1v)
|| (ac0v>ac1v && ac1v>ac2v && ac0v>0)) UP=UP+3;
if ((ac1v<ac2v && ac2v<ac3v && ac0v>0 && ac0v<ac1v)
|| (ac0v<ac1v && ac1v<ac2v && ac0v<0)) Down=Down+3;
ResUP[iTF]=UP;
ResDown[iTF]=Down;
}
//
if(shift <= 1)
{
for (i = 1; i <= CountBars; i++)
if ((DOWNBuffer[i] != EMPTY_VALUE) || (UPBuffer[i] != EMPTY_VALUE))
if (DOWNBuffer[i] != EMPTY_VALUE)
{old = -1; i00=i; uptrend = -1; break;}
else
{old = 1; i00= i; uptrend = 1; break;}
//
}
i=4;
if (ResUP[0] > i && ResUP[1] > i && ResUP[2] > i) uptrend = 1;
if (ResDown[0] > i && ResDown[1] > i && ResDown[2] > i) uptrend = -1;
UPBuffer[shift] = EMPTY_VALUE; // buffer 4 buy áóôåð äëÿ áàé ;
DOWNBuffer[shift] = EMPTY_VALUE; // buff 4 sell áóôåð äëÿ ñåëë
if(old == -1 && uptrend == 1)
{
if (shift != 0)
{
UPBuffer[shift+1] = High[shift];
old=uptrend;
}
else
UPBuffer[shift+1] = Bid;
}
//----
if(old == 1 && uptrend == -1)
{
if (shift != 0)
{
DOWNBuffer[shift+1] = Low[shift];
old=uptrend;
}
else
DOWNBuffer[shift+1] = Ask;
}
if (shift != 0) old=uptrend;
if (uptrend == 1) gotrend = "UP";
else gotrend = "DOWN";
if (showComment)
{
Comment("Trend ",gotrend," ",i00," bars", "\nResUp ",
ResUP[0]*12.5," ",ResUP[1]*12.5," ",ResUP[2]*12.5,
"\nResDn ",ResDown[0]*12.5," ",ResDown[1]*12.5," ",ResDown[2]*12.5);
}
}
return;
}
Comments