sinTrendM4c_SigL_mtf

Download script
Author: Copyright � 2005, DVYU.

Overview of sinTrend Logic

The sinTrend indicator is designed to identify and visualize market trends by analyzing price oscillations and momentum. Rather than simply looking at where the price is currently moving, this tool calculates the "wave-like" behavior of the market to help traders distinguish between active trends and sideways price action.

How the Logic Works

The script operates through three primary layers of data processing:

1. Multi-Timeframe Trend Analysis

One of the core features of this indicator is its ability to look at higher timeframes while you are viewing a lower one. It automatically synchronizes with specific market cycles (such as Daily, Weekly, or Hourly trends). By doing this, the indicator ensures that the signals you see on your immediate chart are consistent with the broader "big picture" of the market.

2. The Sine Wave Calculation

The core engine uses a mathematical function called a Sine Wave. In trading terms, this is used to smooth out price noise.

  • The script looks at the distance between current prices and historical prices over a specific period (the "Global Period").
  • It converts this distance into a fluctuating wave value.
  • This helps filter out small, insignificant price movements and highlights the actual direction of the momentum.

3. Signal Smoothing & Trend Mapping

To make the data readable and actionable, the script applies further refinements:

  • Smoothing: It takes the raw sine wave values and applies a Moving Average calculation. This reduces "jitter" and provides a cleaner line for the user to follow.
  • Trend Segmentation: The indicator categorizes these waves into different visual buckets based on whether they are rising or falling and whether they are above or below the zero line.
  • Visual Output: These categories are displayed as distinct histograms. By separating the data into these specific segments, the indicator allows you to see not just that a trend is happening, but the intensity and momentum of that trend in real-time.

Summary for the Trader

Instead of providing a simple "up or down" arrow, sinTrend provides a sophisticated visual map of market momentum. It tells you:

  1. Direction: Is the current wave moving toward the top or bottom?
  2. Strength: How fast is that wave accelerating?
  3. Context: How does this movement align with the higher timeframe trends?
Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
sinTrendM4c_SigL_mtf
//+------------------------------------------------------------------+
//|   sinTrend                                          TrendOSC.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
//mod2008fxtsd mladen ki   sinTrendM4c_SigL_mtf
#property copyright "Copyright © 2005, DVYU."
#property link      "http://www.DVYU.ox"

#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 OrangeRed
#property indicator_color3 DarkOrange
#property indicator_color4 Red
#property indicator_color5 DodgerBlue

#property indicator_separate_window
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1

//
//
//
//
//

extern int     TimeFrame          = 0;//ïàðàìåòðû
extern bool    useCustom_g_period = false;
extern int     Custom_g_period    = 36;//Îáúÿâëåíèå ãëîáàëüíûõ ïåðåìåííûõ

extern int    SigMAPeriod        = 5;
extern int    SigMAMode          = 0;

extern string  TimeFrames         = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern string  defaultGperiods.TF = "110M1;905M,60M15,42M30,36H1;24H4;18D1;12W1;3MN1";

//
//
//
//
//

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

double SigBuffer[];
double z_buffer[];
double z_buffer1[];

int g_period; //Îáúÿâëåíèå ãëîáàëüíûõ ïåðåìåííûõ


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
{
   IndicatorBuffers(7);  
      SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
      SetIndexBuffer(1,ExtMapBuffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
      SetIndexBuffer(2,ExtMapBuffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
      SetIndexBuffer(3,ExtMapBuffer4); SetIndexStyle(3,DRAW_HISTOGRAM);
      SetIndexBuffer(4,SigBuffer);     SetIndexStyle(5,DRAW_HISTOGRAM);
      SetIndexBuffer(5,z_buffer);
      SetIndexBuffer(6,z_buffer1);

   //
   //
   //
   //
   //
     
   TimeFrame = MathMax(TimeFrame,Period());
      switch(TimeFrame)
      {
         case 1 : string TimeFrameStr="M1";  g_period=110; break;
         case 5 :        TimeFrameStr="M5";  g_period=90;  break;
         case 15 :       TimeFrameStr="M15"; g_period=60;  break;
         case 30 :       TimeFrameStr="M30"; g_period=42;  break;
         case 60 :       TimeFrameStr="H1";  g_period=36;  break;
         case 240 :      TimeFrameStr="H4";  g_period=24;  break;
         case 1440 :     TimeFrameStr="D1";  g_period=18;  break;
         case 10080 :    TimeFrameStr="W1";  g_period=12;  break;
         case 43200 :    TimeFrameStr="MN1"; g_period=3;   break;
         default :       TimeFrameStr="TF 0";
      } 
   string ShortName = ("sinTrend ["+TimeFrameStr+"] default_g ("+g_period+")");
 
 
   if (useCustom_g_period)  
                           {  g_period = Custom_g_period ;
                              ShortName = (ShortName + " | g ("+g_period+")");
                           }

   //
   //
   //
   //
   //
   
          IndicatorShortName(ShortName);
   return(0);
}
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
  {
   int counted_bars=IndicatorCounted();
   int    i,limit,y;
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
          limit= Bars-counted_bars;
          limit= MathMax(limit,TimeFrame/Period());
   
   //
   //
   //
   //
   //
   
   datetime TimeArray[],TimeArray1[]; 
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame); 

      for(i=0,y=0;i<limit;i++)
      {
         if (Time[i]<TimeArray[y]) y++;
         z_buffer[i] = MathSin((iClose(NULL,TimeFrame,y)-iClose(NULL,TimeFrame,y+g_period))/g_period);
         z_buffer1[y] = z_buffer[i];
      }
   

      for(i=0,y=0;i<limit;i++)
      {
         if (Time[i]<TimeArray1[y]) y++;
         SigBuffer[i]=iMAOnArray(z_buffer1,0,SigMAPeriod,0,SigMAMode,y);
      }

   //
   //
   //
   //
   //
   
   for(i=limit;i>=0;i--)
   {
      if (z_buffer[i]==z_buffer[i+1])   
      {
         ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
         ExtMapBuffer2[i]=ExtMapBuffer2[i+1];
         ExtMapBuffer3[i]=ExtMapBuffer3[i+1];
         ExtMapBuffer4[i]=ExtMapBuffer4[i+1];
         continue;
      }        
      
      //
      //
      //
      //
      //
          
      ExtMapBuffer1[i]=EMPTY_VALUE;
      ExtMapBuffer2[i]=EMPTY_VALUE;
      ExtMapBuffer3[i]=EMPTY_VALUE;
      ExtMapBuffer4[i]=EMPTY_VALUE;

         if (z_buffer[i]>0)
         {
             if (z_buffer[i] > z_buffer[i+1])
                 ExtMapBuffer1[i] = z_buffer[i];
            else ExtMapBuffer2[i] = z_buffer[i];
         }         
         if (z_buffer[i]<0)
         {
            if (z_buffer[i] > z_buffer[i+1])
                 ExtMapBuffer3[i] = z_buffer[i];
            else ExtMapBuffer4[i] = z_buffer[i];
         }         
   }
    
   return(0);
}

Comments