公式修改 [金字塔]
- 咨询内容:
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 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
//建立多头离场条件
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
//建立空头离场条件
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
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;
您好老师,这个公式帮我把加仓程序去掉好吗?我不需要加仓我只需要固定手数交易就行啦 - 金字塔客服:
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 ;
ENDGOTO 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 ;
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容