我寫了一個交易腳本,主要想實現的邏輯是, 在突破3%進場 ,並且每漲1%就加碼一次, 總共加碼兩次
不管持有的部位多少,只要虧損超過1000就停損, 並且在停損時 IntraBarPersist 變數 +1 ,
下單時 IntraBarPersist 變數 不小於1的話就不能下單(這邊用意是一天虧一次就不下單等明天),
但我發現print的資料 該個股的print資料 IntraBarPersist 變數會增加 ,但腳本盯的其他商品IntraBarPersist 變數不會增加
這裡我就很納悶,IntraBarPersist 變數 不是屬於我的交易腳本的嗎? 怎麼print資料看起來他是每個商品各有一個IntraBarPersist 變數 , 目前爬文都沒有相關答案 , 只好上來發問 謝謝各位的幫忙 , 以下附上程式碼以及print截圖
各位可以先看重點段落就好 我下面再放完整的 謝謝!
//停損 if position > 0 and filled > 0 then begin value1 = ((filledavgPrice*filled)-stop_price)/filled ; if close < value1 then begin setposition(0); //執行停損 sstop = xxstop+1 ; //計算停損次數 xxstop = sstop ; end; end;
完整程式碼
//參數
input : order_price(5 , "下單金額(萬)"),
stop_price(1 , "停損金額(千)"),
add_price(1.01 , "加碼百分比"),
over_percent(5 , "漲幅停利條件%"),
end_percent(0.95 , "回落停利%") ,
V_avg(100,"成交均參數"),
V_multiple(3,"成交量放大倍數"),
StopTime(133000,"更新時間");
//變數宣告
vars :IntraBarPersist high_price(0) , //進場後高
IntraBarPersist sstop(0), //停損次數
IntraBarPersist xxstop(0),
yesterday(0),
V_avg_100(0),
order_size(0),
max_pos(0),
midd_pos(0);
//抓資料
yesterday = GetField("收盤價", "D")[1] ;
V_avg_100 = average(volume ,V_avg);
max_pos = order_price*5*10000 ; //這裡代表壓滿的部位市值
midd_pos = order_price*3*10000 ;//第一次加碼部位
// 進場
if position = 0 and filled = 0 and sstop < 1 then begin
if close cross Over yesterday*1.03 and volume >= V_avg_100* V_multiple then begin
//計算開倉部位
order_size = IntPortion ((order_price*10000) / (close*1000));
if order_size > 0 then setposition(order_size, label:= "進場");
end;
end;
//停損
if position > 0 and filled > 0 then begin
value1 = ((filledavgPrice*filled)-stop_price)/filled ;
if close < value1 then begin
setposition(0); //執行停損
sstop = xxstop+1 ; //計算停損次數
xxstop = sstop ;
end;
end;
//加碼第一次
if position > 0 and filled > 0 and filledavgPrice*position*1000 < midd_pos then begin
//計算開倉部位
Value2 = IntPortion ((midd_pos) / (close*1000));
if close >= filledavgPrice*add_price then setposition(Value2, label:="加碼第一次");
end;
//加碼第二次
if position > 0 and filled > 0 and filledavgPrice*position*1000 > 100000 and filledavgPrice*filled*1000 < max_pos then begin
value3 = intPortion ((max_pos) / (close*1000)) ;
if close >= filledavgPrice*add_price then setposition(value3, label:="加碼第二次");
end;
//紀錄高點價
if position >=3 and filled >= 3 and high > high_price then high_price = high ;
//停利
if position >=3 and filled >= 3 and high_price >= filledavgPrice*(1+(over_percent*0.1)) then begin
if close < high_price* end_percent then setposition(0);
high_price = 0 ;
end ;
if time = StopTime then begin
sstop = 0 ;
xxstop = 0;
end;
value6 =getfield("Time");
print("停損價",value1, "進場後高",high_price, "停損次數" ,sstop, "現在時間" , value6 );
2 評論