金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 3068|回复: 4

求交易策略公式改编

[复制链接]

5

主题

11

帖子

11

积分

Rank: 1

等级: 新手上路

注册:
2021-7-30
曾用名:
发表于 2021-10-17 00:03 | 显示全部楼层 |阅读模式
以下是系统示范的顾比倒数策略公式,恳请技术老师帮忙插入止盈止损的程序片断,以开仓价为基准,波动1.5%设置止盈止损。谢谢!!

//定义参数
H11:=HIGH;
L11:=LOW;
A:=IFELSE(HIGH>=REF(HIGH,1)&&HIGH>=REF(HIGH,2)&&HIGH>=REF(HIGH,3) &&HIGH>=REF(HIGH,4)&&HIGH>=REF(HIGH,5),LOW,0);
B:=IFELSE(LOW<=REF(LOW,1)&&LOW<=REF(LOW,2)&&LOW<=REF(LOW,3) &&LOW<=REF(LOW,4)&&LOW<=REF(LOW,5),HIGH,888888);
P1:=IFELSE(A>REF(L11,1),REF(L11,1),0);
P2:=IFELSE(A>REF(L11,2)&&A<=REF(L11,1),REF(L,2),0);
P3:=IFELSE(A>REF(L11,3)&&A<=REF(L11,1)&&A<=REF(L11,2),REF(L11,3),0);
P4:=IFELSE(A>REF(L11,4)&&A<=REF(L11,1)&&A<=REF(L11,2)&&A<=REF(L11,3),REF(L11,4),0);
P5:=IFELSE(A>REF(L11,5)&&A<=REF(L11,1)&&A<=REF(L11,2)&&A<=REF(L11,3)&&A<=REF(L11,4),REF(L11,5),0);
P6:=IFELSE(A>REF(L11,6)&&A<=REF(L11,1)&&A<=REF(L11,2)&&A<=REF(L11,3)&&A<=REF(L11,4)&&A<=REF(L11,5),REF(L11,6),0);
P7:=IFELSE(A>REF(L11,7)&&A<=REF(L11,1)&&A<=REF(L11,2)&&A<=REF(L11,3)&&A<=REF(L11,4)&&A<=REF(L11,5)&&A<=REF(L11,6),REF(L11,7),0);
P8:=IFELSE(A>REF(L11,8)&&A<=REF(L11,1)&&A<=REF(L11,2)&&A<=REF(L11,3)&&A<=REF(L11,4)&&A<=REF(L11,5)&&A<=REF(L11,6)&&A<=REF(L11,7),REF(L11,8),0);
P9:=IFELSE(A>REF(L11,9)&&A<=REF(L11,1)&&A<=REF(L11,2)&&A<=REF(L11,3)&&A<=REF(L11,4)&&A<=REF(L11,5)&&A<=REF(L11,6)&&A<=REF(L11,7)&&A<=REF(L11,8),REF(L11,9),0);
P10:=IFELSE(A>REF(L11,10)&&A<=REF(L11,1)&&A<=REF(L11,2)&&A<=REF(L11,3)&&A<=REF(L11,4)&&A<=REF(L11,5)&&A<=REF(L11,6)&&A<=REF(L11,7)&&A<=REF(L11,8)&&A<=REF(L11,9),REF(L11,10),0);
AA:=P1+P2+P3+P4+P5+P6+P7+P8+P9+P10;
PP1:=IFELSE(AA>REF(L11,1),REF(L11,1),0);
PP2:=IFELSE(AA>REF(L11,2)&&AA<=REF(L11,1),REF(L11,2),0);
PP3:=IFELSE(AA>REF(L11,3)&&AA<=REF(L11,1)&&AA<=REF(L11,2),REF(L11,3),0);
PP4:=IFELSE(AA>REF(L11,4)&&AA<=REF(L11,1)&&AA<=REF(L11,2)&&AA<=REF(L11,3),REF(L11,4),0);
PP5:=IFELSE(AA>REF(L11,5)&&AA<=REF(L11,1)&&AA<=REF(L11,2)&&AA<=REF(L11,3)&&AA<=REF(L11,4),REF(L11,5),0);
PP6:=IFELSE(AA>REF(L11,6)&&AA<=REF(L11,1)&&AA<=REF(L11,2)&&AA<=REF(L11,3)&&AA<=REF(L11,4)&&AA<=REF(L11,5),REF(L11,6),0);
PP7:=IFELSE(AA>REF(L11,7)&&AA<=REF(L11,1)&&AA<=REF(L11,2)&&AA<=REF(L11,3)&&AA<=REF(L11,4)&&AA<=REF(L11,5)&&AA<=REF(L11,6),REF(L11,7),0);
PP8:=IFELSE(AA>REF(L11,8)&&AA<=REF(L11,1)&&AA<=REF(L11,2)&&AA<=REF(L11,3)&&AA<=REF(L11,4)&&AA<=REF(L11,5)&&AA<=REF(L11,6)&&AA<=REF(L11,7),REF(L11,8),0);
PP9:=IFELSE(AA>REF(L11,9)&&AA<=REF(L11,1)&&AA<=REF(L11,2)&&AA<=REF(L11,3)&&AA<=REF(L11,4)&&AA<=REF(L11,5)&&AA<=REF(L11,6)&&AA<=REF(L11,7)&&AA<=REF(L11,8),REF(L11,9),0);
PP10:=IFELSE(AA>REF(L11,10)&&AA<=REF(L11,1)&&AA<=REF(L11,2)&&AA<=REF(L11,3)&&AA<=REF(L11,4)&&AA<=REF(L11,5)&&AA<=REF(L11,6)&&AA<=REF(L11,7)&&AA<=REF(L11,8)&&AA<=REF(L11,9),REF(L11,10),0);
AAA:=PP1+PP2+PP3+PP4+PP5+PP6+PP7+PP8+PP9+PP10;
C11:=VALUEWHEN(AAA>0,AAA);
T1:=IFELSE(B<REF(H11,1),REF(H11,1),0);
T2:=IFELSE(B<REF(H11,2)&&B>=REF(H11,1),REF(H11,2),0);
T3:=IFELSE(B<REF(H11,3)&&B>=REF(H11,1)&&B>=REF(H11,2),REF(H11,3),0);
T4:=IFELSE(B<REF(H11,4)&&B>=REF(H11,1)&&B>=REF(H11,2)&&B>=REF(H11,3),REF(H11,4),0);
T5:=IFELSE(B<REF(H11,5)&&B>=REF(H11,1)&&B>=REF(H11,2)&&B>=REF(H11,3)&&B>=REF(H11,4),REF(H11,5),0);
T6:=IFELSE(B<REF(H11,6)&&B>=REF(H11,1)&&B>=REF(H11,2)&&B>=REF(H11,3)&&B>=REF(H11,4)&&B>=REF(H11,5),REF(H11,6),0);
T7:=IFELSE(B<REF(H11,7)&&B>=REF(H11,1)&&B>=REF(H11,2)&&B>=REF(H11,3)&&B>=REF(H11,4)&&B>=REF(H11,5)&&B>=REF(H11,6),REF(H11,7),0);
T8:=IFELSE(B<REF(H11,8)&&B>=REF(H11,1)&&B>=REF(H11,2)&&B>=REF(H11,3)&&B>=REF(H11,4)&&B>=REF(H11,5)&&B>=REF(H11,6)&&B>=REF(H11,7),REF(H11,8),0);
T9:=IFELSE(B<REF(H11,9)&&B>=REF(H11,1)&&B>=REF(H11,2)&&B>=REF(H11,3)&&B>=REF(H11,4)&&B>=REF(H11,5)&&B>=REF(H11,6)&&B>=REF(H11,7)&&B>=REF(H11,8),REF(H11,9),0);
T10:=IFELSE(B<REF(H11,10)&&B>=REF(H11,1)&&B>=REF(H11,2)&&B>=REF(H11,3)&&B>=REF(H11,4)&&B>=REF(H11,5)&&B>=REF(H11,6)&&B>=REF(H11,7)&&B>=REF(H11,8)&&B>=REF(H11,9),REF(H11,10),0);
BB:=IFELSE((T1+T2+T3+T4+T5+T6+T7+T8+T9+T10)=0,888888,T1+T2+T3+T4+T5+T6+T7+T8+T9+T10);
TT1:=IFELSE(BB<REF(H11,1),REF(H11,1),0);
TT2:=IFELSE(BB<REF(H11,2)&&BB>=REF(H11,1),REF(H11,2),0);
TT3:=IFELSE(BB<REF(H11,3)&&BB>=REF(H11,1)&&BB>=REF(H11,2),REF(H11,3),0);
TT4:=IFELSE(BB<REF(H11,4)&&BB>=REF(H11,1)&&BB>=REF(H11,2)&&BB>=REF(H11,3),REF(H11,4),0);
TT5:=IFELSE(BB<REF(H11,5)&&BB>=REF(H11,1)&&BB>=REF(H11,2)&&BB>=REF(H11,3)&&BB>=REF(H11,4),REF(H11,5),0);
TT6:=IFELSE(BB<REF(H11,6)&&BB>=REF(H11,1)&&BB>=REF(H11,2)&&BB>=REF(H11,3)&&BB>=REF(H11,4)&&BB>=REF(H11,5),REF(H11,6),0);
TT7:=IFELSE(BB<REF(H11,7)&&BB>=REF(H11,1)&&BB>=REF(H11,2)&&BB>=REF(H11,3)&&BB>=REF(H11,4)&&BB>=REF(H11,5)&&BB>=REF(H11,6),REF(H11,7),0);
TT8:=IFELSE(BB<REF(H11,8)&&BB>=REF(H11,1)&&BB>=REF(H11,2)&&BB>=REF(H11,3)&&BB>=REF(H11,4)&&BB>=REF(H11,5)&&BB>=REF(H11,6)&&BB>=REF(H11,7),REF(H11,8),0);
TT9:=IFELSE(BB<REF(H11,9)&&BB>=REF(H11,1)&&BB>=REF(H11,2)&&BB>=REF(H11,3)&&BB>=REF(H11,4)&&BB>=REF(H11,5)&&BB>=REF(H11,6)&&BB>=REF(H11,7)&&BB>=REF(H11,8),REF(H11,9),0);
TT10:=IFELSE(BB<REF(H11,10)&&BB>=REF(H11,1)&&BB>=REF(H11,2)&&BB>=REF(H11,3)&&BB>=REF(H11,4)&&BB>=REF(H11,5)&&BB>=REF(H11,6)&&BB>=REF(H11,7)&&BB>=REF(H11,8)&&BB>=REF(H11,9),REF(H11,10),0);
BBB:=TT1+TT2+TT3+TT4+TT5+TT6+TT7+TT8+TT9+TT10;
D:=VALUEWHEN(BBB>0,BBB);
UD:=IFELSE(CLOSE>D&&REF(CLOSE,1)<=D,1,IFELSE(CLOSE<C11&&REF(CLOSE,1)>=C11,-3,0));
K:=VALUEWHEN(UD<>0,UD);
G:=IFELSE(K=1,C11,D),COLORRED;
G1:=VALUEWHEN(ISLASTBAR,G);
TMP:=-K;
//TMP>0,SPK;
//TMP<=0,BPK;
IF HOLDING=0 THEN BEGIN   //若持仓为0
IF TMP<=0 THEN           //且TMP<=0
  BUY(1,1,LIMITR,CLOSE);  //开多单
