DTS-Monta§a

Author: Sapucay-Monta�a
DTS-Monta§a

This script is a specialized technical analysis tool designed for the MetaTrader platform. It functions as a momentum and trend indicator that translates complex price movements into visual signals, helping traders identify potential entry and exit points in the financial markets.

Core Logic and Functionality

The logic of the script revolves around calculating the relative position of current prices compared to recent historical extremes (the highest highs and lowest lows over a specific period). Here is a breakdown of how that process works:

1. Price Normalization The tool first determines a "reference price" for each candle. Depending on user settings, it can look at the opening price, closing price, high, low, or various mathematical averages of these points. It then compares this price against the highest and lowest values reached during a set timeframe (the "period").

2. Momentum Calculation The script applies a mathematical formula to determine how far the current price has moved away from the center of that historical range. This is refined using a smoothing technique, which prevents the indicator from reacting too erratically to tiny, insignificant price fluctuations. The result is a value that represents the "strength" or "velocity" of the current trend.

3. Trend Identification (Visual Representation) The script translates these calculations into several visual components:

  • Histograms and Lines: It plots the momentum as colored lines and bars in a separate window. Generally, these represent the direction of price flow.
  • Moving Averages: The tool includes dual moving averages that smooth out the data even further, providing a "cleaner" view of the trend's path.

4. Automated Signals and Alerts The core utility for many traders is the script’s ability to identify specific transition points:

  • Entry/Exit Markers: The logic detects when momentum shifts significantly (e.g., moving from negative to positive). When these specific conditions are met, the script can automatically place vertical lines on the chart to mark "Buy" or "Sell" zones.
  • Dynamic Labels: It creates text labels on the chart to provide the exact price level where a trend change was identified.
  • Notifications: If enabled, the script can trigger a pop-up alert on the computer screen to notify the trader immediately when a new signal appears, allowing for faster reaction times.

Summary of User Experience

For a non-programmer, this script acts as an automated "trend scanner." Instead of manually calculating whether a price move is significant enough to trade, the script analyzes the historical range, filters out the noise, and highlights exactly where the momentum is shifting, providing both visual cues on the chart and active alerts.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
7 Views
0 Downloads
0 Favorites
DTS-Monta§a
//+------------------------------------------------------------------+
//| rutina: Sapucay-Montaña.mq4 
//| Acción: Puntos de entrada y salida
//| referencia: Basado en el indicador de Kiko Segui
//| Adaptado: Ruben Dieminger
//+------------------------------------------------------------------+

#property copyright "Sapucay-Montaña"
#property link      "http://analizandoforex.blogspot.com/"

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 White
#property indicator_color4 Green
#property indicator_color5 PowderBlue
#property indicator_color6 PowderBlue
         
double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double MA1buffer[];
double MA2buffer[];


extern color ColorLineaVenta=Red;
extern color ColorLineaCompra=Green;
extern int period=22;
extern int price=0; // 0 or other = (H+L)/2
                    // 1 = Open
                    // 2 = Close
                    // 3 = High
                    // 4 = Low
                    // 5 = (H+L+C)/3
                    // 6 = (O+C+H+L)/4
                    // 7 = (O+C)/2
extern string expl01="0 u otro = (H+L)/2 = Precio Promedio";
extern string expl02="1 = Precio de Apertura";
extern string expl03="2 = Precio de Cierre";
extern string expl04="3 = High";
extern string expl05="4 = Low";
extern string expl06="5 = (H+L+C)/3";
extern string expl07="6 = (O+C+H+L)/4";
extern string expl08="7 = (O+C)/2";

extern bool Mode_Fast= False;
extern bool Signals= false;
extern bool AlertWindow=false;
extern int  MA1period=1, MA2period=1;
extern string Ayudas_TypeMA = "0-SMA, 1-EMA , 2-SMMA, 3-LWMA";
extern int TypeMA1=0;
extern int TypeMA2=3;
double val1,val2;
      
int init()
{
   string short_name;
   short_name="Sapucay-Montaña";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
    
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1,DarkGreen);
   SetIndexBuffer(0,buffer1);
  
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1,Orange);
   SetIndexBuffer(1,buffer2);
  
   SetIndexStyle(2,DRAW_LINE);
   SetIndexLabel(2,"line");
   SetIndexBuffer(2,buffer3);
  

   SetIndexStyle(3,DRAW_LINE);
   SetIndexLabel(3,"Señal");
   SetIndexBuffer(3,buffer4);

   SetIndexStyle(4,DRAW_LINE);
   SetIndexLabel(4,"MA1 "+MA1period);
   SetIndexBuffer(4,MA1buffer);

   SetIndexStyle(5,DRAW_LINE);
   SetIndexLabel(5,"MA2 "+MA2period);
   SetIndexBuffer(5,MA2buffer);
   return(0);
}


int deinit()
{
  int i;
  double tmp;
  
  
   for (i=0;i<Bars;i++)
   {
      ObjectDelete("Compra: "+DoubleToStr(i,0));
      ObjectDelete("Venta: "+DoubleToStr(i,0));
      ObjectDelete("SELL SIGNAL: "+DoubleToStr(i,0));
      ObjectDelete("BUY SIGNAL: "+DoubleToStr(i,0));
      ObjectDelete("EXIT: "+DoubleToStr(i,0));
   }
   return(0);
}


double Value=0,Value1=0,Value2=0,Fish=0,Fish1=0,Fish2=0;

