如何获得两个价格之间的角度

问题描述

我正在尝试计算图表上两个价格之间的角度。本质上,我想计算两个不同的前几天之间的移动平均价格之间的角度。我知道我可以按角度在图表上画一条线,但是这些点之间的角度在两个不同的缩放比例下是不同的(自然)。这归结为不一致的 x 坐标。为了更好地理解,我在下面分享了几张图片

Zoom level 1

Zoom level 2

因此,您可以通过角度看到趋势保持不变,但 MA 会随着您的缩放而移动(随着 x 坐标的移动)。现在,我使用简单的三角函数尝试了以下代码,但我认为这是不正确的。

int getTrendSignal()
   {
      int dayCount1 = 1;
      int dayCount2 = dayCount1 + 29;
      double maPrice1,maPrice2;
      string mySymbol = Symbol();
      double opposite;
      int adjacent = 30;
      const double tangentFactor = 2891.53;
      double totalMAAngle = 0;
      
      for(int d = 1; d <= numberMonths; d++){
         //get prices
         maPrice1 = iMA(mySymbol,PERIOD_D1,60,MODE_EMA,PRICE_CLOSE,dayCount1);
         maPrice2 = iMA(mySymbol,dayCount1);
         
         if(maPrice1 > maPrice2){
            opposite = maPrice1 - maPrice2;
            
            totalMAAngle += MathArctan(adjacent / (opposite * tangentFactor));
         }
         if(maPrice1 < maPrice2){
            opposite = maPrice2 - maPrice1;
            
            totalMAAngle += 180 - MathArctan(adjacent / (opposite * tangentFactor));
         }
         
         //increment day count
         dayCount1 += 30;
         dayCount2 += 30;
      }
      
      totalMAAngle /=  numberMonths;
      printf("MA Angle: " + (string)(totalMAAngle));
      
      if(totalMAAngle>0 && totalMAAngle<=maxBullTrendAngle){ return 1;}
      if(totalMAAngle>=minBearTrendAngle && totalMAAngle<180){ return 0;}
      
      return -1;
   }

所以我不确定我是否采用了正确的方法,因为如果使用三角学需要一致的测量单位。一种长度是价格差异,另一种是时间差异...

如果有人知道如何解决这个问题,那会很有帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)