¿Cómo obtener el ángulo de una media móvil? - página 2

 
¿Podría publicar algún código con contexto ya que mi código sigue devolviendo un ángulo de 0? Por ejemplo, encontrar el ángulo de la SMA 50 en 10 períodos.
 
jretzloff:
¿Podría publicar algún código con contexto ya que mi código sigue devolviendo un ángulo de 0? Por ejemplo, encontrar el ángulo de SMA 50 en 10 períodos.
:) ¿por qué no publica su código sigue devolviendo un ángulo de 0 para que otros le ayuden?
 
DxdCn:
jretzloff
¿Podría publicar algún código con contexto ya que mi código sigue devolviendo un ángulo de 0? Por ejemplo, encontrar el ángulo de SMA 50 sobre 10 períodos.
:) ¿por qué no publicas tu código que sigue devolviendo un ángulo de 0 para que otros te ayuden?

Básicamente, porque está lleno de basura que he estado tratando de conseguir que funcione. ..lleno de declaraciones de impresión, etc.. Es un hack total para tratar de probar el cálculo para su posible uso en la visualización más tarde. De todos modos, aquí está:

//+------------------------------------------------------------------+
//|                                                  Angle of MA.mq4 |
//|                                Copyright © 2007,                 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007"
#property link      ""
 
#property indicator_separate_window
#property indicator_minimum -60.0
#property indicator_maximum 60.0
#property indicator_buffers 1
#property indicator_color1 Lime
#property indicator_width1 3
/*#property indicator_color2 Red
#property indicator_width2 3
*/
 
extern int MAPeriod = 50;
extern int SignalPeriod = 10;
 
double posAngle[], negAngle[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 
   IndicatorBuffers(1);
   
   SetIndexBuffer(1, posAngle);
   //SetIndexStyle(1, DRAW_ARROW);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   //SetIndexArrow(1, 110);
   SetIndexLabel(1, "Positive Angle");
   SetIndexEmptyValue(1, 0.0);
   
   /*SetIndexBuffer(2, negAngle);
   //SetIndexStyle(2, DRAW_ARROW);
   SetIndexStyle(2, DRAW_HISTOGRAM);
   //SetIndexArrow(2, 110);
   SetIndexLabel(2, "Negative Angle");
   SetIndexEmptyValue(2, 0.0);*/
   
   ArrayInitialize(posAngle, 0.0);
   //ArrayInitialize(negAngle, 0.0);
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) 
       return(-1);
   if(counted_bars > 0) 
       counted_bars--;
   int limit = Bars - counted_bars; 
   
   double angle = 0.0;
   double price1 = 0.0, price2 = 0.0;
//----
   for(int x = 0; x < limit; x++) 
   {
      //if (x >= MAPeriods) 
      //{
         angle = 0.0;
         price1 = iMA(Symbol(),0,MAPeriod,0, MODE_SMA,PRICE_CLOSE,0);
         price2 = iMA(Symbol(),0,MAPeriod,SignalPeriod, MODE_SMA,PRICE_CLOSE,0);
         double test = (SignalPeriod-0.0)/WindowBarsPerChart();
         //Print("test: ", test);
         Print("Price1/2 ", price1, "/", price2, " angle->", angle);
         Print("price1-price2: ", price1-price2);
         //Print("WindowPriceMin(): ", WindowPriceMin());
         //Print("WindowPriceMax(): ", WindowPriceMax());
         //Print("WindowPriceMax()- WindowPriceMin(): ", WindowPriceMax()- WindowPriceMin());
         //Print("WindowBarsPerChart(): ", WindowBarsPerChart());
         //Print("SignalPeriod: ", SignalPeriod);
         //Print("(SignalPeriod-0)/WindowBarsPerChart()): ", (SignalPeriod-0.0)/WindowBarsPerChart());
         
         
         if (price1-price2 > 0)
            angle = MathArctan(MathTan(((price1-price2)/(WindowPriceMax()- WindowPriceMin()))/((SignalPeriod-0.0)/WindowBarsPerChart())))*180/3.14; 
         else
            angle = 0.0;
            
         Print("Angle > 0: ", angle>0.0);
         Print("Angle < 0: ", angle<0.0);
         
         if (angle > 0.0)
         {
            Print("+++++++++++++++++++ ANGLE +++++++++++++++++++");
            posAngle[x] = angle;
            //negAngle[x] = 0.0;
         }
         else if ( angle < 0.0)
         {
            Print("------------------- ANGLE -------------------");
            //negAngle[x] = angle;
            posAngle[x] = 0.0;  
         }
         else // some error occurred
         {
            Print("******************* ANGLE *******************");
            posAngle[x] = 0.0;
            //negAngle[x] = 0.0;
         }
         
      /*}
      else
      {
         posAngle[x] = 0.0;
         negAngle[x] = 0.0;
      }*/
      Print("posAngle[x]: ", posAngle[x]);
      Print("negAngle[x]: ", negAngle[x]);
      Print("Angle [", TimeToStr(Time[x], TIME_DATE|TIME_MINUTES), "] ---------------------------------------------> ", angle);
   }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

¡NO se necesitan tantos cdes!
En tu cade:
MathArctan(MathTan((precio1-precio2)/(WindowPriceMax()- WindowPriceMin()))/((SignalPeriod-0. 0)/WindowBarsPerChart())))*180/3.14;


¿Cuál es el significado de "SignalPeriod" y por qué?

Usted sabe, generalmente, que un ángulo es la relación entre una línea y los ejes X, esa línea está definida por dos puntos.
En tu cálculo, precio2 y precio1 son dos valores en la misma coordenada X,

