這篇整理一下常會用到的Powerlanduage 語法範例以及常常被客戶問到的寫法,若有錯誤請指正
===========================================
限制當天交易次數
if EntriesToday(date)<1 then begin 限制當天的進場次數1次
===========================================
記錄當天多單空單虧損的次數
if date <> date[1] then begin
OI = 0 ;
B_loss ;
S_loss ;
end;
OI = marketposition * currentcontracts ; 未平倉口數
if OI =0 and OI[1] >=1 then B_net = netprofit ;
if OI =0 and OI[1] <=-1 then S_net = netprofit ;
if B_net < B_net[1] then B_loss= 1 ; 當多單淨獲利前一筆的獲利少,也就是多單虧損
if S_net < S_net[1] then S_loss= 1 ; 當空單淨獲利比前一筆獲利少,也就是空單虧損
if B_loss = 0 then begin ....
if S_loss = 0 then begin ....
vars:xO(0),xH(0),xL(0),xC(0);
if time=CalcTime(sess1starttime,barinterval*N) then begin 開盤後第N根K棒的開盤價
xO=open;
condition1= dayofweek(date)=3 and dayofmonth(date)>14 and dayofmonth(date)<22; 結算日在每個月第三個星期三,落在每月14號和22號之間
if marketposition<>0 and condition1 and time>1300 then begin 超過13:00之後平倉
Sell all contracts this bar on close;
Buytocover all contracts this bar on close;
end;
=============================================
當沖程式當天收盤前平倉
if marketposition<>0 and time>1330 then begin 過了13:30 之後把多單空單都平倉
sell this bar on close;
buytocover this bar on close;
end;
setexitonclose; 別忘了加上這一句
==============================================
最大量K棒高低點
Input: Length(180) ;
Vars: step(0), BigvolHigh(0), BigvolLow(0);
For step=0 to Length -1 begin
if ticks[step]=Highest(ticks, Length) then begin 當成交量是N根K棒最大量開始執行
BigvolHigh = L[step]; 記錄該K棒最高價
BigvolLow = H[step]; 記錄該K棒最低價
end;
end;
plot1(BigvolHigh,"BigvolHigh");
plot2(BigvolLow,"BigvolLow");
===============================================
找出RSI的區間的最高收盤價
Vars:Length(5),count(0);
Value1=RSI(C,9);
for count=0 to Length-1 begin
if Value1[count] >= Highest(Value1,Length) then
Value2=Close[count];
end;
===============================================
紀錄當天開盤一段時間之後最高最低點
vars:mm(0900);
if time = mm then begin
value1 = highD(0);
value2 = lowD(0);
end;
plot1(value1);
plot2(value2);
===============================================
突破一段區間的最高點買進 跌破一段區間的最低點賣出
buy next bar at highest(high,XX) stop; 必須要用next bar
sellshort next bar at lowest(low,YY) stop;
===============================================
停損的寫法
setstoploss(停損金額)
if marketposition = 1 then sell next bar at entryprice - 點數 stop;
if marketposition=-1 then buytocover next bar at entryprice+點數 stop;
===============================================
百分比移動停利
value1 = maxpositionprofit / bigpointvalue; 記錄獲利點數
if marketposition =1 and value1>xPFT then sell next bar at avgentryprice+value1-value1*xPCT/100 stop; 持有多單 當獲利折返一定百分比多單出場
if marketposition =-1 and value1>xPFT then buytocover next bar at avgentryprice-value1+value1*xPCT/100 stop; 持有空單當獲利折返一定百分比出場
表示 最後一筆進場價 就是 PosTradeEntryPrice(0,currentcontracts-1)
if MP=2 then sell next bar at PosTradeEntryPrice(0,currentcontracts-1) - 20 stop 應該就是記錄到最後一筆進場價
有想到其他常用的語法,之後再慢慢補充記錄
歡迎留言討論。 或是追蹤我的 FB粉絲頁 https://www.facebook.com/upup12341234
留言列表