I am trying to calculate the angle between two prices on a chart. Essentially I would like to calculate the angle between a moving average price between two different previous days. I understand that I can draw a line on a chart by angle, but the angle between these points are different at two different zooms (naturally). This comes down to the inconsistent x co-ordinate. I have shared a couple images below for better understanding:
So as you can see the trend by angle remains constant, but the MA moves as you zoon (as the x-coord shifts). Now, I have tried with the below code using simple trigonomtery, but I don't think this is correct.
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, 0, MODE_EMA, PRICE_CLOSE, dayCount1);
maPrice2 = iMA(mySymbol, PERIOD_D1, 60, 0, MODE_EMA, PRICE_CLOSE, 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;
}
So I am not sure if I am taking the correct approach because if using trigonometry would require consistent units of measure. One length is a price differential and another is a time differential...
If anyone knows how to solve this, that would be helpful!
question from:
https://stackoverflow.com/questions/65873284/how-to-get-angle-between-two-prices 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…