請教EMA及TEMA的指標寫法
板上各位大大晚安我是剛入門學習程式交易的新手
在網路上看到EMA感覺比SMA還好很多
但無奈功力不足
跪求神人們指教在TS要寫個EMA和TEMA自設指標要怎麼寫呢?
非常感謝 小弟剛去網路找了一下 參考看看哩input:FastDay(6),SlowDay(12);
variable:EMA_F(0),EMA_S(0);
EMA_F = EMA_F * ((FastDay - 1) / FastDay) + close * ( 1 / FastDay);
EMA_S = EMA_S * ((SlowDay - 1) / SlowDay) + close * ( 1 / SlowDay); /******************************************************************************************
Description: This Indicator plots Exponential Moving Average (EMA) indicator
Provided By: eSignal, a division of Interactive Data Corporation. Copyright2002
******************************************************************************************/
function preMain() {
setPriceStudy(true);
}
var dLastMA = 0.0;
var dThisMA = 0.0;
var dPercent = 0.0;
var dCount = 0;
var bPrimed = false;
function main(nInputLength) {
if(nInputLength == null)
nInputLength = 50;
var nBarState = getBarState();
var i;
var dValue;
var dSum = 0.0;
if(nBarState == BARSTATE_ALLBARS) {
// reset!
dPercent = (2.0 / (nInputLength + 1.0));
dLastMA = 0.0;
dThisMA = 0.0;
dCount = 0;
}
if(nBarState == BARSTATE_NEWBAR) {
dLastMA = dThisMA;
}
dThisMA = dLastMA;
if(bPrimed == false) {
dValue = getValue("Close", 0, -nInputLength);
if(dValue == null)
return;
for(i = 0; i < nInputLength; i++) {
dSum += dValue;
}
dLastMA = dSum / nInputLength;
dThisMA = dLastMA;
bPrimed = true;
} else {
dValue = getValue("Close");
if(dValue == null)
return;
dThisMA = (dValue - dLastMA) * dPercent + dLastMA;
}
return dThisMA;
} 寬哥真的太熱心了, AB, TS都拿手{:4_113:} 寬哥真的太熱心了, AB, TS都拿手
bacardi 發表於 11-8-30 07:30 PM http://www.coco-in.net/images/common/back.gif
網路找到 XD
因為 元大MC 今天開通了
要來 K 一下哩 {:9_582:}{:9_580:} 寬哥
太感謝您了
請受小第一拜 寬哥
小弟去看函數裡面Xaverage的算法
Factor = 2 / (Length + 1)
XAverage = Price*Factor +XAverage*(1 - Factor)
好像就是EMA的計算公式
EMA=Price*(2/N+1)+EMA*( 1-(2/N+1)) 大大客氣了,小弟只是上網找語法啦
我應該是沒幫上忙 XD {:4_187:} 本帖最後由 cxwh 於 11-9-5 06:22 PM 編輯
看看这个是不是你要的效果!
Inputs: Price1(Numeric), Length(Numeric);
Variables: Factor(0),EMAA(0);
If CurrentBar = 1 Then
EMAA = Price1
Else If CurrentBar <= Length -1 Then begin
Factor = 2 / (CurrentBar + 1);
EMAA = Price1 * Factor + (1 - Factor) * EMA;
end
Else begin
Factor = 2 / (Length + 1);
EMAA = Factor * Price1 + (1 - Factor) * EMA;
End ;
EMA=EMAA; TEMA:
Inputs:
Length(14);
Vars:
EMAValue(0),
DbEMAValue(0);
EMAValue = XAverage(Close,Length);
DbEMAValue = XAverage(EMAValue,Length);
plot1(3*EMAValue -3*DbEMAValue+ XAverage(DbEMAValue,Length),"TEMA");
感謝分享程式碼
也許用TEMA的上升 或 下降 當作當前趨勢的確認也不錯 TEMAL1=(3*xaverage(close,L1)) - (3 * xaverage(xaverage(close,L1),L1)) +(xaverage(xaverage(xaverage(close,L1),L1),L1));
以上是從multicharts國外網站抓下來的
程式碼更精簡了
只要設定L1就可以了
頁:
[1]