我本來是使用這樣的語法 , 但明明 hold_days 算出來都是大於一個 甚至還有大於2 可每次從開後都只能抓到今天的最高
之前的發問教授說 應該是因為抓到的 hold_days 都是 = 1 , 但我print出不是這樣 ,實在很好其 明明就大於1 卻都抓不到
我附上print圖片

hold_days = DateDiff( CurrentDate,FilledEntryDate ) + 1 ; HIGHDD = highest(high,hold_days) ; //進場後的高
我之前是用這樣的寫法 可以做到重開記錄到高點 但這樣太低效了
hold_days = DateDiff( CurrentDate,FilledRecordDate(1) ) + 1 ;
if hold_days = 2 and highD(1) > filledavgPrice then begin
if highx < highD(1) then highx = highD(1) ;
end;
if hold_days = 3 then begin
Array: arrA[2](0);
arrA[1] = highD(1); arrA[2] = highD(2);
value10 = HighestArray(arrA,2);
if value10 > filledavgPrice and highx < value10 then highx = value10 ;
end;
if hold_days = 4 then begin
Array: arrB[3](0);
arrB[1] = highD(1); arrB[2] = highD(2); arrB[3] = highD(3);
value11 = HighestArray(arrB,3);
if value11 > filledavgPrice and highx < value11 then highx = value11 ;
end;
實在很納悶 hold_days 就不等於一 也不等於0 HIGHDD = highest(high,hold_days) 的寫法卻都抓不到 , 那如果print出的是假資料 但我用 hold_days 推算的其他參數 又是正常
例如我有用持有天數上移停損點 是有效的
if hold_days >= 1 then newstop1 = (-14)+(hold_days*1) ; //一天上移1%
以上 ,謝謝好心人
補充全部程式碼
inputs : pos1(18,"下單金額(萬)") ;
input:stoploss_en(1,"尾盤清股票降低風險",inputkind:=dict(["Yes",1],["No",0]));
var: intrabarpersist opposition (true); //開關
if stoploss_en=1 then opposition = true; //開
if stoploss_en=0 then opposition = false; //不開
//是否開單
input:op_not(1,"是否開單",inputkind:=dict(["Yes",1],["No",0]));
var: intrabarpersist op_x (true); //是否開單
if op_not=1 then op_x = true; //開單
if op_not=0 then op_x = false; //不開單
value1 = highest(close,60)[1]; //60天高
value2 = lowest(low,30)[1]; //30天低點
var : order_pos(0) , hold_days(0),HIGHDD(0),Profit(0),newstop1(0),newstop2(0),
newstop3(0);
condition1 = close > value1 ; //突破60天高
condition2 = close < value2 ; //跌破30天低
condition3 = close >= close[1]*1.09;
condition4 = currentTime >= 132000 ;
if filled = 0 and condition1 and not condition4 and op_x then begin
order_pos = IntPortion((pos1 * 10000) / (close * 1000));
if order_pos > 0 then
setposition(order_pos, label:="進場");
end;
// 停損邏輯
if filled >0 and close < filledavgPrice then begin
//第1層 躲跌停 & 12%停損
if close < (close[1]*0.91) then setposition(0, label:="-9%有跌停風險")
else if close < (filledavgPrice*0.88) then setposition(0, label:="停損") ;
end;
//第2層 停損上移
if filled >0 then begin
hold_days = DateDiff( CurrentDate,FilledEntryDate ) + 1 ;
if hold_days >= 1 then newstop1 = (-14)+(hold_days*1) ; //一天上移1%
HIGHDD = highest(high,hold_days) ; //進場後的高
Profit = HIGHDD / filledavgPrice ; //獲利百分比
newstop2 = (-12)+((Profit-1)*100)/3 ;
//決定最終價
if newstop1 = 0 then newstop1 = (-12) ;
newstop3 = MaxList(newstop1, newstop2);
//停損邏輯開始
if newstop3 > (-12) then begin
if newstop3 >= 2 then newstop3 = 2 ;
if close < filledavgPrice*(1+(newstop3*0.01)) then
setposition(0, label:="移動停損") ;
end;
end;
if filled > 0 and close >filledavgPrice then begin
if condition2 then setposition(0, label:="停利") ;
end;
//避免系統性風險
if opposition then begin
if not condition3 and close < filledavgPrice*1.1 and condition4
then setposition(0, label:="避風險") ;
end;
print("HIGHDD",HIGHDD,"hold_days",hold_days,"newstop1",newstop1,"newstop2",newstop2,"newstop3",newstop3,"currentTime",currentTime);

12 評論