2010年3月17日 星期三

限制當日虧損

vars: dayLoss(50);

vars: mc(0), entryCount(1);
if date <> date[1] then begin
 dayLoss = 50;
 entryCount = 1;
end if
mc = marketposition * currentcontracts;
if mc[1] = 1 and mc = 0 then dayLoss = dayLoss + exitprice(0) - entryprice(0)
if mc[1] = -1 and mc = 0 then dayLoss = dayLoss + entryprice(0) - exitprice(0)
if mc[1] = -1 and mc = 1 then dayLoss = dayLoss + entryprice(1) - entryprice(0)
if mc[1] = 1 and mc = -1 then dayLoss = dayLoss + entryprice(0) - entryprice(1)

if dayLoss <= 0 then entryCount = 0;
if marketposition > 0 then exitlong next bar at entryprice(0) - dayLoss stop;
if marketposition < 0 then exitshort next bar at entryprice(0) + dayLoss stop;
 
大概如上…利用進場的價位和出場的價位把目前可以損失的點數 (dayLoss) 計算出來。也就是說如果第一筆單是獲利 20 點的話…那 dayLoss 就會變成 70 點。也就是接下來的單子可以虧損 70 點。

可以看到我在 dayLoss <= 0 的時候把一個變數 entryFlag 設定為 0,這個變數是需要加在進場的時候順便檢查是否為 1 的,才可以達到 dayLoss <= 0 的時候不再進場。

++++++++++++++++++++++++++++++
vars: count(0);

vars: mc(0), gp(0);

mc = marketposition * currentcontracts;
gp = netprofit;
if date <> date[1] then count = 0;
if count = 0 and time > 900.00 and time < 1300.00 then begin
 if (marketposition = 0 or close < entryprice(0)) and average(close, 10) cross over average(close, 20) then begin
  buy ("b1") next bar at market;
 end;
 if (marketposition = 0 or close > entryprice(0)) and average(close, 10) cross under average(close, 20) then begin
  sell ("s1") next bar at market;
 end;
end;
if marketposition < 0 and average(close, 10) cross over average(close, 20) then begin
 exitshort ("exs1") next bar at market;
 count = 1;
end;

if marketposition > 0 and average(close, 10) cross under average(close, 20) then begin
 exitlong ("exb1") next bar at market;
 count = 1;
end;

if time = 1330.00 and marketposition <> 0 then begin
 exitlong next bar at market;
 exitshort next bar at market;
end;

if mc <> mc[1] and gp < gp[1] then count = 1;
setstoploss(8000);

二個變數…一個為 mc 一個為 gp
這兩個變數分別儲存了倉位的改變和 netprofit 的改變…透過這樣的方式來檢查
上一次的進出場是否為獲利…如果為虧損的話…就直接把進場的 count 限制掉…就可以達到限制進場次數了。

沒有留言: