請問如何撰寫出KD由20以下,向上穿越50後,取D值站上50後對應的K棒最低點為關鍵價
KD關鍵價位
- 359
- 最後發表 acefrank 2024 十一月 21
//指標腳本
//D小於20且突破50的最低價
var: rsv5(0),k5(0),d5(0),myCon(false);
stochastic(9,3,3,rsv5,k5,d5);
condition1=d5<20;
condition2=d5 cross over 50;
if condition1 then myCon=true;
if myCon=true and condition2=true then
begin
plot1(low);
myCon=false;
end;
感謝回復
系統編輯「選股」腳本中無法使用「plot1」。請問要如何修改呢?
假設這選股條件(時間區間三個月)內產生三個最低價想把這三個數值都列入條件該如何新增呢?
你先了解我提供程式的邏輯,並嘗試修改看看。選股用ret=1取代plot1。
有的感謝指導
Input: Length(9), RSVt(3), Kt(3);
Var: RSV(0), k(0), _d(0) ,myCon(false), keyPrice(0);
SetTotalBar(maxlist(Length, 6) * 3);
SetInputName(1, "天數");
SetInputName(2, "RSVt權數");
SetInputName(3, "Kt權數");
RSV = (Close - Lowest(Low, Length)) / (Highest(High, Length) - Lowest(Low, Length)) * 100;
k = RSV * (1 / RSVt) + k[1] * (RSVt - 1) / RSVt;
_d = k * (1 / Kt) + _d[1] * (Kt - 1) / Kt;
condition1 = _d<20;
condition2= _d cross over 50;
if condition1 then myCon=true;
if myCon=true and condition2=true then
begin
keyPrice = Low;
myCon=false;
ret=1;
end;
計算KD可使用內建函數Stochastic,不需要自己寫程式計算。先處理60天內有D小於20且後來突破50的問題,其他的你就自己想辦法。
//60天內D小於20且突破50的最低價
Input: Length(9,"天數"), RSVt(3,"RSVt權數"), Kt(3,"Kt權數"), TotalBar(300,"總天數"), period(60,"期間");
SetTotalBar(TotalBar);
Var: _rsv(0), _k(0), _d(0) ,myCon(false), keyPrice(0), days(0);
stochastic(Length, RSVt, Kt, _rsv, _k, _d);
condition1=_d<20;
condition2=_d cross over 50;
if condition1 then
begin
value1=TotalBar-currentBar;
myCon=true;
end;
if myCon=true and condition2=true then
begin
days=TotalBar-currentBar; //距今天數
myCon=false;
end;
if isLastBar then
if days<>0 and days<=period then
begin
ret=1;
outputField1(date[value1],"D小於20日期");
outputField2(date[days],"D突破50日期");
end;
感謝教學,謝虎大
6 評論