金字塔决策交易系统

用户名  找回密码
 

微信登录

微信扫一扫,快速登录

帖子
查看: 6562|回复: 10

为什么限制交易失效,图表上还是多次加仓

[复制链接]

18

主题

55

帖子

55

积分

Rank: 6Rank: 6

等级: 机构版

注册:
2022-12-9
曾用名:
发表于 2023-1-3 08:32 | 显示全部楼层 |阅读模式
variable:nums:=0;

if bpkcond then begin
   sellshort(holding<0,0,thisclose);
   buy(holding=0,lot,thisclose);
   nums:=1;
   end

if spkcond then begin
   sell(holding>0,0,thisclose);
   buyshort(holding=0,lot,thisclose);
   nums:=1;
   end
if  nums<2  then begin
回调加多:buy(多单回调,lot,thisclose);
nums:=2;
end
if  nums<2  then begin
回调加空:sell(空单回调,lot,thisclose);
nums:=2;
end

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号? 微信登录

x
回复

举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-1-3 08:59 | 显示全部楼层
如果你这个条件 bpkcond 持续满足的话 你这里就限制不住。因为每次满足时候 都会重置全局变量。

if bpkcond and holding<=0 then begin
   sellshort(holding<0,0,thisclose);
   buy(holding=0,lot,thisclose);
   nums:=1;
   end
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

举报

18

主题

55

帖子

55

积分

Rank: 6Rank: 6

等级: 机构版

注册:
2022-12-9
曾用名:
 楼主| 发表于 2023-1-3 09:19 | 显示全部楼层
技术009 发表于 2023-1-3 08:59
如果你这个条件 bpkcond 持续满足的话 你这里就限制不住。因为每次满足时候 都会重置全局变量。

if bpkc ...

bpkcoond持续满足的话,holding<=0又不可能满足,那怎么办呢?
回复

举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-1-3 09:24 | 显示全部楼层
这个限制条件 对你if内部的开平无影响。只会限制你全局变量不会被错误重置。你之前那个写法,开仓之后 里面的全局变量 还是会被重置。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

举报

18

主题

55

帖子

55

积分

Rank: 6Rank: 6

等级: 机构版

注册:
2022-12-9
曾用名:
 楼主| 发表于 2023-1-3 10:28 | 显示全部楼层
技术009 发表于 2023-1-3 09:24
这个限制条件 对你if内部的开平无影响。只会限制你全局变量不会被错误重置。你之前那个写法,开仓之后 里面 ...

那怎么写好呢
回复

举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-1-3 10:47 | 显示全部楼层
我不是都写出来了?你没看到我加红标记的吗。。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

举报

18

主题

55

帖子

55

积分

Rank: 6Rank: 6

等级: 机构版

注册:
2022-12-9
曾用名:
 楼主| 发表于 2023-1-3 10:50 | 显示全部楼层
还是不行。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号? 微信登录

x
回复

举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-1-3 11:12 | 显示全部楼层
你 nums 是不是还有其他重置的语句?你直接贴下代码吧。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

举报

18

主题

55

帖子

55

积分

Rank: 6Rank: 6

等级: 机构版

注册:
2022-12-9
曾用名:
 楼主| 发表于 2023-1-3 20:52 | 显示全部楼层
技术009 发表于 2023-1-3 11:12
你 nums 是不是还有其他重置的语句?你直接贴下代码吧。

//***********************************//交易系统//***********************************//
variable:nums:=0;

if bpkcond and holding<=0 then begin
   sellshort(holding<0,0,thisclose);
   buy(holding=0,lot,thisclose);
   nums:=1;
   end
   
if spkcond and holding>=0 then begin
   sell(holding>0,0,thisclose);
   buyshort(holding=0,lot,thisclose);
   nums:=1;
   end
////  
多单回调:holding>0 and (底背离 or cross(ma1,c) or cross(0,j)) and enterbars>1;
空单回调:holding<0 and (顶背离 or cross(c,ma1) or cross(j,100)) and enterbars>1;
//多单回调:holding>0 and  cross(0,j);
//空单回调:holding<0 and cross(j,100);
//
if  nums<2  then begin
回调加多:buy(多单回调,lot,thisclose);
nums:=2;
end
if  nums<2  then begin
回调加空:sell(空单回调,lot,thisclose);
nums:=2;
end
//

顶背离止盈卖1/2:sell(holding>0 and 顶背离 ,holding/2,thisclose);
底背离止盈买1/2:sellshort(holding<0 and 底背离  ,holding/2,thisclose);

if   barslast(顶背离)>1 then begin
破ma1清多:sell(holding>0 and c<ma2,0,thisclose);
nums:=0;
end
if     barslast(底背离)>1 then begin
破ma1清空:sellshort(holding<0 and c>ma2 ,0,thisclose);
nums:=0;
end

if  nums>=0 then begin
破ma2清多:sell(holding>0 and c<ma2,0,thisclose);
破ma2清空:sellshort(holding<0 and c>ma2 ,0,thisclose);
nums:=0;
end
//***********************************//资产输出//***********************************//
回复

举报

37

主题

1万

帖子

6万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
wenarm
发表于 2023-1-4 09:15 | 显示全部楼层
本帖最后由 技术006 于 2023-1-4 09:17 编辑

[PEL] 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//***********************************//交易系统//***********************************//
variable:nums:=0;
 
if bpkcond and holding<=0 then begin
   sellshort(holding<0,0,thisclose);
   buy(holding=0,lot,thisclose);
   nums:=1;
   end
    
if spkcond and holding>=0 then begin
   sell(holding>0,0,thisclose);
   buyshort(holding=0,lot,thisclose);
   nums:=1;
   end
//// 
多单回调:holding>0 and (底背离 or cross(ma1,c) or cross(0,j)) and enterbars>1;
空单回调:holding<0 and (顶背离 or cross(c,ma1) or cross(j,100)) and enterbars>1;
//多单回调:holding>0 and  cross(0,j);
//空单回调:holding<0 and cross(j,100);
//
if  nums<2  then begin
回调加多:buy(多单回调,lot,thisclose);
nums:=2;
end
if  nums<2  then begin
回调加空:sell(空单回调,lot,thisclose);
nums:=2;
end
//
 
顶背离止盈卖1/2:sell(holding>0 and 顶背离 ,holding/2,thisclose);
底背离止盈买1/2:sellshort(holding<0 and 底背离  ,holding/2,thisclose);
 
//按照之前的写法,只要barslast(顶背离)>1成立,就会修改nums,//但是平仓语句中存在子条件,它不一定同时执行,从而造成之后的再次加仓。(其他几处同理,所以将子条件拆出来放在主干部分)
if   barslast(顶背离)>1 and holding>0 and c<ma2 then begin
破ma1清多:sell(1,0,thisclose);
nums:=0;
end
if  barslast(底背离)>1 and holding<0 and c>ma2  then begin
破ma1清空:sellshort(1,0,thisclose);
nums:=0;
end
 
if  nums>=0  and holding>0 and c<ma2 then begin
破ma2清多:sell(1,0,thisclose);
nums:=0;
end
 
if  nums>=0 and holding<0 and c>ma2 then begin
破ma2清空:sellshort(1,0,thisclose);
nums:=0;
end

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

举报

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

本版积分规则

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

GMT+8, 2025-7-17 04:55 , Processed in 0.149788 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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