이동 평균의 각도를 구하는 방법은 무엇입니까? - 페이지 2

 
내 코드가 계속 각도 0을 반환하므로 컨텍스트가 있는 코드를 게시해 주시겠습니까? 예를 들어, 10주기 동안 SMA 50의 각도를 찾으십시오.
 
jretzloff :
내 코드가 계속 각도 0을 반환하므로 컨텍스트가 있는 코드를 게시해 주시겠습니까? 예를 들어, 10주기 동안 SMA 50의 각도를 찾으십시오.
:) 왜 당신은 다른 사람이 당신을 돕기 위해 0의 각도를 반환하는 코드를 계속 게시하지 않습니까?
 
DxdCn :
제레츨로프 :
내 코드가 계속 각도 0을 반환하므로 컨텍스트가 있는 코드를 게시해 주시겠습니까? 예를 들어, 10주기 동안 SMA 50의 각도를 찾으십시오.
:) 왜 당신은 다른 사람이 당신을 돕기 위해 0의 각도를 반환하는 코드를 계속 게시하지 않습니까?

기본적으로, 그것은 쓰레기로 가득 차 있기 때문에 나는 그것을 작동시키려고 노력했습니다. ..full of print statements, etc.. 나중에 시각화에서 사용할 수 있도록 계산을 시도하고 테스트하는 것은 완전한 해킹입니다. 어쨌든 여기 있습니다:

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

많은 CD가 필요하지 않습니다!
당신의 케이드에서:
MathArctan (MathTan(((price1-price2)/(WindowPriceMax()- WindowPriceMin()))/((SignalPeriod-0.0)/WindowBarsPerChart())))*180/3.14;


"SignalPeriod"의 의미는 무엇이며 그 이유는 무엇입니까?

일반적으로 각도는 선과 X축 사이의 관계이며 그 선은 두 점으로 정의됩니다.
계산에서 price2와 price1은 동일한 X 좌표에 있는 두 값입니다.

내 공식에서 (delt Y) / (delt X)를 사용하여 각도를 계산합니다.
MathArctan(MathTan(
((price1-price2)/(WindowPriceMax()- WindowPriceMin())) // 델타 Y
/
((shift2-shift1)/WindowBarsPerChart()) // 델타 X
))
*180/3.14

 

shift1 및 shift2의 값은 무엇입니까? 또는 어디에서 계산됩니까? 이것이 내 문제라는 것을 알고 있지만 이동 평균을 적용하는 방법을 이해하지 못합니다.

 
여기서, 각도는 선과 X축 사이의 실수이며,
선은 두 점으로 정의됩니다.
(price1,shift1), (price2,shift2)는 두 점의 좌표입니다. 코드에서 x와 동일하게 이동합니다.
-------------------------------------------------- -
즉, 두 선의 각도를 계산해야 하는 경우 3 또는 4개의 점이 필요하고(2개의 선을 정의하려면 3 또는 4개의 점이 필요함) 삼각 함수 에 대한 더 많은 지식이 필요합니다.
당신이 코드에서 한 줄과 X 축의 각도가 아니라 두 줄의 각도 (MACD의 두 줄과 같은)를 계산하고 싶다고 생각합니다.
따라서 3개 또는 4개의 점이 필요하고 삼각 함수, 아마도 코사인 법칙에 대한 더 많은 지식을 검토해야 합니다.
--------------------------
또는 1st는 선과 X축 중 하나의 각을 계산하고 2nd는 두 선의 각도를 뺀 값입니다.
 

귀하의 응답에 감사드립니다. 저는 단일 선의 각도, 즉 이동 평균 과 x축을 계산하려고 할 뿐입니다. 나는 계산을 수행하기 위해 trig에 대해 충분히 알고 있지만 MT를 통해 사용할 수 있는 것은 아닙니다.

아주 간단하게, 나는 두 번째 기준점이 SignalPeriod 또는 MA에서 0 시프트에서 MA의 현재 각도를 계산하고 싶습니다. 이전 바. 다른 기준점은 시프트 0 y와 SignalPeriod x의 교차점입니다.

 
그렇다면 price2는 다음과 같이 변경되어야 합니다.
price2 = iMA (Symbol(),0,MAPeriod,0,MODE_SMA,PRICE_CLOSE,SignalPeriod);

X 좌표(SignalPeriod)는 4번째 매개변수가 아닌 iMA(....) 함수의 마지막 매개변수여야 합니다. (4번째 파라더: ma_shift는 또 다른 의미이니, 뭔지 안다면 사용하지 마세요!!!!)
이제 다시 시도하십시오!
 
  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;