Angulo_de__MAs

Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
Angulo_de__MAs
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
/*+------------------------------------------------------------------+
  |                                          Angulo de MAs suave.mq5 |
  |                It calculates the slope of a moving average chart |
  |                                 Slope = Change in price / minute |
  |                                      Angle = Sexagesimal degrees |
  |                                             Smooth line with EMA |
  |                            Copyright © 2013, José Miguel Soriano |
  |                        Almería-Spain,   josemiguel1812@gmail.com | 
  +------------------------------------------------------------------+
  |                            Indicators JMA.mq5, LRMA.mq5, HMA.mq5 |
  |                               Copyright © 2010, Nikolay Kositsin |
  |                                            farria@mail.redcom.ru |
  |                            JMA - http://www.mql5.com/en/code/427 |
  |                           LRMA - http://www.mql5.com/en/code/429 |
  |                            HMA - http://www.mql5.com/en/code/549 |
  +------------------------------------------------------------------+                                            
  |     Place you the SmoothAlgorithms.mqh, IndicatorsAlgorithms.mqh |
  |      and MovingAverages.mqhfiles (http://www.mql5.com/en/code/77)|
  |             to the directory: terminal_data_folder\\MQL5\Include |
  +------------------------------------------------------------------|
*/

#include <MovingAverages.mqh>
#include <SmoothAlgorithms.mqh>
#include <IndicatorsAlgorithms.mqh> 

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   1

#property indicator_type1   DRAW_LINE
#property indicator_color1  clrTurquoise
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

#property indicator_label1  "MaAngSuav"

#property indicator_level1       0
#property indicator_level2       15
#property indicator_level3       -15
#property indicator_level4        30
#property indicator_level5       -30

enum mis_MA_METODOS {SMA,EMA,SMMA,LWMA,DEMA,TEMA,LRMA,HMA,FRAMA,VIDYA,AMA,JMA};

//--- input parameters
input mis_MA_METODOS       MAmetodo       = EMA;            //Method MA
input int                  MAPeriodo      = 14;             //Period MA
input int                  perSuavizado   = 4;              //Smoothing period
input ENUM_APPLIED_PRICE   MAPrecio       = PRICE_TYPICAL;  //Price applied
input int                  velaSalto      = 2;              //Jump into candles slope calculation
input double               factorVisual   = 0.8;            //Set visual angle numeric-image

int JMAperiodSuav       =   6;
int JMAfase             =   100;
int AMAFast             =   5;
int AMASlow             =   14;
int VIDYAcmoPeriodo     =   9;
int maxBarras=-1;                      //Max bars to calculate

