金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 4170|回复: 19

求助指标怎么改写。

[复制链接]

47

主题

163

帖子

163

积分

等级: 免费版

注册:
2024-1-11
曾用名:
发表于 2024-2-22 09:20 | 显示全部楼层 |阅读模式
本帖最后由 技术006 于 2024-2-22 11:16 编辑

大神,有几个问题咨询;
1、为什么开仓后立马平仓了呢,这种连续的开仓平仓是怎么样用公式解决?是条件写错了吗?
2、为什么开多单或者开空单后有利润,没有到止盈100跳或者止损点位就平仓了么?像纸浆开多单后,没到位置就出现平多了。
3、我想在有写“多”或“空”字标识处开单,如果是“多”字标识开多单后,条件到开空单位置了,平多反手做空;如果是“空”字标识开空单后,条件到开多单位置了,平空反手做多;这些用公式怎么改呢?
4、在有利润的情况下,利润回撤20%即平仓位;
5、在趋势线ema((2*high+low+open+2*close)未变红的时候不开多单;未变绿的情况下不开空单。怎么用公式表达呢?
6、只做主力连续合约;每天9点10分开始做单,14点50分平掉所有仓位;
跪谢大神。



本帖子中包含更多资源

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

x
回复

使用道具 举报

47

主题

163

帖子

163

积分

等级: 免费版

注册:
2024-1-11
曾用名:
 楼主| 发表于 2024-2-22 09:22 | 显示全部楼层
k:=1;//首次开仓手数;
jk:=1;//加仓手数;
tt:=3;//开仓每个信号之间的间距;

tp:=100;//止盈
lp:=20;//止损;

ma5:=ema((high+low+open+2*close)/5,5);
ma10:=ema((2*high+low+open+2*close)/6,10);
ma55:=ema(ema(c,34),34);
n_jc_ma5_ma10:=sumbars(cross(ma5,ma10),1);//金叉加仓;
n_sc_ma5_ma10:=sumbars(cross(ma10,ma5),1);//死叉减仓;

//中枢线
中枢:ema(ema(c,10),10),colorgreen,linethick2;
aa:=中枢>ref(中枢,1);//多头趋势;
中枢线:if(aa-0.03,中枢,drawnull),colorred,linethick2;

//趋势线
趋势:ema((2*high+low+open+2*close)/6,34),colormagenta,linethick2;
a:=趋势>ref(趋势,1);//多头趋势;
趋势线:if(a-0.03,趋势,drawnull),colorred,linethick2;

//大趋势
多空线:ema(ema(c,34),34),colorwhite,linethick2;
a2:=多空线>ref(多空线,1);//多头趋势;
大趋势:if(a2-0.03,多空线,drawnull),colorred,linethick2;

b:=cross(ma5,趋势);
s:=cross(趋势,ma5);

//引用macd
diff:=ema(close,9)-ema(close,34);
dea:=ema(diff,9);
macd:=(diff-dea)*2,colorstick;

//引用kd;
rsv:=(close-llv(low,21))/(hhv(high,21)-llv(low,21))*100;
k:=sma(rsv,5,1),colorred;
d:=sma(k,5,1),colorgreen;

//多空
xx:=b and diff>dea and k>d;
xxx:=s and dea>diff and d>k;
drawtext(xx,l*0.9998,'多'),colorred,fontszup3;
drawtext(xxx,h+3,'空'),coloryellow,fontszup3;

barsbk:ref(c,typebar(1,1));
barssp:=ref(c,typebar(1,2));
//开仓
kd:=XX;
buy(kd and holding=0,k,market);
jd:=min(barsbk,barssp)>=tt and c>=ma55 and n_jc_ma5_ma10=1;//加仓
加多:buy(holding>0 and jd,tt,market);

pd1:=min(barsbk,barssp)>=tt and c>=ma55 and n_sc_ma5_ma10=1;//减仓
减仓:sell(pd1,tt,market);

pd2:=cross(ema(ema(c,34),34),c);//下穿55日均线时候,平所有仓位;
sell(pd2,holding,market);

dzy:=c>avgenterprice+tp*mindiff;//止盈100跳;
sell(dzy,holding,market);
dzs:=c<avgenterprice-lp*mindiff;//止损20跳;
sell(dzs,holding,market);

barssk:ref(c,typebar(1,3));
barssp:=ref(c,typebar(1,4));
kk1:=XXX;
buyshort(kk1 and holding=0,k,market);
kk2:=min(barssk,barssp)>=tt and c<ma55 and n_sc_ma5_ma10=1;
buyshort(kk2 and holding=0,jk,market);

pk1:=min(barssk,barssp)>=tt and c<ma55 and n_jc_ma5_ma10=1;
sellshort(pk1,jk,market);

pk2:=cross(c,ma55);
sellshort(pk2,holding,market);

pk3:=c<avgenterprice-lp*mindiff;
sellshort(pk3,holding,market);


if time>144500 then//如果时间在14点45分以后,那么
begin
sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量                                                                                    
end
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2024-2-22 09:39 | 显示全部楼层
1.
你使用北京时区的情况下:

if time>144500 then//如果时间在14点45分以后,那么
begin
sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量                                                                                    
end


夜盘的品种开了就会平,因为这个条件在夜盘恒满足。
if time>144500 and time<=150000 then//如果时间在14点45分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量                                                                                    
end

2.把第一个问题解决了再看。

另外建议把你的下单信号都做个标记,否则你都搞不清是哪个语法触发的下单。你以为的止盈 实际可能是收盘平仓条件没控制好触发的平仓。
//开仓
kd:=XX;
buy(kd and holding=0,k,market);
jd:=min(barsbk,barssp)>=tt and c>=ma55 and n_jc_ma5_ma10=1;//加仓
加多:buy(holding>0 and jd,tt,market);

pd1:=min(barsbk,barssp)>=tt and c>=ma55 and n_sc_ma5_ma10=1;//减仓
减仓:sell(pd1,tt,market);

pd2:=cross(ema(ema(c,34),34),c);//下穿55日均线时候,平所有仓位;
下穿ema平多:sell(pd2,holding,market);

dzy:=c>avgenterprice+tp*mindiff;//止盈100跳;
多止盈:sell(dzy,holding,market);
dzs:=c<avgenterprice-lp*mindiff;//止损20跳;
多止损:sell(dzs,holding,market);
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2024-2-22 09:42 | 显示全部楼层
3. 反手在相应开仓语句前面加个平仓就行了。

kk1:=XXX;
sell(kk1,holding,market);
buyshort(kk1 and holding=0,k,market);


//开仓
kd:=XX;
sellshort(kd and holding<0,holding,market);
buy(kd and holding=0,k,market);
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2024-2-22 10:06 | 显示全部楼层
[PEL] 复制代码
variable:maxprofit:=0.01;
k:=1;//首次开仓手数;
jk:=1;//加仓手数;
tt:=3;//开仓每个信号之间的间距;

tp:=100;//止盈
lp:=20;//止损;

ma5:=ema((high+low+open+2*close)/5,5);
ma10:=ema((2*high+low+open+2*close)/6,10);
ma55:=ema(ema(c,34),34);
n_jc_ma5_ma10:=sumbars(cross(ma5,ma10),1);//金叉加仓;
n_sc_ma5_ma10:=sumbars(cross(ma10,ma5),1);//死叉减仓;

//中枢线
中枢:ema(ema(c,10),10),colorgreen,linethick2;
aa:=中枢>ref(中枢,1);//多头趋势;
中枢线:if(aa-0.03,中枢,drawnull),colorred,linethick2;

//趋势线
趋势:ema((2*high+low+open+2*close)/6,34),colormagenta,linethick2;
a:=趋势>ref(趋势,1);//多头趋势;
趋势线:if(a-0.03,趋势,drawnull),colorred,linethick2;

//大趋势
多空线:ema(ema(c,34),34),colorwhite,linethick2;
a2:=多空线>ref(多空线,1);//多头趋势;
大趋势:if(a2-0.03,多空线,drawnull),colorred,linethick2;

b:=cross(ma5,趋势);
s:=cross(趋势,ma5);

//引用macd
diff:=ema(close,9)-ema(close,34);
dea:=ema(diff,9);
macd:=(diff-dea)*2,colorstick;

//引用kd;
rsv:=(close-llv(low,21))/(hhv(high,21)-llv(low,21))*100;
k:=sma(rsv,5,1),colorred;
d:=sma(k,5,1),colorgreen;

//多空
xx:=b and diff>dea and k>d and a;
xxx:=s and dea>diff and d>k and not(a);
drawtext(xx,l*0.9998,'多'),colorred,fontszup3;
drawtext(xxx,h+3,'空'),coloryellow,fontszup3;

barsbk:ref(c,typebar(1,1));
barssp:=ref(c,typebar(1,2));

if holding=0 then maxprofit:=0.01;

tcd:time>=091000 and time<145000;
//开仓
kd:=xx;
sellshort(kd and holding<0  ,holding,market);
buy(kd and holding=0 and tcd,k,market);
jd:=min(barsbk,barssp)>=tt and c>=ma55 and n_jc_ma5_ma10=1;//加仓
加多:buy(holding>0 and jd and tcd,tt,market);

pd1:=min(barsbk,barssp)>=tt and c>=ma55 and n_sc_ma5_ma10=1;//减仓
减仓:sell(pd1,tt,market);


pd2:=cross(ema(ema(c,34),34),c);//下穿55日均线时候,平所有仓位;
下穿ema平多:sell(pd2,holding,market);
dzy:=c>avgenterprice+tp*mindiff;//止盈100跳;
多止盈:sell(dzy,holding,market);

dzs:=c<avgenterprice-lp*mindiff;//止损20跳;
多止损:sell(dzs,holding,market);

barssk:ref(c,typebar(1,3));
barssp:=ref(c,typebar(1,4));
kk1:=xxx;
sell(kk1,holding,market);
if holding=0 then maxprofit:=0.01;


buyshort(kk1 and holding=0 and tcd,k,market);
kk2:=min(barssk,barssp)>=tt and c<ma55 and n_sc_ma5_ma10=1;
buyshort(kk2 and holding=0 and tcd,jk,market);

pk1:=min(barssk,barssp)>=tt and c<ma55 and n_jc_ma5_ma10=1;
sellshort(pk1,jk,market);

pk2:=cross(c,ma55);
sellshort(pk2,holding,market);

pk3:=c<avgenterprice-lp*mindiff;

空止盈:sellshort(pk3,holding,market);

if holding=0 then maxprofit:=0.01;


if  holding<>0 and maxprofit=0.01 then maxprofit:=openprofit;//如果maxprofit是初始值,直接赋值为最新的浮动盈亏
if openprofit>maxprofit and maxprofit<>0.01 then maxprofit:=openprofit;//更新最大盈利

//最大盈利大于0 当前小于最大盈利80% 
if maxprofit>0 and openprofit<=maxprofit*0.8  and  holding<>0 then 
begin
回撤平多:sell(holding>0,0,market);
回撤平空:sellshort(holding<0,0,market); 
maxprofit:=0.01;	 
end 

if time>144500 and time<=150000 then//如果时间在14点45分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量         
maxprofit:=0.01;                                                                           
end

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

使用道具 举报

47

主题

163

帖子

163

积分

等级: 免费版

注册:
2024-1-11
曾用名:
 楼主| 发表于 2024-2-22 10:08 | 显示全部楼层
技术009 发表于 2024-2-22 09:42
3. 反手在相应开仓语句前面加个平仓就行了。

kk1:=XXX;

6、只做主力连续合约;每天9点10分开始做单,14点50分平掉所有仓位;
大神,第6个问题;每天白天9点10分开始做单,14点50分平掉所有仓位;夜盘21点10分开始做单,收盘前10分钟平掉所有仓位;如果品种交易时间是到23点,则22点50分平仓位,如果品种交易时间是到凌晨01点,则凌晨12点50分平仓位,如果品种交易时间是到凌晨2点半,则凌晨2点20分平仓位;这句话怎么写呢。
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2024-2-22 10:11 | 显示全部楼层
时间控制的参考我前面贴的代码里的部分。你自己修改下就行了。搞来搞去就是对time做判断。

收盘平仓也是。 参考前面代码里已有部分修改下就行了。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

47

主题

163

帖子

163

积分

等级: 免费版

注册:
2024-1-11
曾用名:
 楼主| 发表于 2024-2-22 10:42 | 显示全部楼层
if time>091000 or time>211000 then//如果时间在09点10分 or 21点10分以后,那么
begin
xxx中间是公式;
省略...

if time>144500 and time<=150000 then//如果时间在14点45分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量        
maxprofit:=0.01;
or
if time>225000 and time<=230000 then//如果时间在22点50分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量        
maxprofit:=0.01;
or
if time>005000 and time<=010000 then//如果时间凌晨12点50分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量        
maxprofit:=0.01;
or
if time>022000 and time<=023000 then//如果时间凌晨2点20分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量        
maxprofit:=0.01;
总感觉不对呢.
大神。
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2024-2-22 10:47 | 显示全部楼层
你这个or是干嘛的。。 你后面那些if 语句都是独立判断的。不需要加or,你加了都编译不了的吧。
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

47

主题

163

帖子

163

积分

等级: 免费版

注册:
2024-1-11
曾用名:
 楼主| 发表于 2024-2-22 10:50 | 显示全部楼层
技术009 发表于 2024-2-22 10:47
你这个or是干嘛的。。 你后面那些if 语句都是独立判断的。不需要加or,你加了都编译不了的吧。

按照理解,每个应该是独立的或者关系呀。

if time>225000 and time<=230000 then//如果时间在22点50分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量        
maxprofit:=0.01;
or
if time>005000 and time<=010000 then//如果时间凌晨12点50分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量        
maxprofit:=0.01;
不加or能识别的了吗?
他们不会矛盾吗?
刚学也不是很久。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-1 07:34 , Processed in 0.109801 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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