INPUT : T20(20,15,60,1) ; //??3?μ??ü?ú
INPUT : T10(10,10,30,1); //3?3?μ??ü?ú
INPUT : ATRLEN(20,15,30,1) ;
INPUT : POSNUM(2,1,20,1) ; //??′???ò×μ?ê?êy
//éù?÷±?á?
BUYORDERTHISBAR := 0 ; //μ±?°BARóD1y??ò×
VARIABLE : _DEBUG = 1 ; //ê?·?ê?3??°ì¨??ò×??á?
VARIABLE : _TDEBUG = 1 ; //ê?·?ê?3?oóì¨??ò×??á?
VARIABLE : _DEBUGOUT = 1 ; //ê?·?ê?3?oóì¨??ò×μ?μ÷ê?D??¢
VARIABLE : MYENTRYPRICE =0 ; //?a2?????
VARIABLE : MYEXITPRICE =0 ; //??2?????
VARIABLE : TURTLEUNITS=0 ; //??ò×μ¥??
VARIABLE : POSITION=0 ; //2???×′ì?
//0±íê???óD2???£?1±íê?3?óD?àí·£? -1±íê?3?óD??í·
VARIABLE : T20HI=CLOSE ; //20?ü?úμ???μ?
VARIABLE : T20LO=CLOSE ; //20?ü?úμ?μíμ?
VARIABLE : T10HI=CLOSE ; //10?ü?úμ???μ?
VARIABLE : T10LO=CLOSE ; //10?ü?úμ?μíμ?
//×?±?Dèòa????μ?±?á?
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) ;
//2éó?è???±?á?±£′?×?oóò??ùK??μ?????×′ì?
STRENTRYBARPOS:=STRCAT(STKLABEL,\'ENTRYBARPOS\') ;
STREXITBARPOS:=STRCAT(STKLABEL,\'EXITBARPOS\') ;
STRPREENTRYPRICE:=STRCAT(STKLABEL,\'PREENTRYPRICE\') ;
STRTURTLEUNITS:=STRCAT(STKLABEL,\'TURTLEUNITS\') ;
STRPOSITION:=STRCAT(STKLABEL,\'POSITION\') ;
STRPREN:=STRCAT(STKLABEL,\'PREN\') ;
IF NOT ( WORKMODE=1 ) THEN BEGIN
DRAWTEXTEX(1 ,0 ,0 ,0 ,\'ìáê?£o±?1?ê???ó?óúoóì¨??ò×£?\' ),COLORYELLOW ;
EXIT ;
END //IF
//?aê??′DDê± 3?ê??ˉêy?Y
//×¢òa£oμúò???êy?Yμ?BARPOS=1
IF BARPOS=1 THEN BEGIN
//POSITION := 0 ;
END //IF
//è?1?μ±?°°?ê?×?oóò??ùK??£??′DD
IF ISLASTBAR THEN BEGIN
// è?1?×?oóò??ùK??·¢éú1y3?3?D?o?£??ò??ò??ùK??2??ù??ò×
IF EXTGBDATA(STREXITBARPOS) = BARPOS THEN BEGIN
GOTO CONTINUELINE ;
END
//???′é?ò???????ê±±£′?μ?êy?Y
//è?1?????μ???3?BARPOSoíμ±?°μ??àμè£??μ?÷é?ò?????3?D?o?ò2ê?×?oóò??ùK??·¢3?μ??£
IF EXTGBDATA(STRENTRYBARPOS) = BARPOS THEN BEGIN
MYENTRYPRICE := EXTGBDATA(STRPREENTRYPRICE) ;
TURTLEUNITS := EXTGBDATA(STRTURTLEUNITS) ;
POSITION := EXTGBDATA(STRPOSITION) ;
N := EXTGBDATA(STRPREN) ;
END
//è?1?μ±?°ê???óD3?2?μ?×′ì?
IF POSITION=0 AND BARPOS>T20 AND H>L THEN BEGIN
//?¨á¢?àí·??3?ì??t
LONG := H > T20HI ;
//?àí·??3?·?o?
IF LONG THEN BEGIN
MYENTRYPRICE := IF(OPEN>T20HI+MINDIFF ,OPEN ,T20HI+MINDIFF ) ;
POSITION := 1 ;
TURTLEUNITS := 1 ;
N := AVGTR ;
TBUY( _TDEBUG,POSNUM,LMT,H),ALLOWREPEAT ;
EXTGBDATASET(STRENTRYBARPOS,BARPOS ) ;
EXTGBDATASET(STRPREENTRYPRICE,MYENTRYPRICE ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
EXTGBDATASET(STRPREN,N ) ;
END //IF?àí·??3?·?o?
//?¨á¢??í·??3?ì??t
SHORT := L < T20LO ;
//??í·??3?·?o?
IF SHORT AND POSITION=0 THEN BEGIN
MYENTRYPRICE := IF(OPEN<T20LO-MINDIFF ,OPEN ,T20LO-MINDIFF ) ;
POSITION := -1 ;
TURTLEUNITS := 1 ;
N := AVGTR ;
TBUYSHORT( _TDEBUG,POSNUM,LMT,L),ALLOWREPEAT;
EXTGBDATASET(STRENTRYBARPOS,BARPOS ) ;
EXTGBDATASET(STRPREENTRYPRICE,MYENTRYPRICE ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
EXTGBDATASET(STRPREN,N ) ;
END //IF??í·??3?·?o?
GOTO CONTINUELINE ;
END //IFè?1?μ±?°ê???óD3?2?μ?×′ì?
//è?1?μ±?°3?óD?àí·2???μ?×′ì?
IF POSITION=1 AND BARPOS>T20 AND H>L THEN BEGIN
//?àí·?ó2?ì??t
IF (HIGH>MYENTRYPRICE+0.5*N) AND TURTLEUNITS<4 THEN BEGIN
MYENTRYPRICE := IF(OPEN>MYENTRYPRICE+0.5*N ,OPEN ,MYENTRYPRICE+0.5*N ) ;
MYENTRYPRICE := CEILING(MYENTRYPRICE/MINDIFF)*MINDIFF ;
TURTLEUNITS := TURTLEUNITS+1 ;
TBUY( _TDEBUG,POSNUM,LMT,H),ALLOWREPEAT ;
EXTGBDATASET(STRENTRYBARPOS,BARPOS ) ;
EXTGBDATASET(STRPREENTRYPRICE,MYENTRYPRICE ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
END //IF?àí·?ó2?ì??t
//?¨á¢?àí·à?3?ì??t
LONGX1 := (LOW < T10LO) ;
IF LONGX1 AND EXTGBDATA(STRENTRYBARPOS)<>BARPOS AND EXTGBDATA(STREXITBARPOS)<>BARPOS THEN BEGIN
MYEXITPRICE := IF(OPEN<T10LO-MINDIFF ,OPEN ,T10LO-MINDIFF ) ;
POSITION := 0 ;
TURTLEUNITS := 0 ;
TSELL( _TDEBUG ,0,LMT,L),ALLOWREPEAT;
EXTGBDATASET(STREXITBARPOS,BARPOS ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
END
//?¨á¢?àí·?1?eì??t
LONGX2 := (LOW<MYENTRYPRICE-2*N) ;
IF LONGX2 AND POSITION=1 AND EXTGBDATA(STRENTRYBARPOS)<>BARPOS AND EXTGBDATA(STREXITBARPOS)<>BARPOS THEN BEGIN
MYEXITPRICE := IF(OPEN<MYENTRYPRICE-2*N ,OPEN ,MYENTRYPRICE-2*N ) ;
MYEXITPRICE := FLOOR(MYEXITPRICE/MINDIFF)*MINDIFF ;
POSITION := 0 ;
TURTLEUNITS := 0 ;
TSELL( _TDEBUG ,0,LMT,L),ALLOWREPEAT;
EXTGBDATASET(STREXITBARPOS,BARPOS ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
END
GOTO CONTINUELINE ;
END //IFè?1?μ±?°3?óD?àí·2???μ?×′ì?
//è?1?μ±?°3?óD??í·2???μ?×′ì?
IF POSITION = -1 AND BARPOS>T20 AND H>L THEN BEGIN
//??í·?ó2?ì??t
IF (LOW<MYENTRYPRICE-0.5*N) AND TURTLEUNITS<4 THEN BEGIN
MYENTRYPRICE := IF(OPEN<MYENTRYPRICE-0.5*N ,OPEN ,MYENTRYPRICE-0.5*N ) ;
MYENTRYPRICE := FLOOR(MYENTRYPRICE/MINDIFF)*MINDIFF ;
TURTLEUNITS := TURTLEUNITS+1 ;
TBUYSHORT( _TDEBUG,POSNUM,LMT,L),ALLOWREPEAT;
EXTGBDATASET(STRENTRYBARPOS,BARPOS ) ;
EXTGBDATASET(STRPREENTRYPRICE,MYENTRYPRICE ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
END //IF??í·?ó2?ì??t
//?¨á¢??í·à?3?ì??t
SHORTX1 := H > T10HI ;
IF SHORTX1 AND EXTGBDATA(STRENTRYBARPOS)<>BARPOS AND EXTGBDATA(STREXITBARPOS)<>BARPOS THEN BEGIN
MYEXITPRICE := IF(OPEN>T10HI+MINDIFF ,OPEN ,T10HI+MINDIFF ) ;
POSITION := 0 ;
TURTLEUNITS := 0 ;
TSELLSHORT( _TDEBUG,0,LMT,H),ALLOWREPEAT;
EXTGBDATASET(STREXITBARPOS,BARPOS ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
END
//?¨á¢??í·?1?eì??t
SHORTX2 := HIGH > MYENTRYPRICE + 2*N ;
IF SHORTX2 AND POSITION = -1 AND EXTGBDATA(STRENTRYBARPOS)<>BARPOS AND EXTGBDATA(STREXITBARPOS)<>BARPOS THEN BEGIN
MYEXITPRICE := IF(OPEN>MYENTRYPRICE+2*N ,OPEN ,MYENTRYPRICE+2*N ) ;
MYEXITPRICE := CEILING(MYEXITPRICE/MINDIFF)*MINDIFF ;
POSITION := 0 ;
TURTLEUNITS := 0 ;
TSELLSHORT( _TDEBUG,0,LMT,H),ALLOWREPEAT;
EXTGBDATASET(STREXITBARPOS,BARPOS ) ;
EXTGBDATASET(STRTURTLEUNITS,TURTLEUNITS ) ;
EXTGBDATASET(STRPOSITION,POSITION ) ;
END
GOTO CONTINUELINE ;
END //IFè?1?μ±?°3?óD??í·2???μ?×′ì?
//è?1?ò?é?3???éD?????óD3éᢣ??ò?±?ó?áê?±?′??D??
GOTO CONTINUELINE ;
END //IFè?1?μ±?°°?ê?×?oóò??ùK??
//2?ê?×?oóò??ùK??μ??éD?
//è?1?μ±?°ê???óD3?2?μ?×′ì?
IF POSITION=0 AND BARPOS>T20 AND H>L THEN BEGIN
//?¨á¢?àí·??3?ì??t
LONG := H > T20HI ;
//?àí·??3?
IF LONG THEN BEGIN
MYENTRYPRICE := IF(OPEN>T20HI+MINDIFF ,OPEN ,T20HI+MINDIFF ) ;
//BUY( _DEBUG,POSNUM,LIMITR,MYENTRYPRICE+MINDIFF);
POSITION := 1 ;
TURTLEUNITS := 1 ;
N := AVGTR ;
BUYORDERTHISBAR := 1;
END //IF
//?¨á¢??í·??3?ì??t
SHORT := L < T20LO ;
//??í·??3?
IF SHORT AND POSITION=0 THEN BEGIN
MYENTRYPRICE := IF(OPEN<T20LO-MINDIFF ,OPEN ,T20LO-MINDIFF ) ;
//BUYSHORT( _DEBUG,POSNUM,LIMITR,MYENTRYPRICE-MINDIFF);
POSITION := -1 ;
TURTLEUNITS := 1 ;
N := AVGTR ;
BUYORDERTHISBAR := 1;
END
//2?òaì?×a£?è?3ìDò?ì2éí?ò??ùK??ê?·??éò??ó2?
//GOTO CONTINUELINE ;
END //IF
//è?1?μ±?°3?óD?àí·2???μ?×′ì?
IF POSITION=1 AND BARPOS>T20 AND H>L THEN BEGIN
//?àí·?ó2?ì??t
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
//?¨á¢?àí·à?3?ì??t
LONGX1 := (LOW < T10LO) ;
IF LONGX1 AND BUYORDERTHISBAR=0 THEN BEGIN
MYEXITPRICE := IF(OPEN<T10LO-MINDIFF ,OPEN ,T10LO-MINDIFF ) ;
//SELL( _DEBUG ,0,LIMITR,MYEXITPRICE-MINDIFF);
POSITION := 0 ;
TURTLEUNITS := 0 ;
END
//?¨á¢?àí·?1?eì??t
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
//è?1?μ±?°3?óD??í·2???μ?×′ì?
IF POSITION = -1 AND BARPOS>T20 AND H>L THEN BEGIN
//??í·?ó2?ì??t
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
//?¨á¢??í·à?3?ì??t
SHORTX1 := H > T10HI ;
IF SHORTX1 AND BUYORDERTHISBAR=0 THEN BEGIN
MYEXITPRICE := IF(OPEN>T10HI+MINDIFF ,OPEN ,T10HI+MINDIFF ) ;
//SELLSHORT( _DEBUG,0,LIMITR,MYEXITPRICE+MINDIFF);
POSITION := 0 ;
TURTLEUNITS := 0 ;
END
//?¨á¢??í·?1?eì??t
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@ ×ê2ú:TASSET,LINETHICK0;
//?éó????e:CASH(0),LINETHICK0;
POS:THOLDING,LINETHICK0;
//??ò×′?êy:TOTALDAYTRADE, LINETHICK0 ;
//EP:MYENTRYPRICE ;
// DEBUGOUT(\'POSITION=%.0F\' ,POSITION ) ;
// DEBUGOUT(\'TURTLEUNITS=%.0F\' ,TURTLEUNITS ) ;
// DEBUGOUT(\'BARPOS=%.0F\' ,BARPOS ) ;
// DEBUGOUT(\'MYENTRYPRICE=%.0F\' ,MYENTRYPRICE ) ;
IF _DEBUGOUT>0 AND ISLASTBAR THEN BEGIN
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'BARPOS=%.0F\' ,BARPOS,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'T20HI=%.2F\' ,T20HI ,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'N=%.2F\' ,N ,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'AVGTR=%.2F\' ,AVGTR ,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'POSITION=%.0F\' ,POSITION,1 ) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'TURTLEUNITS=%.0F\' ,TURTLEUNITS,1 ) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'OPEN=%.2F\' ,O ,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'HIGH=%.2F\' ,H ,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'LOW=%.2F\' ,L ,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'CLOSE=%.2F\' ,C ,1) ;
DEBUGFILE2(\'C:\\DEBUGFILE.TXT\',\'MYENTRYPRICE=%.0F\' ,MYENTRYPRICE ,1) ;
END //IF