OS_Gaussian_trend

Download script
Author: mladen

Overview

The One Side Gaussian Trend indicator is a sophisticated multi-timeframe analysis tool designed to help traders visualize market momentum and trend direction. By utilizing Gaussian smoothing—a mathematical method known for effectively filtering out "noise" while preserving the underlying shape of price movement—the script provides a clearer picture of market dynamics than standard moving averages.

Core Logic and Functionality

The indicator operates by processing price data through several layers of analysis to determine whether the current market environment is bullish (upward) or bearish (downward). Here is a breakdown of how it achieves this:

1. Support and Resistance Identification The script constantly scans recent historical price action to identify key structural points. It specifically looks for:

  • Support Levels: The lowest prices reached within a defined look-back period.
  • Resistance Levels: The highest prices reached within that same period.
  • Median Calculation: It then calculates the midpoint (median) between these two extremes to establish a "central" value for the current price action.

2. Trend Comparison To determine the trend, the tool compares this Median value against a smoothed average of the market price.

  • If the median is higher than the average, it interprets the momentum as positive.
  • If the median is lower than the average, it interprets the momentum as negative.

3. Multi-Timeframe Integration One of the most powerful features of this script is its ability to "look ahead" into different timeframes simultaneously. Instead of just showing you what is happening on your current chart (e.g., the 15-minute chart), it automatically identifies the next four relevant higher timeframes. It then pulls trend data from those larger windows and projects them onto your current view.

4. Visual Representation The results are displayed as a histogram in a separate window. The script uses color-coded bars to differentiate between upward and downward trends across different timeframes:

  • Upward Trends: Represented by one color (Green).
  • Downward Trends: Represented by another color (Orange-Red).

Summary for the Trader

Instead of forcing you to switch back and forth between multiple charts to see the "big picture," this indicator aggregates that information into a single visual display. It allows you to see at a glance whether the short-term momentum aligns with the larger, long-term trends across various time horizons, helping to identify when the market is in a synchronized move or when it is experiencing conflicting signals.

Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
OS_Gaussian_trend
//+------------------------------------------------------------------+
//|                                          One Side Gaussian trend |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 clrOrangeRed
#property indicator_color2 clrGreen
#property indicator_color3 clrOrangeRed
#property indicator_color4 clrGreen
#property indicator_color5 clrOrangeRed
#property indicator_color6 clrGreen
#property indicator_color7 clrOrangeRed
#property indicator_color8 clrGreen
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2
#property indicator_width7 2
#property indicator_width8 2

#property indicator_maximum 4
#property indicator_minimum 0

//
//
//
//
//

#import "OneSideGaussianLibrary.ex4"
void   BuffersInit();
double Smooth(int version,int price,int i);
#import

//
//
//
//
//

extern string _            = "parameters";
extern int    SRPeriod     = 40;
extern int    SRSmoothType = 5;
extern int    MASmoothType = 5;
extern int    MAPrice      = PRICE_CLOSE;

//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double buffer6[];
double buffer7[];
double buffer8[];
string IndicatorFileName;
bool   calculating = false;
bool   gettingBars = false;

//
//
//
//
//

