
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Could you please post some code with context as my code continues to return an angle of 0? For example, find angle of SMA 50 over 10 periods.
Could you please post some code with context as my code continues to return an angle of 0? For example, find angle of SMA 50 over 10 periods.
Basically, because it is full of crap i have been trying to get it to work with. ..full of print statements, etc.. It is a total hack to try and test computation for possible use in visualization later. Anyway, here it is:
NO need so many cdes!
In you cade:
MathArctan(MathTan(((price1-price2)/(WindowPriceMax()- WindowPriceMin()))/((SignalPeriod-0. 0)/WindowBarsPerChart())))*180/3.14;
What is the meaning of "SignalPeriod" and why?
You know,generally, an angle is the realtion betweent a line and X axes, that line is defined by two points.
In your calculation , price2 and price1 are two values at same X coordinate,
In my formula, use (delt Y) / (delt X) to calculate angle :
MathArctan(MathTan(
((price1-price2)/(WindowPriceMax()- WindowPriceMin())) // is delt Y
/
((shift2-shift1)/WindowBarsPerChart()) // is delt X
))
*180/3.14
what would be the values for shift1 and shift2? or where are they calculated from? i know this has been my problem but don't understand how to apply with the moving average.
a line is defined by two points.
(price1,shift1), (price2,shift2) are that two points' coordinate. shift same as x in you code.
---------------------------------------------------
other words, if you need to calculate the angle of any two lines, you need 3 or 4 points ( two line need 3 or 4 points to define) , and need more knowlesge of trigonometric functions.
from you code , I guess you want to calculate the angle of any two lines (like two lines of MACD), not the angle of one line and X axes.
So you need 3 or 4 points , should review more knowlesge of trigonometric functions, maybe law of cosines.
--------------------------
Or , 1st , calculate each angle of one of lines and X axes, 2nd, their difference is the angle of that two lines .
thank you for your response, i am only trying to calculate the angle of a single line, i.e. a moving average and the x-axis. i do know enough about trig to perform the calculations, just not with what is available through MT.
very simply, i would like to calculate the current angle of the MA at shift 0 with the second reference point being the MA at SignalPeriod or MA at ? bars earlier. the other reference point would be the intersect of the shift 0 y and the SignalPeriod x.
price2 = iMA(Symbol(),0,MAPeriod,0, MODE_SMA,PRICE_CLOSE,SignalPeriod);
X coordinate (SignalPeriod) should be last parameter of iMA(....) function, not 4th parather. (4th parather: ma_shift is another meaning, not use it except you know what it is !!!!)
Now Ok, try again!