iTREND_alexcud(2)

Download script
Author: Copyright � 2008, Sergej Solujanov
iTREND_alexcud(2)

This tool is designed as a visual trend-following indicator for the MetaTrader platform. Its primary purpose is to analyze multiple layers of market data simultaneously to identify shifts in momentum, displaying clear "Buy" and "Sell" arrows directly on your price chart to highlight potential reversals or trend confirmations.

How the Logic Works

Instead of relying on a single piece of information, the script uses a multi-layered verification system. It evaluates three specific criteria across three different timeframes:

1. Moving Average Momentum The script tracks five different Moving Averages (MAs) across three different timeframes. It looks at the relationship between the current value and the previous value for each. If the average prices are trending upward across these various periods, it adds "weight" to a bullish (upward) score. Conversely, if they are trending downward, it contributes to a bearish (downward) score.

2. Accelerator Dynamics In addition to moving averages, the script calculates an "Accelerator" value. It looks for specific mathematical patterns in these values—specifically checking if the rate of change is increasing or decreasing over several consecutive steps. If the acceleration confirms the direction of the move, it significantly boosts the internal score for that trend.

3. Multi-Timeframe Confirmation The core strength of this logic is its "consensus" model. It doesn't just look at the current chart you are viewing. It checks the data for three different time periods (for example, 5 minutes, 15 minutes, and 1 hour) simultaneously. For a signal to be generated, the script seeks a high level of agreement across all these timeframes.

Signal Generation and Visuals

  • The Arrows: The script places blue arrows for upward trends and red arrows for downward trends. These appear when the weighted scores from the moving averages and accelerators reach a specific threshold of agreement across all analyzed timeframes.
  • Trend Stability: To prevent "false signals" or flickering, the logic includes a check to ensure that a new signal is only triggered when there is a definitive reversal from the previous state (e.g., switching from a confirmed downtrend to a confirmed uptrend).
  • On-Screen Dashboard: While the arrows appear on the chart, the script also provides a real-time text commentary in the corner of your screen. This dashboard shows the current trend direction, how many bars it has been active, and the raw "strength scores" for both upward and downward movements.

Summary for the User

Think of this tool as a committee of analysts. One analyst looks at short-term speed, one at medium-term momentum, and one at long-term structure. The script only gives you a "Buy" or "Sell" signal when the majority of these analysts agree that the market is moving in a specific direction with enough strength to be significant.

Indicators Used
Moving average indicatorBill Williams Accelerator/Decelerator oscillator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
iTREND_alexcud(2)
//+------------------------------------------------------------------+
//| Èíäèêàòîð íà îñíîâå èíäèêàòîðà âçÿòîãî îòñþäà                    |
//| http://codebase.mql4.com/ru/1729                                 |
//| TREND_alexcud v_2. mq4                                           |
//| Copyright © 2007, Aleksander Kudimov                             |
//| alexcud@rambler.ru                                               |
//| Ðèñóåò ñòðåëêè â îñíîâíîì îêíå                                   |
//+------------------------------------------------------------------+
#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

//  Äëÿ TF1 - TF3 äîïóñòèìî  óñòàíîâèòü
//  ñëåäóþùèå çíà÷åíèÿ:
//     1   1 ìèíóòà 
//     5   5 ìèíóò
//    15   15 ìèíóò
//    30   30 ìèíóò
//    60    1 ÷àñ
//   240    4 ÷àñà
//  1440    1 äåíü 
// 10080    1 íåäåëÿ 
// 43200    1 ìåñÿö 
//
extern int TF1 = 5;
extern int TF2 = 15;
extern int TF3 = 60;
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;   // Êîëè÷åñòâî áàðîâ äëÿ ïðîðèñîâêè ñòðåëîê

double  UPBuffer[];
double  DOWNBuffer[];
int     Shift;
int     TFperiod[], MAperiod[];
int     ResUP[], ResDown[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+

int init()
 {
 IndicatorShortName("asd");
 SetIndexStyle(0, DRAW_ARROW,DRAW_ARROW,2);
 SetIndexArrow(0, 228);        // ñòðåëêà äëÿ áàé
 SetIndexStyle(1, DRAW_ARROW,DRAW_ARROW,2);
 SetIndexArrow(1, 230);        // ñòðåëêà äëÿ ñåëë
 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;     // áóôåð äëÿ áàé   ;
   DOWNBuffer[shift] = EMPTY_VALUE;   // áóôåð äëÿ ñåëë

   if(old == -1 && uptrend == 1)
      {
        if (shift != 0) 
             {
              UPBuffer[shift+1] = Close[shift];
              old=uptrend;
              }
             else 
              UPBuffer[shift+1] = Bid;
       }
//----
   if(old == 1 && uptrend == -1)
      {
        if (shift != 0) 
             {
              DOWNBuffer[shift+1] = Close[shift];
              old=uptrend;
              }
             else 
              DOWNBuffer[shift+1] = Ask;
       }
   if (shift != 0) old=uptrend; 
   if (uptrend == 1) gotrend = "UP";
        else gotrend = "DOWN";    

   Comment("Trend ",gotrend," ",i00," bars", "\nResUP    ",
           ResUP[0]*12.5,"   ",ResUP[1]*12.5,"   ",ResUP[2]*12.5,
           "\nResDown  ",ResDown[0]*12.5,"   ",ResDown[1]*12.5,"   ",ResDown[2]*12.5);
 }  
return;
}

Comments