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周期的低點
//準備需要計算的變量
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 and holding=0 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 and holding=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
//如果當前持有多頭倉位的狀態
//建立多頭離場條件
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 ;
//如果當前持有空頭倉位的狀態
//建立空頭離場條件
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
//IF
//顯示賬戶狀態
CONTINUELINE@ 資產:ASSET,LINETHICK0;
可用現金:CASH(0),LINETHICK0;
POS:HOLDING,LINETHICK0;
交易次數:TOTALDAYTRADE, LINETHICK0 ;
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周期的低點
//準備需要計算的變量
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 and holding=0 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 and holding=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
//如果當前持有多頭倉位的狀態
//建立多頭離場條件
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
//如果當前持有空頭倉位的狀態
//建立空頭離場條件
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
//IF
//顯示賬戶狀態
資產:ASSET,LINETHICK0;
可用現金:CASH(0),LINETHICK0;
POS:HOLDING,LINETHICK0;
交易次數:TOTALDAYTRADE, LINETHICK0 ;