//《定制的海龟交易系统V1.0前台显示版本》
// 适用于多时间框架图表
// 这个版本可以用于在图表上显示信号,也可以做自动交易
// 同一根K线多次发出指令。
// Designed By Likai
// 2010.07.16
//声明参数
Input : T20(20,15,60,1) ;
Input : T10(10,10,30,1);
Input : ATRLen(20,15,30,1) ;
Input : PosNum(1,1,20,1) ;
//声明变量
nt := 1 ; //调试信息带时间戳
BuyOrderThisBar := 0 ; //当前Bar有过交易
VARIABLE : _DEBUG = 1 ; //是否输出前台交易指令
VARIABLE : _TDEBUG = 1 ; //是否输出后台交易指令
VARIABLE : _DEBUGOUT = 0 ; //是否输出后台交易的调试信息
VARIABLE : myEntryPrice =0 ; //开仓价格
VARIABLE : myExitPrice =0 ; //平仓价格
VARIABLE : TurtleUnits=0 ; //交易单位
VARIABLE : Position=0 ; //仓位状态
//0表示没有仓位,1表示持有多头, -1表示持有空头
VARIABLE : T20Hi=Close ; //20周期的高点
VARIABLE : T20Lo=Close ; //20周期的低点
VARIABLE : T10Hi=Close ; //10周期的高点
VARIABLE : T10Lo=Close ; //10周期的低点
//准备需要计算的变量
t30hi:=ref(hhv(h,30));
t30li:=ref(llv(l,30));
T20Hi := ref(hhv(h,T20),1) ;
T20Lo := ref(llv(l,T20),1) ;
T10Hi := ref(hhv(h,T10),1) ;
T10Lo := ref(llv(l,T10),1) ;
AvgTR := ref(MA(TR,ATRLen),1) ;
//开始执行时 初始化数据
If BARPOS=1 Then Begin
//Position := 0 ;
End //If
//如果当前是没有持仓的状态
If Position=0 and BARPOS>T20 and h>l Then Begin
//建立多头进场条件
Long := h > T20Hi ;
//多头进场
if Long then begin
myEntryPrice := IF(Open>T20Hi+MINDIFF ,Open ,T20Hi+MINDIFF ) ;
buy( _DEBUG,PosNum,limitr,myEntryPrice);
Position := 1 ;
TurtleUnits := 1 ;
N := AvgTR ;
BuyOrderThisBar := 1;
end //if
//建立空头进场条件
Short := l < T20Lo ;
//空头进场
if Short and Position=0 then begin
myEntryPrice := IF(Open<T20Lo-MINDIFF ,Open ,T20Lo-MINDIFF ) ;
buyshort( _DEBUG,PosNum,limitr,myEntryPrice);
Position := -1 ;
TurtleUnits := 1 ;
N := AvgTR ;
BuyOrderThisBar := 1;
end
//不要跳转,让程序检查同一根K线是否可以加仓
//Goto ContinueLine ;
End //If
//如果当前持有多头仓位的状态、、、、、、、、、、、、、第一资加仓
If Position=1 and BARPOS>T20 and h>l Then Begin
//多头加仓条件
While (High>myEntryPrice+0.5*N) and TurtleUnits<4 Do Begin
myEntryPrice := IF(Open>myEntryPrice+0.5*N ,Open ,myEntryPrice+0.5*N ) ;
myEntryPrice := Ceiling(myEntryPrice/MINDIFF)*MINDIFF ;
buy( _DEBUG, PosNum, limitr, myEntryPrice);
TurtleUnits := TurtleUnits+1 ;
BuyOrderThisBar := 1;
End //While
While (High>//如果当前持有多头仓位的状态、、、、、、、、、、、、、第二次加仓
If Position=1 and BARPOS>T20 and h>l Then Begin
//多头加仓条件
While (High>t30hi) and TurtleUnits<4 Do Begin
myEntryPrice := IF(High>t30hi ,Open ,myEntryPrice+0.5*N ) ;
myEntryPrice := Ceiling(myEntryPrice/MINDIFF)*MINDIFF ;
buy( _DEBUG, PosNum, limitr, myEntryPrice);
TurtleUnits := TurtleUnits+1 ;
BuyOrderThisBar := 1;
End //While
//建立多头离场条件
LongX1 := (low < T10Lo) ;
if LongX1 and BuyOrderThisBar=0 then begin
myExitPrice := IF(Open<T10Lo-MINDIFF ,Open ,T10Lo-MINDIFF ) ;
sell( _DEBUG ,0,limitr,myExitPrice);
Position := 0 ;
TurtleUnits := 0 ;
end
//建立多头止损条件
LongX2 := (Low<myEntryPrice-2*N) ;
if LongX2 and Position=1 and BuyOrderThisBar=0 then begin
myExitPrice := IF(Open<myEntryPrice-2*N ,Open ,myEntryPrice-2*N ) ;
myExitPrice := Floor(myExitPrice/MINDIFF)*MINDIFF ;
sell( _DEBUG ,0,limitr,myExitPrice);
Position := 0 ;
TurtleUnits := 0 ;
end
Goto ContinueLine ;
End //If
//如果当前持有空头仓位的状态
If Position = -1 and BARPOS>T20 and h>l Then Begin
//空头加仓条件
While (Low<myEntryPrice-0.5*N) and TurtleUnits<4 Do Begin
myEntryPrice := IF(Open<myEntryPrice-0.5*N ,Open ,myEntryPrice-0.5*N ) ;
myEntryPrice := Floor(myEntryPrice/MINDIFF)*MINDIFF ;
buyshort( _DEBUG,PosNum, limitr, myEntryPrice);
TurtleUnits := TurtleUnits+1 ;
BuyOrderThisBar := 1;
End //If
//如果当前持有空头仓位的状态
If Position = -1 and BARPOS>T20 and h>l Then Begin
//空头加仓条件
While (Low<t30li) and TurtleUnits<4 Do Begin
myEntryPrice := IF(l<t30li ,Open ,myEntryPrice-0.5*N ) ;
myEntryPrice := Floor(myEntryPrice/MINDIFF)*MINDIFF ;
buyshort( _DEBUG,PosNum, limitr, myEntryPrice);
TurtleUnits := TurtleUnits+1 ;
BuyOrderThisBar := 1;
End //If
//建立空头离场条件
ShortX1 := h > T10Hi ;
if ShortX1 and BuyOrderThisBar=0 then begin
myExitPrice := IF(Open>T10Hi+MINDIFF ,Open ,T10Hi+MINDIFF ) ;
sellshort( _DEBUG,0,limitr,myExitPrice);
Position := 0 ;
TurtleUnits := 0 ;
end
//建立空头止损条件
ShortX2 := High > myEntryPrice + 2*N ;
if ShortX2 and Position = -1 and BuyOrderThisBar=0 then begin
myExitPrice := IF(Open>myEntryPrice+2*N ,Open ,myEntryPrice+2*N ) ;
myExitPrice := Ceiling(myExitPrice/MINDIFF)*MINDIFF ;
sellshort( _DEBUG,0,limitr,myExitPrice);
Position := 0 ;
TurtleUnits := 0 ;
end
End //If
//显示账户状态
ContinueLine@ 资产:ASSET,LINETHICK0;
可用现金:CASH(0),LINETHICK0;
Pos:HOLDING,LINETHICK0;
交易次数:TOTALDAYTRADE, LINETHICK0 ;
If _DEBUGOUT>0 Then Begin
DEBUGFILE2('c:\debugfile.txt','BarPos=%.0f' ,BARPOS,nt ) ;
DEBUGFILE2('c:\debugfile.txt','T20Hi=%.2f' ,T20Hi ,nt) ;
DEBUGFILE2('c:\debugfile.txt','N=%.2f' ,N ,nt) ;
DEBUGFILE2('c:\debugfile.txt','Close=%.2f' ,C ,nt) ;
DEBUGFILE2('c:\debugfile.txt','Position=%.0f' ,Position,nt ) ;
DEBUGFILE2('c:\debugfile.txt','TurtleUnits=%.0f' ,TurtleUnits,nt ) ;
DEBUGFILE2('c:\debugfile.txt','myEntryPrice=%.0f' ,myEntryPrice ,nt) ;
DEBUGFILE2('c:\debugfile.txt','myExitPrice=%.0f' ,myExitPrice ,nt) ;
End //If
求助:加入红色的关键代码后为什么不能编译
请老师帮忙修改一下,谢谢
老师在吗?请教
我的想法是用While ~~~~~~~~~~~~ Do Begin 再加一将次仓
如可实现
看起来有点乱
最好把加仓的条件用语言再描述一下
《定制的海龟交易系统V1.0前台显示版本》是内置的;
我只是想在原来的基础上在用一次循环加仓{要求是用用While ~~~~~~~~~~~~ Do Begin }{加仓条件是最高价大于30天最高价}这一种加仓方式
老师帮忙写一下 谢谢
上面的代码加载 提示 少了 END 不知道加在什么地方
把上面红色代码删了就正常,多加两个加仓的While就不行
是在While~~~DO BEGIN 这条语句后面的END加分号吗?