以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  代码编写  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=47536)

--  作者:金字塔散户
--  发布时间:2013/1/8 14:36:13
--  代码编写
以多头为例,
开仓价:=a;

下面一段代码帮忙写下
最高价为开仓到现在的最高价
如果1.02>最高价/开仓价>=1.01
出场价:=最高价*0.98
sell(限价,出场价)

如果最高价/开仓价>=1.02
出场价:=最高价*0.99
sell(限价,出场价)

--  作者:fly
--  发布时间:2013/1/8 15:30:59
--  

以图表程序化为例说明

 

variable:hh=0;//记录开仓到现在的最高价

 

pcj:=hh*0.98;

 

if hh/a>=1.01 and hh/a<1.02 and holding>0 then sell(1,1,lmt,trimprice(pcj));//a您给的开仓价

 

if hh/a>=1.02 and holding>0 then  sell(1,1,lmt,trimprice(pcj));

if con1 and holding=0 then begin //con1为开仓条件

  buy(1,1,mkt);

  hh:=h

  end

 

if holding>0 and h>=hh then hh:=h;//记录开仓后的最高价

[此贴子已经被作者于2013-1-8 15:56:09编辑过]

--  作者:金字塔散户
--  发布时间:2013/1/8 15:49:11
--  
你这个逻辑好像有点问题
if holding>0 and h>=hh then hh:=h;//记录开仓后的最高价
这句为什么在最后面啊?


我希望把开仓以来的最高价作为一个变量,每根k线都能用来判断一次,就写这一小段


--  作者:fly
--  发布时间:2013/1/8 15:55:18
--  

给的就是你想要的,只是你只看了一句,没理解

 

if con1 and holding=0 then begin //con1为开仓条件

  buy(1,1,mkt);

  hh:=h

  end

 

if holding>0 and h>=hh then hh:=h;//记录开仓后的最高价

 

请结合起来看,写出来的都是有必要的


--  作者:金字塔散户
--  发布时间:2013/1/8 23:57:18
--  

if con1  then begin 

kcj:=a;

buy(1,1,lmt,a);

hh:=h;

end


if holding>0 and h>=hh then hh:=h;


if hh/a>=1.01 and hh/a<1.02 and holding>0 then begin

pcj:=(hh+a)/2;

sell(1,1,lmt,pcj);

end

为什么写成这样回测的时候一次交易都没有,哪里有问题呢?






--  作者:jinzhe
--  发布时间:2013/1/9 8:48:06
--  
这个就是全局变量和普通的定义变量的区别了
--  作者:jiangsen
--  发布时间:2013/1/9 17:09:14
--  
应该怎么改?
--  作者:金字塔散户
--  发布时间:2013/1/9 17:23:08
--  
jinzhe能说具体点吗?