END
IF HOLDING=0 THEN BEGIN   //若持仓为0
IF TMP>0 THEN            //且TMP>0
  BUYSHORT(1,1,LIMITR,CLOSE);  //开空单
END
IF HOLDING>0 THEN BEGIN   //若持有多单
IF TMP>0 THEN BEGIN      //且TMP>0
  SELL(1,HOLDING,LIMITR,CLOSE);   //平多单
  BUYSHORT(1,1,LIMITR,CLOSE);    //开空单
END
END
IF HOLDING<0 THEN BEGIN    //若持有空单
IF TMP<=0 THEN BEGIN      //且TMP<=0
  SELLSHORT(1,HOLDING,LIMITR,CLOSE);  //平空单
  BUY(1,1,LIMITR,CLOSE);    //开多单
END
END

//其他  
次数:TOTALTRADE,LINETHICK0;
胜率:PERCENTWIN,LINETHICK0;
连亏:MAXSEQLOSS,LINETHICK0;
连赢:MAXSEQWIN,LINETHICK0;
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;

回复

使用道具 举报

34

主题

9212

帖子

5万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
wenarm
发表于 2021-10-17 09:09 | 显示全部楼层
//多头止盈空头止损
IF (C-AVGENTERPRICE)/AVGENTERPRICE>0.015 THEN BEGIN
SELL(1,HOLDING,MARKET);
SELLSHORT(1,HOLDING,MARKET);
END

