From:traderslaboratory.com
http://www.traderslaboratory.com/forums/coding-forum/7409-how-do-i-get-angle-ema.html

Input: Price(Close), NumBars(1), MA_length(20);
variable: MA(0), slope(0);

MA = average(price, MA_length);
slope = arctangent((MA - MA[NumBars])/NumBars);

plot1(slope, "slope");
plot2(0,"Zero");




If you need the the degrees instead of the radians change
如果你需要的程度,而不是弧度變化

slope = arctangent((MA - MA[NumBars])/NumBars);

to
slope = arctangent((MA - MA[NumBars])/NumBars)*180/3.141592654;


----------------------------------------------------------------------------
This is the function that I am going to try out for my project. I think that is the closest I can get using the multicharts software.

--------------------------
TLAngle (Function)
Disclaimer
The TLAngle function returns the angle of a trendline.
Syntax
TLAngle(StartPrice, StartBar, EndPrice, EndBar)
Parameters
Name Type Description
StartPrice Numeric Sets the price of the trendline start point.
StartBar Numeric Sets the bar number of the trendline start point.
EndPrice Numeric Sets the price of the trendline end point.
EndBar Numeric Sets the bar number of the trendline end point.
Returns (Double0
A numeric value representing the angle of the specified trendline.
Remarks
To calculate the angle, the function requires that you specify the start and end bars for the trendline as well as the start
and end prices. The inputs StartPrice and EndPrice are the start price and end price, respectively, of the
trendline. They are usually replaced by values such as Close, High, Low, and so on, or are replaced with numeric
series type inputs.
Also, you must offset the Price by its corresponding bar number. For example, if you want the trendline angle for a
line drawn from the Close of ten bars ago to the Close of the current bar, replace the inputs StartPrice,
StartBar, EndPrice, and EndBar with the values Close[10], 10, Close[0], and 0 respectively.
The inputs StartBar and EndBar refer to the bar numbers of the starting and ending points of the trendline. These
inputs must be replaced by positive whole numbers or be replaced with numeric simple type inputs.
The formula used is a simple rise over run calculation to obtain the slope; the formula then takes the arctangent of that
slope. In fact, you can obtain the same value as the TLAngle function by taking the ArcTangent of the TLSlope
function.

備註
計算的角度,功能要求您指定的趨勢線的開始和結束的酒吧以及開始和結束的價格。輸入StartPrice和EndPrice開始價格和年底的價格,分別為趨勢線。他們通常所取代,如關閉,高,低,所以值,或用數字系列類型輸入取代。此外,還必須抵消了其相應的酒吧數量的價格。例如,如果你想從十個酒吧關閉前提請關閉目前酒吧一條線的趨勢線的角度,更換輸入StartPrice,StartBar,EndPrice,EndBar值接近[10],10,關閉[0]和0。的的投入StartBar和EndBar指趨勢線的出發點和落腳點酒吧。這些投入必須更換正整數,或用簡單的數字類型的輸入取代。公式中使用的是較簡單的運行計算獲得斜坡上升的公式,然後以該斜坡的反正切。事實上,你可以得到相同的值作為TLAngle功能通過採取的TLSlope功能的反正切。


Example
Plot1(TLAngle(High,1,High 9);
See Also
TLAngleEasy
--------------------------------------------------------------------------------------------------------------
HI Insideday,

Thanks for this function. I will try this later today to see if there is any difference between TLEasyAngle function which is builtin inside multicharts and your one.

Here is a description of this function.
---------------------------------------

TLAngleEasy (Function)
Disclaimer
The TLAngleEasy function returns the angle of a trendline with one price input.
Syntax
TLAngleEasy(Price, StartBar, EndBar)
Returns (Double)
A numeric value containing the angle of a trendline.
Parameters
Name Type Description
Price Numeric Specifies which bar value (price, function, or formula) to use.
StartBar Numeric Sets the bar number of the trendline start point.
EndBar Numeric Sets the bar number of the trendline end point.
Remarks
This function is similar to TLAngle, except that you cannot specify different prices for the start and end points. This
function uses the same price on the start and end bars.
The formula used is a simple rise over run calculation to obtain the slope; the formula then takes the cotangent of that
slope. In fact, you can obtain the same value as the TLAngleEasy function by taking the ArcTangent of the TLSlope
function.
Example
Plot1(TLAngleEasy(High,1, 9);

----------------------------------------
Insideday,

As I said my platform doesn't provide this function, but the formula I ended up with basically mimics yours. It's basically a pythagorean expression where the length of the adjacent angle is your "NumBars."
However, I found that an easier way to all of this is simply to look for bars outside of the bb (standards of deviation). The StDevs in essence create angles for you and a bar that exceeds the bb exceeds that angle. I hope that makes sense. Not to detract from those of you who are doing it this way.




arrow
arrow
    全站熱搜
    創作者介紹
    創作者 David 的頭像
    David

    FUTURE ATM

    David 發表在 痞客邦 留言(0) 人氣()