Comment obtenir l'angle d'une moyenne mobile ? - page 2

 
Pourriez-vous s'il vous plaît poster un code avec un contexte car mon code continue à retourner un angle de 0 ? Par exemple, trouver l'angle de la SMA 50 sur 10 périodes.
 
jretzloff:
Pourriez-vous s'il vous plaît poster un code avec un contexte car mon code continue à retourner un angle de 0 ? Par exemple, trouver l'angle de la SMA 50 sur 10 périodes.
Pourquoi ne pas poster votre code qui continue à retourner un angle de 0 pour que d'autres puissent vous aider ?
 
DxdCn:
jretzloff:
Pourriez-vous s'il vous plaît poster un code avec un contexte car mon code continue de retourner un angle de 0 ? Par exemple, trouver l'angle de la SMA 50 sur 10 périodes.
Pourquoi ne pas poster votre code qui continue à retourner un angle de 0 pour que d'autres puissent vous aider ?

En fait, c'est parce que c'est plein de conneries que j'ai essayé de le faire fonctionner avec... plein de déclarations d'impression, etc. C'est un hack total pour essayer de tester le calcul pour une utilisation possible dans la visualisation plus tard. Quoi qu'il en soit, le voici :

//+------------------------------------------------------------------+
//|                                                  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);
  }
//+------------------------------------------------------------------+
 

PAS besoin de tant de cdes !
Dans votre cade :
MathArctan(MathTan(((prix1-prix2)/(WindowPriceMax()- WindowPriceMin()))/((SignalPeriod-0. 0)/WindowBarsPerChart())))*180/3.14 ;


Quelle est la signification de "SignalPeriod" et pourquoi ?

Vous savez, généralement, un angle est la relation entre une ligne et un axe X, cette ligne est définie par deux points.
Dans votre calcul, le prix 2 et le prix 1 sont deux valeurs à la même coordonnée X,

Dans ma formule, j'utilise (delt Y) / (delt X) pour calculer l'angle :
MathArctan(MathTan(
((prix1-prix2)/(WindowPriceMax()- WindowPriceMin())) // est delt Y
/
((shift2-shift1)/WindowBarsPerChart()) // est le delt X
))
*180/3.14

 

quelles seraient les valeurs de shift1 et shift2 ? ou d'où sont-elles calculées ? je sais que c'est mon problème mais je ne comprends pas comment l'appliquer avec la moyenne mobile.

 
ici, un angle est la relation entre une ligne et les axes X,
une ligne est définie par deux points.
(price1,shift1), (price2,shift2) sont les coordonnées de ces deux points. shift est identique à x dans votre code.
---------------------------------------------------
En d'autres termes, si vous avez besoin de calculer l'angle de deux lignes, vous avez besoin de 3 ou 4 points (deux lignes ont besoin de 3 ou 4 points pour être définies), et vous avez besoin de plus de connaissances sur les fonctions trigonométriques.
D'après votre code, je suppose que vous voulez calculer l'angle de deux lignes (comme deux lignes de MACD), et non l'angle d'une ligne et de l'axe des X. Donc vous avez besoin de 3 ou 4 points.
Donc vous avez besoin de 3 ou 4 points, vous devriez revoir plus de connaissances sur les fonctions trigonométriques, peut-être la loi des cosinus.
--------------------------
Ou, premièrement, calculer chaque angle d'une des lignes et des axes X, deuxièmement, leur différence est l'angle de ces deux lignes.
 

Merci pour votre réponse, j'essaie seulement de calculer l'angle d'une seule ligne, c'est-à-dire une moyenne mobile et l'axe des x. J'ai suffisamment de connaissances en trigonométrie pour effectuer les calculs, mais pas avec ce qui est disponible sur MT.

très simplement, je voudrais calculer l'angle actuel de la MA à shift 0 avec le second point de référence étant la MA à SignalPeriod ou la MA à ? barres plus tôt. l'autre point de référence serait l'intersection de shift 0 y et de SignalPeriod x.

 
Si c'est le cas, le prix 2 devrait devenir :
price2 = iMA(Symbol(),0,MAPeriod,0, MODE_SMA,PRICE_CLOSE,SignalPeriod) ;

La coordonnée X (SignalPeriod) doit être le dernier paramètre de la fonction iMA(....), et non le 4ème paramètre. (4ème paramètre : ma_shift a une autre signification, ne l'utilisez que si vous savez ce que c'est ! !!!)
Maintenant Ok, essayez encore !
 
  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;
 
Raison: