龙听期货论坛's Archiver

龙听 发表于 2022-7-7 17:27

程序化过程中连续亏损N笔,则当天停止交易【含程式码】

[code]
{.....................................................count start}
var: openEquity(0), closeEquity(0), closeProfit(0),mp(0);
var: wlCount(0),earnloss(0);

mp = marketposition;

//calc OpenEquity
openEquity = i_OpenEquity; //i_OpenEquity = netprofit(has been exit) + openpositionprofit(still has position)
closeEquity = i_ClosedEquity;
closeProfit = 0;

if mp <> mp[1]{this bar position changed!} and mp[1] <> 0{last bar have position} then {means new bar:1,no position or 2,opposite position} closeProfit = closeEquity - closeEquity[1]{covered earns};

if closeProfit <> 0 then begin {have earn or loss}
        if closeProfit > 0 then begin {have earn}
                if wlCount < 0 then wlCount = 0;{last is loss,reset time = 0}
                wlCount = wlCount + 1;{earn time +1 ,the first time earn}   
         end;

        if closeProfit < 0 then begin {have loss}
                if wlCount > 0 then wlCount = 0; {last trade is earn,the reset time = 0}
                wlCount = wlCount - 1; {record loss time -1}               
        end;
end;
earnloss = wlCount;

{.....................................................count end}
{check count start}
Input:N1(-3);
var:allow(False);
if earnloss < N1 then allow =False; //loss > 3 then stop trade
{check count end}

if allow = False and date<>date[1] then allow = True;{second day allow change to true}

if allow = True then begin
buy next bar at Highest(high,5) stop;
sellshort next bar at Lowest(low,5) stop;
end;

[/code]

页: [1]