請教各位大神程式問題

  •   337 
  • 最後發表   XQ小菜鳥  2025 一月 14
XQ小菜鳥 發文於   2025/01/12

input:day1(5,"短均線");

input:day2(10,"短中均線");

input:day3(20,"中均線");

input:day4(60,"中長均線");

input:day5(120,"長均線");

input:day6(240,"超長均線");

settotalBar(25000);

var:rsv1(0),k1(0),d1(0);

var:rsvd(0),kd(0),dd(0);

stochastic(9,3,3,rsv1,k1,d1);

xf_Stochastic("D",9,3,3,rsvd,kd,dd);

var:intraBarPersist BP(0);

Input: Length(20, "期數"), UpperBand(2, "通道上緣"), LowerBand(2, "通道下緣");

variable: mid(0), up(0), down(0);

up = bollingerband(Close, Length, UpperBand);

down = bollingerband(Close, Length, -1 * LowerBand);

mid = (up + down) / 2;

condition1 = k1 > d1;

condition2 = v >66;

condition3 = c cross over average(c,day3);

condition6 = c > average(c,day1);

condition10 = kd < 10 and dd <10;

condition11 = c > average(c,day1) and c > average(c,day2) and c > average(c,day3) and c > average(c,day4)

  and c > average(c,day5) and c > average(c,day6);

condition7 = c > average(c,day3);

condition9 = k1 > k1[1];

condition8 = c < filledAvgPrice - 125 ;

//開始做空

condition21 = c < average(c,day1) and c < average(c,day2) and c < average(c,day3) and

  c < average(c,day4) and c < average(c,day5) and c < average(c,day6);//跟condition12相同了

condition22 = v >= 258;

condition23 = k1 < d1;

condition24 = c >= average(c,day2) + 8;

condition25 = k1 < d1;

//多單進場

if position = 0 and filled = 0 then

begin

if condition1 and condition2 and condition3 and condition5 and condition6 then

setposition(1,market);

end;

//多單再度進場

if position = 0 and filled = 0 and BP = 1 then

if condition1 and condition2 and condition7 and condition5 and condition6 and condition9 then

begin

setposition(1,market);

BP = 2;

end;

//多單加碼

if position = 1 and filled = 1 and kd < 88 and dd < 82 then

begin

if condition1 and condition2 and condition3 and condition5 and condition6 and condition8 then

setposition(2,market);

end;

//抄底進場

if position = 0 and filled = 0 then

if condition10 and condition11 and condition5 then

begin

setposition(1,market);

BP = 8;

end;

//多單出場2口

if position = 2 and filled = 2 then

begin

if (c > filledAvgPrice + 45 and c < average(c,day3)-5)

then setposition(0,market);

end;

//多單出場1口

if position = 1 and filled = 1 then

begin

if (c > filledAvgPrice + 90 and c < average(c,day3)-5)

then setposition(0,market);

end;

//多單跌破布林上軌且賺超過150點出場

if position > 1 and filled > 1 then

if c cross under up and c[1] > filledAvgPrice + 258 then

begin

setposition(0,market);

BP = 1;

end;

if position = 1 and filled = 1 then

if c cross under up and c > filledAvgPrice + 150 then

begin

setposition(0,market);

BP = 1;

end;

//開始做空

if position >= 0 and filled >= 0 then

begin

if condition21 and condition22 and condition23 then

setposition(-1,market);

end;

//空單回補並翻多

if position <= -1 and filled <= -1 then

begin

if condition24 or c > l + 100 then

setposition(1,market);

BP = 7;

end;

//空單翻多的停利

if position >= 1 and filled >= 1 and BP = 7 then

begin

if condition25 then

setposition(0,market);

BP=0;

end;

 

print(

datetostring(date),

timetostring(time),

".成本",numtoStr(filledAvgPrice,1),

".C",numtoStr(c,0),

".V",numtoStr(v,0),

".avg(c,d1)",numtoStr(average(c,day1),0),

".avg(c,d3)",numtoStr(average(c,day3),0),

".BP",numtoStr(BP,0),

".k1",numtoStr(k1,2),

",d1",numtoStr(d1,2),

",kd",numtoStr(kd,2),

",dd",numtoStr(Dd,2));

 

 

想請教各位大神最後一段

//空單翻多的停利

好像都進不去

以近期微台全1/2 13:20有進場為例

應該會在15:15結束

15:20出場才對

但是一直等到16:30才出場(看起來是condition21啟動)

無論我怎麼修改就是好像無法進入BP = 7(condition25無法啟動)

因為這幾天才寫好,我看列印BP都是0

 

麻煩各位大神幫忙修改或回答,謝謝

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/01/12

//空單回補並翻多
if position <= -1 and filled <= -1 then
    if condition24 or c > l + 100 then
        begin
            setposition(1,market);
            BP = 7;
        end;
//空單翻多的停利
if position >= 1 and filled >= 1 and BP = 7 then
    if condition25 then
        begin
            setposition(0,market);
            BP=0;
        end;

XQ小菜鳥 發文於   2025/01/14

感謝許教授

看來犯了跟上次一樣的錯誤

謝謝

發表回覆
Close