Indicadores: ATR Probability Levels

 

ATR Probability Levels:

Probables niveles a base de ATR. La «probabilidad» se calcula a base del valor medio pronosticado de ATR y el precio Close del período anterior.


Autor: Mladen Rakic

 

¡Gran indicador ! He creado el mismo utilizando tampones, ¿alguna idea de cómo trazar los niveles de soporte y resistencia para cada día, en lugar de tener sólo el día actual?


Aquí está mi versión hasta el momento. Pero no puedo encontrar una manera de obtener 10 días de barras diarias para cada barra de'marco de tiempo actual' ...

//+------------------------------------------------------------------+
//|B_ATR_Levels.mq5
//+------------------------------------------------------------------+
#property copyright "Skullnick"
#property link      "https://www.mql5.com"
#property version   "1.00"

//--- Configuración de la trama de indicadores
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots   6

#property indicator_type1   DRAW_LINE 
#property indicator_color1  clrDeepSkyBlue
#property indicator_width1  1
#property indicator_label1  "Resistance 1"
#property indicator_style1  STYLE_DASH

#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDeepSkyBlue
#property indicator_width2  1
#property indicator_label2  "Resistance 2"
#property indicator_style2  STYLE_DASH

#property indicator_type3   DRAW_LINE
#property indicator_color3  clrDeepSkyBlue
#property indicator_width3  1
#property indicator_label3  "Resistance 3"
#property indicator_style3  STYLE_DASH

#property indicator_type4   DRAW_LINE
#property indicator_color4  clrOrangeRed
#property indicator_width4  1
#property indicator_label4  "Support 1"
#property indicator_style4  STYLE_DASH

#property indicator_type5   DRAW_LINE
#property indicator_color5  clrOrangeRed
#property indicator_width5  1
#property indicator_label5  "Support 2"
#property indicator_style5  STYLE_DASH

#property indicator_type6   DRAW_LINE
#property indicator_color6  clrOrangeRed
#property indicator_width6  1
#property indicator_label6  "Support 3"
#property indicator_style6  STYLE_DASH

//--- Entradas
input int             inpAtrPeriod   = 21;             // Periodo ATR

//--- Búferes indicadores
double ExtR1Buffer[];
double ExtR2Buffer[];
double ExtR3Buffer[];
double ExtS1Buffer[];
double ExtS2Buffer[];
double ExtS3Buffer[];

// Ponderaciones para Average True Range
double dWeights[];

// Variable global
double dATR           = 0;
double dPreviousClose = 0;
  
//+------------------------------------------------------------------+
//| Función de inicialización del indicador personalizada |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- asignación de búferes indicadores
   SetIndexBuffer(0,ExtR1Buffer,   INDICATOR_DATA);         // Resistencia Nivel 1
   SetIndexBuffer(1,ExtR2Buffer,   INDICATOR_DATA);         // Resistencia Nivel 2
   SetIndexBuffer(2,ExtR3Buffer,   INDICATOR_DATA);         // Resistencia Nivel 3
   SetIndexBuffer(3,ExtS1Buffer,   INDICATOR_DATA);         // Soporte Nivel 1
   SetIndexBuffer(4,ExtS2Buffer,   INDICATOR_DATA);         // Soporte Nivel 2
   SetIndexBuffer(5,ExtS3Buffer,   INDICATOR_DATA);         // Soporte Nivel 3
   
   ArraySetAsSeries(ExtR1Buffer,    true);
   ArraySetAsSeries(ExtR2Buffer,    true);
   ArraySetAsSeries(ExtR3Buffer,    true);
   ArraySetAsSeries(ExtS1Buffer,    true);
   ArraySetAsSeries(ExtS2Buffer,    true);
   ArraySetAsSeries(ExtS3Buffer,    true);
   
   // Redimensionar pesos
   ArrayResize(dWeights, inpAtrPeriod);
 
   // Establecer suavizado
   double dSmoothing = 2.0 / (ArraySize(dWeights) + 1);
   
   // Cálculo de pesos
   for(int i = 0; i < ArraySize(dWeights); i++)  
      dWeights[i] = dSmoothing * MathPow(1 - dSmoothing, i);   
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Función de iteración del indicador personalizada|
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
    
   // Obtener datos diarios y comprobar si hay datos suficientes
   MqlRates oDailyRates[];
   ArraySetAsSeries(oDailyRates, true);
     
   int iLast = 0;
   
   if(prev_calculated == 0)  
      iLast  = rates_total - 1;  
   else 
      iLast  = rates_total - prev_calculated;
   
   //--- Calcular niveles
   for(int i = iLast; i >= 0 && !IsStopped();i--)
   {
      
      int iNumDaysCopied = CopyRates(_Symbol, PERIOD_D1, 1, inpAtrPeriod + 1, oDailyRates);
      if(iNumDaysCopied >= (inpAtrPeriod+1) && bIsNewDay() == true)
      {
        // Calcular el ATR del día
          dATR            = dCalculateATR(oDailyRates);
          dPreviousClose  = oDailyRates[0].close;        
      }
      
      ExtR1Buffer[i] = dPreviousClose + 0.5  * dATR;
      ExtR2Buffer[i] = dPreviousClose + 0.75 * dATR;
      ExtR3Buffer[i] = dPreviousClose + 1.0  * dATR;
      ExtS1Buffer[i] = dPreviousClose - 0.5  * dATR;
      ExtS2Buffer[i] = dPreviousClose - 0.75 * dATR;
      ExtS3Buffer[i] = dPreviousClose - 1.0  * dATR;
   }

