input: lot(5), num(3);??//lot是手?jǐn)?shù),num是平倉(cāng)反向的次數(shù)
var: mp(0), flag(num);
mp=marketposition;
if mp[1]*mp=-1 then
? ? ? ? flag=flag-1
else if mp[1]=0 and mp<>0 then
? ? ? ? flag=num;
{這段是平倉(cāng)反向的次數(shù)統(tǒng)計(jì);平倉(cāng)反向一次,flag就減少一次;從持倉(cāng)為0到開倉(cāng)之后,flag的值重新賦值為平倉(cāng)反向的次數(shù)num}
if marketposition=0 and condition1 then??
? ? ? ? buy lot shares next bar at market;
if marketposition=0 and condition2 then
? ? ? ? sellshort lot shares next bar at market;
if marketposition=-1 and condition1 and flag>0 then
? ? ? ? buy lot shares next bar at market;
if marketposition=1 and condition2 and flag>0 then
? ? ? ? sellshort lot shares next bar at market;
if marketposition=1 and condition3 and flag=0 then
? ? ? ? sell next bar at market;
if marketposition=-1 and condition4 and flag=0 then
? ? ? ? buytocover next bar at market;
{condition1是買入進(jìn)場(chǎng)的條件;condition2是賣出進(jìn)場(chǎng)的條件;condition3和condition4都是出場(chǎng)條件}
注意:從代碼的效率來說,這樣并不高;您可以使用if else將整個(gè)代碼優(yōu)化一下。
?
input: lot(5), num(3);??//lot是手?jǐn)?shù),num是平倉(cāng)反向的次數(shù)
var: mp(0), flag(num);
mp=marketposition;
if mp[1]*mp=-1 then
? ? ? ? flag=flag-1
else if mp[1]=0 and mp<>0 then
? ? ? ? flag=num;
{這段是平倉(cāng)反向的次數(shù)統(tǒng)計(jì);平倉(cāng)反向一次,flag就減少一次;從持倉(cāng)為0到開倉(cāng)之后,flag的值重新賦值為平倉(cāng)反向的次數(shù)num}
if marketposition=0 and condition1 then??
? ? ? ? buy lot shares next bar at market;
if marketposition=0 and condition2 then
? ? ? ? sellshort lot shares next bar at market;
if marketposition=-1 and condition1 and flag>0 then
? ? ? ? buy lot shares next bar at market;
if marketposition=1 and condition2 and flag>0 then
? ? ? ? sellshort lot shares next bar at market;
if marketposition=1 and condition3 and flag=0 then
? ? ? ? sell next bar at market;
if marketposition=-1 and condition4 and flag=0 then
? ? ? ? buytocover next bar at market;
{condition1是買入進(jìn)場(chǎng)的條件;condition2是賣出進(jìn)場(chǎng)的條件;condition3和condition4都是出場(chǎng)條件}
注意:從代碼的效率來說,這樣并不高;您可以使用if else將整個(gè)代碼優(yōu)化一下。
?
?
input: sf(5);
var: mp(0), flag_b(1), flag_s(1);
{原理還是一樣的,都是通過變量來控制條件和相關(guān)的邏輯;這里flag_b為1時(shí),可以買入進(jìn)場(chǎng),0時(shí)不允許;flag_s為1時(shí),可以賣出進(jìn)場(chǎng),0時(shí)不允許}
mp=marketposition;
if flag_b=1 and condition1 then begin
? ? ? ? buy next bar at market;
? ? ? ? flag_s=1;
end;
{當(dāng)買入進(jìn)場(chǎng)之后,將flag_s賦值為1,也就是多頭進(jìn)場(chǎng)之后,空頭可以允許進(jìn)場(chǎng)}
if flag_s=1 and condition2 then begin
? ? ? ? sellshort next bar at market;
? ? ? ? flag_b=1;
end;
{空頭進(jìn)場(chǎng)之后,允許多頭進(jìn)場(chǎng)}
setstoploss(bigpointvalue*minmove*sf point);
setprofittarget(bigpointvalue*minmove*sf point);
{使用set系列關(guān)鍵字進(jìn)行實(shí)時(shí)止損止盈}
if mp[1]=1 and mp=0 and positionprofit(1)<0 then
? ? ? ? flag_b=0
else if mp[1]=-1 and mp=0 and positionprofit(1)<0 then
? ? ? ? flag_s=0;
{當(dāng)多頭止損時(shí),將flag_b賦值為0,表示不允許多頭進(jìn)場(chǎng),唯一將flag_b賦值為1的時(shí)刻是空頭進(jìn)場(chǎng)之后;同理對(duì)于,空頭止損,邏輯也是一樣的}
?
input: sf(5);
var: mp(0), flag_b(1), flag_s(1);
{原理還是一樣的,都是通過變量來控制條件和相關(guān)的邏輯;這里flag_b為1時(shí),可以買入進(jìn)場(chǎng),0時(shí)不允許;flag_s為1時(shí),可以賣出進(jìn)場(chǎng),0時(shí)不允許}
mp=marketposition;
if flag_b=1 and condition1 then begin
? ? ? ? buy next bar at market;
? ? ? ? flag_s=1;
end;
{當(dāng)買入進(jìn)場(chǎng)之后,將flag_s賦值為1,也就是多頭進(jìn)場(chǎng)之后,空頭可以允許進(jìn)場(chǎng)}
if flag_s=1 and condition2 then begin
? ? ? ? sellshort next bar at market;
? ? ? ? flag_b=1;
end;
{空頭進(jìn)場(chǎng)之后,允許多頭進(jìn)場(chǎng)}
setstoploss(bigpointvalue*minmove*sf point);
setprofittarget(bigpointvalue*minmove*sf point);
{使用set系列關(guān)鍵字進(jìn)行實(shí)時(shí)止損止盈}
if mp[1]=1 and mp=0 and positionprofit(1)<0 then
? ? ? ? flag_b=0
else if mp[1]=-1 and mp=0 and positionprofit(1)<0 then
? ? ? ? flag_s=0;
{當(dāng)多頭止損時(shí),將flag_b賦值為0,表示不允許多頭進(jìn)場(chǎng),唯一將flag_b賦值為1的時(shí)刻是空頭進(jìn)場(chǎng)之后;同理對(duì)于,空頭止損,邏輯也是一樣的}