以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  先止损后开仓,一一对应  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=153756)

--  作者:系统使用者
--  发布时间:2017/5/20 15:11:45
--  先止损后开仓,一一对应
这样编写程序顺序合理,正确? 
pdd:=aq1>=1 and l>fl;
pkk:=aq1>=1 and h<fh;

VARIABLE: ll=0, hh=0, astop=0, bstop=0, temp_ll[]=0, temp_hh[]=0; 
//交易系统
 if enterbars>1 and l<astop -2*MINDIFF and holding>0 then sell(1,0,marketr);//止损止盈,实时出场
  if h>valuewhen(TYPE(2),hhv(fh,10)) and holding=0 and 仓差>0 then buy(1,ss,marketr);//止损后,再次入场
 if enterbars>1 and h>bstop +2*MINDIFF and holding<0 then sellshort(1,0,marketr);//止损止盈,实时出场
  if l<valuewhen(TYPE(4),llv(fl,10)) and holding=0 and 仓差<0 then buyshort(1,ss,marketr);//止损后,再次入场
 //开多 
temp_ll:=llv(l,2);
if pdd then
begin
   sellshort(1,0,marketr);
   buy(holding=0 and 仓差>0,ss,marketr);
   ll:=temp_ll;
end
astop:=ll;
//开空
temp_hh:=hhv(h,2);
if pkk then
begin
   sell(1,0,marketr);
   buyshort(holding=0 and 仓差<0,ss,marketr);
   hh:=temp_hh;
end
bstop:=hh;

--  作者:系统使用者
--  发布时间:2017/5/20 15:12:49
--  
另外这样编写法:
pdd:=aq1>=1 and l>fl;
pkk:=aq1>=1 and h<fh;
//交易系统
temp_ll:=llv(l,2);
if pdd then
begin
   sellshort(1,0,marketr);
   buy(holding=0 and 仓差>0,ss,marketr);
   ll:=temp_ll;
end
 if enterbars>1 and l<ll-2*MINDIFF and holding>0 then sell(1,0,marketr);//止损止盈,实时出场
 if h>valuewhen(TYPE(2),hhv(fh,10)) and holding=0 and 仓差>0 then buy(1,ss,marketr);

temp_hh:=hhv(h,2);
if pkk then
begin
   sell(1,0,marketr);
   buyshort(holding=0 and 仓差<0,ss,marketr);
   hh:=temp_hh;
end
 if enterbars>1 and h>hh+2*MINDIFF and holding<0 then sellshort(1,0,marketr);
 if l<valuewhen(TYPE(4),llv(fl,10)) and holding=0 and 仓差<0 then buyshort(1,ss,marketr);

--  作者:系统使用者
--  发布时间:2017/5/20 15:13:56
--  
关键要保证止损一定要执行。
--  作者:系统使用者
--  发布时间:2017/5/20 15:16:08
--  
在线等
--  作者:系统使用者
--  发布时间:2017/5/20 15:18:32
--  
在线等。VIP
图片点击可在新窗口打开查看此主题相关图片如下:qq图片20170520151708.png
图片点击可在新窗口打开查看
客户
--  作者:系统使用者
--  发布时间:2017/5/20 15:22:28
--  
若不正确帮忙修改,请帮忙改为后台模式。
[此贴子已经被作者于2017/5/20 15:23:21编辑过]

--  作者:系统使用者
--  发布时间:2017/5/21 14:43:26
--  
在实盘跑的时候,出现单独的开多或者开空,平多或者平空都正确,
1)一遇到双向的开仓(平空开多,平多开空)就出现问题,出现不能平空就出现开多,或者干脆出现信号就不下单。
2)问题出现在这里反手,
if pdd then
begin
   sellshort(1,0,marketr);
   buy(holding=0 and 仓差>0,ss,marketr);
   ll:=temp_ll;
end
估计是不是函数holding实盘问题,实盘取不到持仓。若出现这样的图表交易该如何处理?

[此贴子已经被作者于2017/5/21 14:44:16编辑过]

--  作者:系统使用者
--  发布时间:2017/5/21 17:25:38
--  
VARIABLE: ll=0, hh=0, astop=0, bstop=0, temp_ll[]=0, temp_hh[]=0; 
//交易系统
 if enterbars>1 and l<astop -2*MINDIFF and holding>0 then sell(1,0,marketr);//止损止盈,实时出场
 if enterbars>1 and h>bstop +2*MINDIFF and holding<0 then sellshort(1,0,marketr);//止损止盈,实时出场
  
 //开多 
temp_ll:=llv(l,2);
if pdd then
begin
   sellshort(1,0,marketr);
   buy(holding=0 and 仓差>0,ss,marketr);
   ll:=temp_ll;
end
astop:=ll;

//开空
temp_hh:=hhv(h,2);
if pkk then
begin
   sell(1,0,marketr);
   buyshort(holding=0 and 仓差<0,ss,marketr);
   hh:=temp_hh;
end
bstop:=hh;
   if h>valuewhen(TYPE(2),hhv(fh,10)) and holding=0 and 仓差>0 then buy(1,ss,marketr);//止损后,再次入场
   if l<valuewhen(TYPE(4),llv(fl,10)) and holding=0 and 仓差<0 then buyshort(1,ss,marketr);//止损后,再次入场

这样顺序?

--  作者:系统使用者
--  发布时间:2017/5/21 17:28:52
--  
还有再次开仓的平仓会先执行那一个平仓顺序?
--  作者:系统使用者
--  发布时间:2017/5/21 17:42:08
--  
具体思路
1)条件pdd:=aq1>=1 and l>fl;开多
            pkk:=aq1>=1 and h<fh;开空
2)平仓就反手
3)若开仓后,开多的跌破开仓对应的2日最低点-2滑点止损;若开空的升破开仓对应的2日高点+2滑点止损;动态实盘止损。
4)若开多止损后,很快价格又再次上涨突破上次开多的10日内高点位置,开多单;
    开空止损相反;   平仓条件执行1)