int puntMA;
ENUM_TIMEFRAMES marcoTrab=PERIOD_CURRENT;
//--- indicator buffers
double AngBuffer[],MABuffer[],senalBuffer[];
string simbTrab=Symbol();
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   string etiqu="MAAngSuav("+etiquetaMA(MAmetodo,MAPeriodo,MAPrecio, AMAFast, AMASlow)+"-"+
                IaS(perSuavizado)+"-"+IaS(velaSalto)+")- "+abrevPrecio(MAPrecio);
   SetIndexBuffer(0,senalBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,MABuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,AngBuffer,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(AngBuffer,true);
   ArraySetAsSeries(MABuffer,true);
   ArraySetAsSeries(senalBuffer,true);
   PlotIndexSetString(0,PLOT_LABEL,etiqu);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   IndicatorSetString(INDICATOR_SHORTNAME,etiqu);
   switch(MAmetodo)
     {
      case SMA:  puntMA=iMA(simbTrab,marcoTrab,MAPeriodo,0,MODE_SMA,MAPrecio); break;
      case EMA:  puntMA=iMA(simbTrab,marcoTrab,MAPeriodo,0,MODE_EMA,MAPrecio); break;
      case SMMA: puntMA=iMA(simbTrab,marcoTrab,MAPeriodo,0,MODE_SMMA,MAPrecio); break;
      case LWMA: puntMA=iMA(simbTrab,marcoTrab,MAPeriodo,0,MODE_LWMA,MAPrecio); break;
      case AMA:  puntMA=iAMA(simbTrab,marcoTrab,MAPeriodo,AMAFast,AMASlow,0,MAPrecio); break;
      case DEMA: puntMA=iDEMA(simbTrab,marcoTrab,MAPeriodo,0,MAPrecio); break;
      case FRAMA:puntMA=iFrAMA(simbTrab,marcoTrab,MAPeriodo,0,MAPrecio); break;
      case TEMA: puntMA=iTEMA(simbTrab,marcoTrab,MAPeriodo,0,MAPrecio); break;
      case VIDYA:puntMA=iVIDyA(simbTrab,marcoTrab,VIDYAcmoPeriodo,MAPeriodo,0,MAPrecio); break;
      case LRMA: puntMA=iCustom(simbTrab,marcoTrab,"LRMA",MAPeriodo,MAPrecio); break;
      case HMA:  puntMA= iCustom(simbTrab,marcoTrab,"HMA",MAPeriodo,MAPrecio); break;
      case JMA:  puntMA= iCustom(simbTrab,marcoTrab,"JMA",JMAperiodSuav,JMAfase,MAPrecio); break;
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rangoTotal,
                const int preCalculado,
                const int begin,
                const double &price[])
  {
   int k,inicio,limite,nCopiados,nBuffer=0,
   contBarras=preCalculado;

   if(contBarras<0) return(-1);
   else if(contBarras>0) contBarras--;
   if(contBarras==0)inicio=0;
   else inicio=contBarras;
   limite=rangoTotal-contBarras-velaSalto;         // - (MAPeriodo+velaSalto);
   if(maxBarras>0) limite=MathMin(limite,maxBarras);

   nCopiados=CopyBuffer(puntMA,nBuffer,0,rangoTotal-inicio,MABuffer);
   if(nCopiados>0)
     {
      limite=MathMin(limite,nCopiados);
      for(k=inicio; k<limite; k++) AngBuffer[k]=anguloMA(MABuffer,k,marcoTrab,velaSalto,factorVisual,simbTrab);
      ExponentialMAOnBuffer(rangoTotal,preCalculado,begin,perSuavizado,AngBuffer,senalBuffer);
     }
   return(rangoTotal);
  }
//----------------------------------------- ÁNGULO DE MEDIA MOVIL ---------------------------------------------
double anguloMA(double &arrayValores[],int indVela,ENUM_TIMEFRAMES marcoTmp,int barraSalto=2,double factor_visual=0.80,string simb="")
  {                     //DEVUELVE EL ÁNGULO FORMADO POR LA LINEA DE UNA MEDIA MÓVIL, expresado en grados
   double MAactual=0,MAprevia=0;
   double incremento=0,tangente=0,angulo=0;
   if(simb=="") simb=Symbol();
   MAactual= arrayValores[indVela];
   MAprevia= arrayValores[indVela+barraSalto];
   incremento= (MAactual - MAprevia) / valorPunto(simb);                   //Points()
   tangente= incremento / (barraSalto*PeriodSeconds(marcoTmp)/60);         //tangente= incremento en puntos / minutos
   angulo= MathArctan(tangente) / M_PI * 180 * factor_visual;              //ángulo en grados sexagesimales
   return(angulo);
  }
//+------------------------------------- DEFINE ETIQUETA de MA --------------------------------------+
string etiquetaMA(mis_MA_METODOS metodo,int MAPeriodo,ENUM_APPLIED_PRICE MAPrecio,int AMArapida=5,int AMAlenta=14)
  {
   string etiqueta;
   switch(metodo)
     {
      case SMA:
         etiqueta="SMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case EMA:
         etiqueta="EMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case SMMA:
         etiqueta="SMMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case LWMA:
         etiqueta="LWMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case AMA:
         etiqueta="AMA("+IaS(MAPeriodo)+","+IaS(AMArapida)+","+IaS(AMAlenta)+","+abrevPrecio(MAPrecio)+")";
         break;
      case DEMA:
         etiqueta="DEMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case FRAMA:
         etiqueta="FRAM("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case TEMA:
         etiqueta="TEMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case VIDYA:
         etiqueta="VIDYA("+IaS(MAPeriodo)+","+IaS(VIDYAcmoPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case HMA:
         etiqueta="HMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case LRMA:
         etiqueta="LRMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
      case JMA:
         etiqueta="JMA("+IaS(MAPeriodo)+","+abrevPrecio(MAPrecio)+")";
         break;
     }
   return(etiqueta);
  }
//+------------------------------ ABREVIA PRECIO  ------------------------------------+
string abrevPrecio(ENUM_APPLIED_PRICE precio)
  {
   string resp="-";
   switch(precio)
     {
      case PRICE_CLOSE:   resp= "C"; break;
      case PRICE_HIGH:    resp= "H"; break;
      case PRICE_LOW:     resp= "L"; break;
      case PRICE_MEDIAN:  resp= "M"; break;
      case PRICE_OPEN:    resp= "O"; break;
      case PRICE_TYPICAL: resp= "T"; break;
      case PRICE_WEIGHTED:resp= "W";
     }
   return(resp);
  }
//----------------------------------- VALOR DEL PUNTO en precio (Point())---------------------------------
double valorPunto(string simb="")
  {
   if(simb=="") simb=_Symbol;
   double resp=SymbolInfoDouble(simb,SYMBOL_POINT);
   return(resp);
  }
//--------------------------------- DÍGITOS DEL SÍMBOLO ---------------------------------------
int digitosSimb(string simb)
  {
   int numDig=SymbolInfoInteger(simb,SYMBOL_DIGITS);
   return(numDig);
  }
//+------------------------------------ ENTERO A CADENA -----------------------------------------+
string IaS(int valor)
  {
   string resp;
   resp=IntegerToString(valor);
   return(resp);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---