int    frames[4];
int    periods[]={PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1,-1,-1,-1,-1};
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
  {
   SetIndexBuffer(0,buffer1);
   SetIndexBuffer(1,buffer2);
   SetIndexBuffer(2,buffer3);

//
//
//
//
//

   SRSmoothType = MathMax(MathMin(SRSmoothType,7),0);
   MASmoothType = MathMax(MathMin(MASmoothType,7),0);
   if(_=="calculate")
     {
      BuffersInit(); calculating=true;
      return(0);
     }
   if(_=="gettingBars")
     {
      gettingBars=true;
      return(0);
     }

//
//
//
//
//

   SetIndexBuffer(3,buffer4);
   SetIndexBuffer(4,buffer5);
   SetIndexBuffer(5,buffer6);
   SetIndexBuffer(6,buffer7);
   SetIndexBuffer(7,buffer8);
   IndicatorShortName("OS Gaussian trend("+SRPeriod+","+SRSmoothType+","+MASmoothType+")");
   IndicatorDigits(0);
   IndicatorFileName=WindowExpertName();

   int begin=0;
   while(periods[begin]<Period()) begin++;
   frames[0] = periods[begin+0];
   frames[1] = periods[begin+1];
   frames[2] = periods[begin+2];
   frames[3] = periods[begin+3];

//
//
//
//
//

   for(int i=0; i<8; i++)
     {
      SetIndexStyle(i,DRAW_HISTOGRAM);
      string TimeFrameStr="";
      switch(frames[i/2])
        {
         case PERIOD_M1:  TimeFrameStr="(M1)";      break;
         case PERIOD_M5:  TimeFrameStr="(M5)";      break;
         case PERIOD_M15: TimeFrameStr="(M15)";     break;
         case PERIOD_M30: TimeFrameStr="(M30)";     break;
         case PERIOD_H1:  TimeFrameStr="(H1)";      break;
         case PERIOD_H4:  TimeFrameStr="(H4)";      break;
         case PERIOD_D1:  TimeFrameStr="(Dayly)";   break;
         case PERIOD_W1:  TimeFrameStr="(Weekly)";  break;
         case PERIOD_MN1: TimeFrameStr="(Monthly)"; break;
        }

      if((i%2)==0)
         SetIndexLabel(i,"OS trend "+TimeFrameStr+" down");
      else  SetIndexLabel(i,"OS trend "+TimeFrameStr+" up");
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
  {
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(counted_bars==0) limit-=SRPeriod;
//
//
//
//
//

   if(gettingBars) { buffer1[0]=limit; return(0); }
   if(calculating)
     {
      for(i=limit; i>=0; i--)
        {
         buffer2[i] = Smooth(SRSmoothType,PRICE_LOW, i);
         buffer3[i] = Smooth(SRSmoothType,PRICE_HIGH,i);
         double support    = buffer2[ArrayMinimum(buffer2,SRPeriod,i)];
         double resistance = buffer3[ArrayMaximum(buffer3,SRPeriod,i)];
         double median     = (support+resistance)/2;
         double average    = Smooth(MASmoothType,MAPrice,i);

         buffer1[i]=0;
         if(median > average) buffer1[i] =  1;
         if(median < average) buffer1[i] = -1;
        }
      return(0);
     }

//
//
//
//
//

   if(frames[0]>-1) CalculateIt(limit,4,frames[0],buffer1,buffer2);
   if(frames[1]>-1) CalculateIt(limit,3,frames[1],buffer3,buffer4);
   if(frames[2]>-1) CalculateIt(limit,2,frames[2],buffer5,buffer6);
   if(frames[3]>-1) CalculateIt(limit,1,frames[3],buffer7,buffer8);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

void CalculateIt(int limit,int value,int timeFrame,double &bufferu[],double &bufferd[])
  {
   int shifp=EMPTY_VALUE;

   limit=MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,IndicatorFileName,"gettingBars",0,0)*timeFrame/Period()));
   limit-=SRPeriod;
//
//
//
//
//

   for(int i=limit; i>=0; i--)
     {
      bufferu[i] = bufferu[i+1];
      bufferd[i] = bufferd[i+1];

      int shift= iBarShift(NULL,timeFrame,Time[i]);
      if(shift == shifp) continue;

      double trend=iCustom(NULL,timeFrame,IndicatorFileName,"calculate",SRPeriod,SRSmoothType,MASmoothType,MAPrice,0,shift);

      if(trend>0) { bufferu[i] = value; bufferd[i] = EMPTY_VALUE; }
      if(trend<0) { bufferd[i] = value; bufferu[i] = EMPTY_VALUE; }
      shifp=shift;
     }
  }
//+------------------------------------------------------------------+

Comments