//判断进场条件
//////////////////////
input:f1(10),f2(20),f3(30),stp(11);
var:av1(0),av2(0),av3(0),position(0),stH(0),Hct(0),stl(0),lct(0);
av1 = average(close, f1);
av2 = average(close, f2);
av3 = average(close, f3);
position = marketposition;
//定义常用的三条移动平均线
if position =1 and position[1] =0 then begin
stH = high;
Hct =0;
end;
//进场后对第一个bar高点赋值
if position =1 and close > stH then begin
stH = high;
Hct = Hct[1] +1;
end;
//后面对创新高时进行累加计算
if position =1 then begin
if Hct <3 then sell("begin stop") next bar at entryprice - stp stop;
if Hct >=3 and Hct <6 then sell("30stop") next bar at av3 stop;
if Hct >=6 and Hct <9 then sell("20stop") next bar at av2 stop;
if Hct >=9 then sell ("10stop") next bar at av1 stop;
end;
//当有持仓时,累加值作为激活某条均线的出场条件,有长期均线激活开始,这样可以防止进场后快速被洗出来。
position = marketposition;
是不是TB 里面的啊
marketposition 好像 相当于 holding
input:f1(10),f2(20),f3(30);
variable:hct=0;
av1: = ma(close, f1);
av2: = ma(close, f2);
av3: = ma(close, f3);
position: = holding;
//定义常用的三条移动平均线
if position =1 and ref(holding,1) =0 then begin
stH: = high;
Hct: =0;
end;
//进场后对第一个bar高点赋值
if position =1 and close > stH then begin
stH := high;
Hct: =hct +1;
end;
//后面对创新高时进行累加计算
if position =1 then begin
if Hct <3 then sell(1,0,limitr,close);
if Hct >=3 and Hct <6 then sell(1,0,limitr,close+30*mindiff) ;
if Hct >=6 and Hct <9 then sell(1,0,limitr,close+20*mindiff);
if Hct >=9 then sell(1,0,limitr,close+10*mindiff);
end;