En mi fórmula, utilice (delt Y) / (delt X) para calcular el ángulo :
MathArctan(MathTan(
((precio1-precio2)/(WindowPriceMax()- WindowPriceMin())) // es delt Y
/
((cambio2-desplazamiento1)/BarrasDeVentanaPorCarta()) // es delt X
))
*180/3.14

 

¿cuáles serían los valores de shift1 y shift2? o ¿de dónde se calculan? sé que este ha sido mi problema pero no entiendo cómo aplicarlo con la media móvil.

 
aquí, un ángulo es la relación entre una línea y los ejes X,
una línea está definida por dos puntos.
(precio1,shift1), (precio2,shift2) son las coordenadas de esos dos puntos. shift es lo mismo que x en tu código.
---------------------------------------------------
en otras palabras, si necesitas calcular el ángulo de dos líneas cualesquiera, necesitas 3 o 4 puntos (dos líneas necesitan 3 o 4 puntos para definirse), y necesitas más conocimiento de las funciones trigonométricas.
de tu código, supongo que quieres calcular el ángulo de dos líneas cualesquiera (como dos líneas de MACD), no el ángulo de una línea y los ejes X.
Así que necesitas 3 o 4 puntos, deberías repasar más conocimientos de funciones trigonométricas, quizás la ley de los cosenos.
--------------------------
O, primero, calcular cada ángulo de una de las líneas y los ejes X, segundo, su diferencia es el ángulo de esas dos líneas.
 

gracias por su respuesta, sólo estoy tratando de calcular el ángulo de una sola línea, es decir, una media móvil y el eje x. sé lo suficiente sobre trigonometría para realizar los cálculos, sólo que no con lo que está disponible a través de MT.

muy simple, me gustaría calcular el ángulo actual de la MA en el turno 0 con el segundo punto de referencia siendo la MA en SignalPeriod o MA en ? barras antes. el otro punto de referencia sería la intersección del cambio 0 y y el SignalPeriod x.

 
Si es así, el precio2 debería cambiar a :
price2 = iMA(Symbol(),0,MAPeriod,0, MODE_SMA,PRICE_CLOSE,SignalPeriod);

La coordenada X (SignalPeriod) debería ser el último parámetro de la función iMA(....), no el cuarto parámetro. (4to parámetro: ma_shift es otro significado, no lo use a menos que sepa lo que es !!!!)
Ahora bien, ¡intenta de nuevo!
 
  Whats Wrong with this code ? ? ? 
  I am trying to 4 angles but I keep getting a divide 0 error ? 
  Thanks, 
  KK
  
 
  VectorPer = 16;
 
  HighStartPoint       = iHigh(Symbol(),0,VectorPer);
  PreviousBarHigh      = iHigh(Symbol(),0,SIGNALCANDLE+1);
  HighestPoint         = High[iHighest(Symbol(),0,MODE_HIGH,VectorPer,SIGNALCANDLE+1)];
  HighestAngle         = MathArctan(MathTan(((HighStartPoint-HighestPoint)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer-SIGNALCANDLE+1)/WindowBarsPerChart())))*180/3.14;
  PreviousHighBarAngle = MathArctan(MathTan(((HighStartPoint-PreviousBarHigh)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer-SIGNALCANDLE+1)/WindowBarsPerChart())))*180/3.14;
 
  pHighStartPoint       = iHigh(Symbol(),0,VectorPer+1);
  pPreviousBarHigh      = iHigh(Symbol(),0,SIGNALCANDLE+2);
  pHighestPoint         = High[iHighest(Symbol(),0,MODE_HIGH,VectorPer+1,SIGNALCANDLE+2)];
  pHighestAngle         = MathArctan(MathTan(((pHighStartPoint-pHighestPoint)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer+1-SIGNALCANDLE+2)/WindowBarsPerChart())))*180/3.14;
  pPreviousHighBarAngle = MathArctan(MathTan(((pHighStartPoint-pPreviousBarHigh)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer+1-SIGNALCANDLE+2)/WindowBarsPerChart())))*180/3.14;
  
  LowStartPoint        = iLow(Symbol(),0,VectorPer);
  PreviousBarLow       = iLow(Symbol(),0,SIGNALCANDLE);
  LowestPoint          = Low[iLowest(Symbol(),0,MODE_LOW,VectorPer,SIGNALCANDLE+1)];
  LowestAngle          = MathArctan(MathTan(((LowStartPoint-LowestPoint)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer-SIGNALCANDLE+1)/WindowBarsPerChart())))*180/3.14;
  PreviousLowBarAngle  = MathArctan(MathTan(((LowStartPoint-PreviousBarLow)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer-SIGNALCANDLE+1)/WindowBarsPerChart())))*180/3.14;
 
  pLowStartPoint        = iLow(Symbol(),0,VectorPer+1);
  pPreviousBarLow       = iLow(Symbol(),0,SIGNALCANDLE+2);
  pLowestPoint          = Low[iLowest(Symbol(),0,MODE_LOW,VectorPer,SIGNALCANDLE+2)];
  pLowestAngle          = MathArctan(MathTan(((pLowStartPoint-pLowestPoint)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer+1-SIGNALCANDLE+2)/WindowBarsPerChart())))*180/3.1415;
  pPreviousLowBarAngle  = MathArctan(MathTan(((pLowStartPoint-pPreviousBarLow)/(WindowPriceMax()- WindowPriceMin()))/((VectorPer+1-SIGNALCANDLE+2)/WindowBarsPerChart())))*180/3.1415;