//多头止损空头止盈
IF (AVGENTERPRICE-C)/AVGENTERPRICE>0.015 THEN BEGIN
SELL(1,HOLDING,MARKET);
SELLSHORT(1,HOLDING,MARKET);
END
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

5

主题

11

帖子

11

积分

Rank: 1

等级: 新手上路

注册:
2021-7-30
曾用名:
 楼主| 发表于 2021-10-17 10:17 | 显示全部楼层
感谢6号大咖!只是把这段加到最后测试改进效果很小,是不是放的位置不对我也不懂?另外我想止损后反向开新仓,又如何编辑呢?
回复

使用道具 举报

34

主题

9212

帖子

5万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
wenarm
发表于 2021-10-17 18:56 | 显示全部楼层
放在“其他”的上面即可。这段代码止盈止损的位置影响不会特别大。

[PEL] 复制代码
//多头止盈空头止损
IF (C-AVGENTERPRICE)/AVGENTERPRICE>0.015 THEN BEGIN
	
	SELL(1,HOLDING,MARKET);

	if HOLDING<0 then BEGIN
		SELLSHORT(1,HOLDING,MARKET);
		BUY(1,1,MARKET);
	end

END

//多头止损空头止盈
IF (AVGENTERPRICE-C)/AVGENTERPRICE>0.015 THEN BEGIN

	if HOLDING>0 then BEGIN
		SELL(1,HOLDING,MARKET);
		BUYSHORT(1,1,MARKET);
	end
	SELLSHORT(1,HOLDING,MARKET);
END

金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

5

主题

11

帖子

11

积分

Rank: 1

等级: 新手上路

注册:
2021-7-30
曾用名:
 楼主| 发表于 2021-10-17 22:02 | 显示全部楼层
辛苦啦,多谢多谢!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2024-12-25 22:11 , Processed in 0.210429 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表