int buy=0,sell=0;

int start()
  {
  int counted_bars=IndicatorCounted();
  int i;
  int barras;
  double _price;
  double tmp;
  
  double MinL=0;
  double MaxH=0;                    
  
  double Threshold=0; 

  if(counted_bars>0) counted_bars--;

  //barras = Bars;&#231;
  barras = Bars-counted_bars;
  if (Mode_Fast)
    barras = 100;
  i = 0;
  while(i<barras)
   {
   MaxH = High[Highest(NULL,0,MODE_HIGH,period,i)];
   MinL = Low[Lowest(NULL,0,MODE_LOW,period,i)];
   
   switch (price)
     {
     case 1: _price = Open[i]; break;
     case 2: _price = Close[i]; break;
     case 3: _price = High[i]; break;
     case 4: _price = Low[i]; break;
     case 5: _price = (High[i]+Low[i]+Close[i])/3; break;
     case 6: _price = (Open[i]+High[i]+Low[i]+Close[i])/4; break;
     case 7: _price = (Open[i]+Close[i])/2; break;
     default: _price = (High[i]+Low[i])/2; break;
     }
   
        
   Value = 0.33*2*((_price-MinL)/(MaxH-MinL)-0.5) + 0.67*Value1;     
   Value=MathMin(MathMax(Value,-0.999),0.999); 
   Fish = 0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
   
   buffer1[i]= 0;
   buffer2[i]= 0;
   
   if ( (Fish<0) && (Fish1>0)) 
   {
      if (Signals)
      {
         VerticalLine("Compra: "+DoubleToStr(i,0),i,STYLE_SOLID,ColorLineaCompra);
         ObjectCreate("EXIT: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
         ObjectSetText("EXIT: "+DoubleToStr(i,0),"Compra "+DoubleToStr(_price,4),7,"Arial",White);
      }
      if (AlertWindow)
      {
         Alert("Compra " + Symbol());
      }
      buy = 0;
   }   
   
   if ((Fish>0) && (Fish1<0))
   {
      if (Signals)
      {
         VerticalLine("Venta: "+DoubleToStr(i,0),i,STYLE_SOLID,ColorLineaVenta);
         ObjectCreate("EXIT: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
         ObjectSetText("EXIT: "+DoubleToStr(i,0),"Venta "+DoubleToStr(_price,4),7,"Arial",White);
      }
      if (AlertWindow)
      {
         Alert("Venta " + Symbol());
      }
      sell = 0;
   }        
    
   if (Fish > 0)
     {
     buffer1[i] = Fish;
     buffer3[i]= Fish;
     }  

   if (Fish < 0)
     {
     buffer2[i] = Fish;  
     buffer3[i]= Fish;
     }

   if (Fish == 0)
     {
     buffer2[i] = 0;  
     buffer3[i]= 0;
     }
        
   tmp = i;
   if ((Fish<-Threshold) && 
       (Fish>Fish1) && 
       (Fish1<=Fish2))
     {     
     if (Signals)
       {
       //ObjectCreate("SELL SIGNAL: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
       //ObjectSetText("SELL SIGNAL: "+DoubleToStr(i,0),"SELL AT "+DoubleToStr(_price,4),7,"Arial",Red);
       }
     sell = 1;
     }

  if ((Fish>Threshold) && 
       (Fish<Fish1) && 
       (Fish1>=Fish2))
    {
    if (Signals)
       {
       //ObjectCreate("BUY SIGNAL: "+DoubleToStr(i,0),OBJ_TEXT,0,Time[i],_price);
       //ObjectSetText("BUY SIGNAL: "+DoubleToStr(i,0),"BUY AT "+DoubleToStr(_price,4),7,"Arial",Lime);
       }
    buy=1;
    }
   
   
   buffer4[i]= Fish1;
   
   
   Value1 = Value;
   Fish2 = Fish1;  
   Fish1 = Fish;
   i++;
   }
   
   for(i=0; i<barras; i++)
   MA1buffer[i]=iMAOnArray(buffer3,Bars,MA1period,0,TypeMA1,i);
   
   for(i=0; i<barras; i++)
   MA2buffer[i]=iMAOnArray(MA1buffer,Bars,MA2period,0,TypeMA2,i);
   //Alert(MA1buffer[i]);
   return(0);
  }
  
//+------------------------------------------------------------------+
// Linea Vertical
//----------------------------------------------------------------------------------------------
int VerticalLine(string s,int i,int st,int Col)    //s=Text Label, i = bar, st=Line Style, Col = color
{
   // uso: VerticalLine("Venta",i,STYLE_SOLID,LineaVenta);

   ObjectDelete(s);
   val1=Low[Lowest(NULL,0,MODE_LOW,BarsPerWindow(),0)];
   val2=High[Highest(NULL,0,MODE_HIGH,BarsPerWindow(),0)];
   ObjectCreate(s,OBJ_TREND,0,Time[i],0,Time[i],900);
   
   // Activar Valores
   ObjectSet(s,OBJPROP_COLOR,Col);
   ObjectSet(s,OBJPROP_WIDTH,1);
   ObjectSet(s,OBJPROP_STYLE,st);
   ObjectSet(s,OBJPROP_RAY,0);
   //ObjectCreate(s,OBJ_TEXT,0,Time[i],val2-Point*16);
   ObjectSetText(s,"",7,"Arial",Col);               
//   ObjectsRedraw();
   return(0);
}

Comments