移動平均線の角度を求めるには? - ページ 2

 
私のコードは角度0を返し続けるので、文脈のあるコードを投稿していただけませんか? 例えば、10期間にわたるSMA50の角度を見つける。
 
jretzloff:
私のコードは角度0を返し続けるので、文脈のあるコードを投稿していただけませんか?例えば、10期間にわたるSMA50の角度を見つける。
:) なぜ、 あなたのコードが角度 0を返し続けることを、他の人があなたを助けられるように投稿しないのですか?
 
DxdCn:
jretzloff です。
私のコードは角度0を返し続けるので、コンテキストを持ついくつかのコードを投稿してもらえますか?例えば、SMA50の角度を10期間にわたって求める。
:) なぜ、 あなたのコードが 角度0を返し続けることを、他の人があなたを助けられるように投稿しないのでしょうか?

基本的に、それは私がそれを動作させるために取得しようとしてきたがらくたの完全であるため、print文の完全な、等。これは、後で可視化で使用する可能性のために計算をテストしようとする完全なハックです。とにかく、それはここにあります。

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

たくさんのcdeは必要ない!
あなたのケードで
MathArctan(MathTan(((price1-price2)/(WindowPriceMax()- WindowPriceMin()))/((SignalPeriod-0. 0)/WindowBarsPerChart())))*180/3.14;


SignalPeriod "の意味とその理由を教えてください。

一般的に、角度とは、2つの点によって定義される線とX軸の間の実線のことです。
あなたの計算では、価格2と価格1が同じX座標にある2つの値です。

私の計算式では、(delt Y) / (delt X)を使って角度を計算します。
MathArctan(MathTan(
((価格1-価格2)/(WindowPriceMax()-WindowPriceMin()))です。//はデルトY
/
((シフト2-シフト1)/WindowBarsPerChart())です。// はデルトX
))
*180/3.14

 

シフト1とシフト2はどのような値なのでしょうか?

 
ここで、角度とは、直線とX軸の間の実線である。
直線は2つの点で定義される。
(price1,shift1), (price2,shift2) はその2つの点の座標です。
--------------------------------------------------------------
つまり、2本の直線の角度を計算する場合、3点か4点が必要で、三角関数の 知識がもっと必要です。
あなたのコードから推測すると、1本の直線とX軸の角度ではなく、任意の2本の直線(MACDの2直線など)の角度を計算したいのでしょう。
そのため、3点か4点必要で、三角関数や余弦の法則の知識をもっと復習する必要があります。
--------------------------
もしくは、1つ目の線とX軸の角度を計算し、その差を2つの線の角度とする。
 



非常に簡単に言うと、私はシフト0のMAの現在の角度を計算したいのですが、2番目の基準点はシグナルピリオドのMAか、それ以前のMAになります。

 
もしそうなら、price2は.に変わるはずです。
price2 =iMA(Symbol(),0,MAPeriod,0, MODE_SMA,PRICE_CLOSE,SignalPeriod) となります。

X座標(SignalPeriod)はiMA(...)関数の第4パラメータではなく、最後のパラメータであるべきです。(4th parather: ma_shift は別の意味で、それが何であるかを知っている人以外は使わないでください!!!)
これでOK、もう一度やってみてください。
 
  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;