![]() |
在這個頁面顯示本主題全部的 13 個文章 |
奇狐社區論壇 (http://www.chiefox.com.tw/bbs/index.php)
- 問題交流 (http://www.chiefox.com.tw/bbs/forumdisplay.php?forumid=28)
-- 請教公式 (http://www.chiefox.com.tw/bbs/showthread.php?threadid=19861)
請教公式
版主您好,
我想寫一個公式,一直無法成功,煩請幫我看看問題是出在哪,謝謝!
目標:
買訊:
收盤價上穿5日均線 AND 5日均線>=10日均線.
賣訊:
收盤價跌破10日均線.
規則:
1.只計算第一個買,賣訊(只有:買進---賣出---買進---).
2.賣訊出現後,10天(限制日期)內的買訊不算.
我嘗試寫的公式如下:
買訊:=cross(c,ma(c,5)) and ma(c,5)>=ma(c,10);
賣訊:=cross(ma(c,10),c);
限制日期:10;
倉位:=0;
CC:=C;
for i = 1 to datacount do begin
if 倉位=0 then begin
if 買訊[i] then 買進價:=CC[i];盈虧[i]:=(CC[i]-買進價)*100/買進價;倉位=1;
end else if 倉位=1 then begin
if 賣訊[i] then 賣出價:=CC[i];平倉盈虧[i]:=(賣出價-買進價)*100/買進價;倉位=0;買進價:=0; i = i + 限制日期;
end ;
end;
-----------------------------------------------
這指標顯示:"數組下標越界或超出有效數據區間;"
我剛開始學習寫程式,很沒概念,麻煩您幫我看看要怎麼改,謝謝!
回覆: 請教公式
引用:
最初由 max687 發表
版主您好,
我想寫一個公式,一直無法成功,煩請幫我看看問題是出在哪,謝謝!
目標:
買訊:
收盤價上穿5日均線 AND 5日均線>=10日均線.
賣訊:
收盤價跌破10日均線.
規則:
1.只計算第一個買,賣訊(只有:買進---賣出---買進---).
2.賣訊出現後,10天(限制日期)內的買訊不算.
我嘗試寫的公式如下:
買訊:=cross(c,ma(c,5)) and ma(c,5)>=ma(c,10);
賣訊:=cross(ma(c,10),c);
限制日期:10;
倉位:=0;
CC:=C;
for i = 1 to datacount do begin
if 倉位=0 then begin
if 買訊[i] then 買進價:=CC[i];盈虧[i]:=(CC[i]-買進價)*100/買進價;倉位=1;
end else if 倉位=1 then begin
if 賣訊[i] then 賣出價:=CC[i];平倉盈虧[i]:=(賣出價-買進價)*100/買進價;倉位=0;買進價:=0; i = i + 限制日期;
end ;
end;
-----------------------------------------------
這指標顯示:"數組下標越界或超出有效數據區間;"
我剛開始學習寫程式,很沒概念,麻煩您幫我看看要怎麼改,謝謝!
原碼:
MA5:=ma(c,5); MA10:=ma(c,10); 買訊:cross(c,MA5) and MA5>=MA10 or barpos=0 colorred; 賣訊:cross(MA10,c) or barpos=0 colorgreen; 訊號:=買訊-賣訊; NowBS:=0; Last賣:=0; BS:=訊號*0; 限制日期:=10; for i=1 to datacount do begin if NowBS=1 and 訊號[i]=-1 then begin NowBS:=-1; Last賣:=i; end else if NowBS=-1 and 訊號[i]=1 then begin if i-Last賣>限制日期 then NowBS:=1; end else if NowBS=0 then begin NowBS:=訊號[i]; if NowBS=-1 then Last賣:=i; end; BS[i]:=NowBS; end; BS:=if(BS<>ref(BS,1) or barpos=lbound(BS),BS,0); 買訊:=BS=1; 賣訊:=BS=-1;
感謝版主,我來試試
謝謝版主,我還有2個問題要麻煩您.
1.如果第1個出現的是賣訊,那就不取,這條件只要做多.
2我想顯示從買進到賣出,每天以收盤計算的浮動損益,我自己嘗試的程式如下,但仍完全無法顯示.
原碼如下:
MA5:=ma(c,5); MA10:=ma(c,10);
買訊:cross(c,MA5) and MA5>=MA10 or barpos=0 colorred;
賣訊:cross(MA10,c) or barpos=0 colorgreen;
訊號:=買訊-賣訊; NowBS:=0; Last賣:=0;
CC:=C;
進價:=C*0 NOAXIS;
出價:=C*0 NOAXIS;
BS:=訊號*0; 限制日期:=10;
for i=1 to datacount do begin
if NowBS=1 and 訊號[i]=-1 then begin
出價:=CC[i];平倉盈虧:=(出價-進價)*100/進價;
NowBS:=-1; Last賣:=i;
end else if NowBS=-1 and 訊號[i]=1 then begin
if i-Last賣>限制日期 then
進價:=CC[i];盈虧:=(CC[i]-進價)*訊號*100/進價;NowBS:=1;
end else if NowBS=0 then begin
NowBS:=訊號[i]; if NowBS=-1 then Last賣:=i;
end;
BS[i]:=NowBS;
end;
BS:=if(BS<>ref(BS,1) or barpos=lbound(BS),BS,0);
買訊:=BS=1;
賣訊:=BS=-1;
非常感謝!
引用:
最初由 max687 發表
謝謝版主,我還有2個問題要麻煩您.
1.如果第1個出現的是賣訊,那就不取,這條件只要做多.
1是歷史條件,只用日線.
謝謝
引用:
最初由 max687 發表
1是歷史條件,只用日線.
謝謝
原碼:
MA5:=ma(c,5); MA10:=ma(c,10); 買訊:cross(c,MA5) and MA5>=MA10 or barpos=0 colorred; 賣訊:cross(MA10,c) or barpos=0 colorgreen; 訊號:=買訊-賣訊; NowBS:=0; Last賣:=-99; CC:=C; BS:=訊號*0; 限制日期:=10; 盈虧:訊號*0 linethick; for i=1 to datacount do begin if NowBS=1 and 訊號[i]=-1 then begin NowBS:=-1; Last賣:=i; end else if NowBS=-1 and 訊號[i]=1 then begin if i-Last賣>限制日期 then begin NowBS:=1; 進價:=CC[i]; end; end else if NowBS=0 and 訊號[i]=1 then begin NowBS:=訊號[i]; 進價:=CC[i]; end; BS[i]:=NowBS; if 進價>0 then 盈虧[i]:=CC[i]-進價; if NowBS=-1 then 進價:=0; end; BS:=if(BS<>ref(BS,1) or barpos=lbound(BS),BS,0); 買訊:=BS=1; 賣訊:=BS=-1;
感謝,我趕快去學習!
版主太厲害了!
已經可以用了,把LAST賣設定為-99,我想破頭也想不到.這程式真不是一般人能寫的呀.
非常感謝!
引用:
最初由 max687 發表
版主太厲害了!
已經可以用了,把LAST賣設定為-99,我想破頭也想不到.這程式真不是一般人能寫的呀.
非常感謝!
了解,我還要花好多時間來好好研究這程式.謝謝!
請問如果我要加上:"開始計算的日期"這個限制條件,該怎麼做?
我的寫法如下:
MA5:=ma(c,5); MA10:=ma(c,10);
買訊:cross(c,MA5) and MA5>=MA10 or barpos=0 colorred;
賣訊:cross(MA10,c) or barpos=0 colorgreen;
訊號:=買訊-賣訊; NowBS:=0; Last賣:=-99; CC:=C;
BS:=訊號*0; 限制日期:=10; 盈虧:訊號*0 linethick;
-------------------------------------------------
開始日期:1000;
KK:=max(0,barssince(c)-開始日期);
--------------------------------------------------
我想從1000天前,或是上市日(小於1000天)開始計算,所以加了這2行,希望當底下的i大於KK這個數,再開始計算,但不知要怎麼加進去.
另外,如果要加一個"截止日期"(提前結束,例如:只顯示1000天到500天這段時間的訊號),又該如何?
感謝!
for i=1 to datacount do begin
if NowBS=1 and 訊號[i]=-1 then begin
NowBS:=-1; Last賣:=i;
end else if NowBS=-1 and 訊號[i]=1 then begin
if i-Last賣>限制日期 then begin
NowBS:=1; 進價:=CC[i];
end;
end else if NowBS=0 and 訊號[i]=1 then begin
NowBS:=訊號[i]; 進價:=CC[i];
end;
BS[i]:=NowBS;
if 進價>0 then 盈虧[i]:=CC[i]-進價;
if NowBS=-1 then 進價:=0;
end;
BS:=if(BS<>ref(BS,1) or barpos=lbound(BS),BS,0);
買訊:=BS=1;
賣訊:=BS=-1;
引用:
最初由 max687 發表
請問如果我要加上:"開始計算的日期"這個限制條件,該怎麼做?
我的寫法如下:
MA5:=ma(c,5); MA10:=ma(c,10);
買訊:cross(c,MA5) and MA5>=MA10 or barpos=0 colorred;
賣訊:cross(MA10,c) or barpos=0 colorgreen;
訊號:=買訊-賣訊; NowBS:=0; Last賣:=-99; CC:=C;
BS:=訊號*0; 限制日期:=10; 盈虧:訊號*0 linethick;
-------------------------------------------------
開始日期:1000;
KK:=max(0,barssince(c)-開始日期);
--------------------------------------------------
我想從1000天前,或是上市日(小於1000天)開始計算,所以加了這2行,希望當底下的i大於KK這個數,再開始計算,但不知要怎麼加進去.
另外,如果要加一個"截止日期"(提前結束,例如:只顯示1000天到500天這段時間的訊號),又該如何?
感謝!
...............
全部時間均為台灣時間, 現在時間為12:14 | 在這個頁面顯示本主題全部的 13 個文章 |
Powered by: vBulletin Version 2.3.0 - Copyright©2000-, Jelsoft Enterprises Limited.
簡愛洋行 製作 Copyright 2003-. All Rights Reserved.