{海龟法则1交易系统}
{定义变量,即ATR Ratchet 跟踪停损价格}
variable: xstop=0;
{计算ATR}
tr:=max(high-low,max(abs(high-ref(close,1)),abs(low-ref(close,1))));
atr:=sma(tr,20,1);
{计算Turtle rule-1 跟踪停损价格}
if high>=hhv(high,20) then
xstop:=llv(low,10); {20日新高,建立多头停损价格起点——最近10日低点}
else if low>xstop then
xstop:=xstop+0.05*atr; {多头延续,每天跟踪停损价格上移ATR的5%}
else if low<=llv(low,20) then
xstop:=hhv(high,10);{20日新低,建立空头停损价格起点——最近10日高点}
else if high<xstop then
xstop:=xstop - 0.05*atr;{空头延续,每天跟踪停损价格下移ATR的5%}
StopPrice: xstop;{显示停损价格}
{海龟法则1交易系统}
{定义变量,即ATR Ratchet 跟踪停损价格}
variable: xstop=0;
{计算ATR}
tr1:=max(high-low,max(abs(high-ref(close,1)),abs(low-ref(close,1))));
atr:=sma(tr1,20,1);
{计算Turtle rule-1 跟踪停损价格}
tmp1:=llv(low,10);
tmp2:=llv(low,20);
tmp3:=hhv(high,10);
if high>=hhv(high,20) then
xstop:=tmp1; {20日新高,建立多头停损价格起点——最近10日低点}
else if low>xstop then
xstop:=xstop+0.05*atr; {多头延续,每天跟踪停损价格上移ATR的5%}
else if low<=tmp2 then
xstop:=tmp3;{20日新低,建立空头停损价格起点——最近10日高点}
else if high<xstop then
xstop:=xstop - 0.05*atr;{空头延续,每天跟踪停损价格下移ATR的5%}
StopPrice: xstop;{显示停损价格}