//--- valor de retorno de prev_calculado para la siguiente llamada
   return(rates_total);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Calcular ATR|
//+------------------------------------------------------------------+
double dCalculateATR(const MqlRates &oRates[])
{
    double dValue = 0;
    int iIndex    = 0;
    
    for (int i = 0; i < ArraySize(dWeights); i++)
    {
       double dHL   = oRates[i].high - oRates[i].low;
       double dHCp  = MathAbs(oRates[i].high - oRates[i+1].close);
       double dLCp  = MathAbs(oRates[i].low - oRates[i+1].close);
       double dTR   = MathMax(MathMax(dHL, dHCp),dLCp);
       
       dValue +=  dTR * dWeights[iIndex];      
       iIndex++;
    }   
    return dValue;
}

//-----------------------------
// -- Comprobar Nuevo Día
//-----------------------------
bool bIsNewDay(void)
{
   bool bNewDay  = false;
   
   static datetime oDateOld;  
   datetime        oDateNew[1];
   
   MqlDateTime oStructDateOld;
   MqlDateTime oStructDateNew;

   // Copiar Array de Hora Actual a Nueva_Hora
   int iCopyHandle = CopyTime(_Symbol, PERIOD_D1, 0, 1, oDateNew);
   
   TimeToStruct(oDateNew[0] , oStructDateNew);
   TimeToStruct(oDateOld    , oStructDateOld);
   
   // Si copia con éxito
   if(iCopyHandle>0)
   {
      // Si Nuevo Día
      if(oStructDateNew.day != oStructDateOld.day)
      {
         bNewDay  =  true;   
         oDateOld =  oDateNew[0];        
      }
   }      
   return bNewDay;     
}
 
me gustaría una versión mt4 de esto por favor.
 
Cómo cambiar la línea horizontal del indicador en una línea horizontal corta, mostrando sólo el lado derecho.
 
xy618z línea horizontal del indicador en una línea horizontal corta, mostrando sólo el lado derecho.

Hola

puede intentar crear una línea horizontal utilizando

   ObjectCreate(0,_name,OBJ_HLINE,0,0,0);

y el tiempo de inicio + 'n' periodos como tiempo de parada.

 
Anil Varma #:

Hola

puede intentar crear una línea horizontal utilizando

y la hora de inicio + 'n' periodos como hora de finalización.

La línea horizontal siempre se expande en todo el gráfico - no se puede limitar por el parámetro de tiempo: https: //www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_hline

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_HLINE
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_HLINE
  • www.mql5.com
OBJ_HLINE - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Gracias, señor.
 
No se puede compilar tiene 4 errores
 
merky16 # No se puede compilar tiene 4 errores
Publicado en 2018, el código ha evolucionado desde entonces. El autor puede o no actualizarlo, quién sabe.

Disclaimer: Asumo, como has dicho, que contiene errores; no lo he compilado yo mismo.
 
merky16 #:
No se puede compilar tiene 4 errores

No hay errores de compilación