以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  多策略后台的移动止盈止损  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=30994)

--  作者:leonxu
--  发布时间:2012/11/29 12:53:11
--  多策略后台的移动止盈止损

采取后台多策略操作,其中单独将止盈止损策略单独列出,但似乎始终无反应,不知问题在哪,程序如下:

variable:maxprofit=0;

debugout(\'最新开仓价tavgenterprice=%2.f\',tavgenterprice);


//判断当前持仓状态下的最大盈利
win:=0;
win2:=0;

if tholding2 > 0 and tenterbars > 0 then
begin
 win:=(c-tavgenterprice)/tavgenterprice*100; //记录最大盈利
 if win > maxprofit then
  maxprofit:=win;
 
 win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end

if tholding2 < 0 and tenterbars > 0 then
begin
 win:=(tavgenterprice-c)/tavgenterprice*100; //记录最大盈利
 if win > maxprofit then
  maxprofit:=win;
 
 win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end

//出现浮动亏损比如2%平仓
多止损:tSELL(win<=-1*止损,0);
空止损:tSELLshort(win<=-1*止损,0);
 
//出现最高盈利后,回落到盈利的40%平仓出场
多止赢:tSELL(maxprofit>止盈 and win2 >= 60 and topenprofit>0,0);
空止赢:tSELLshort(maxprofit>止盈 and win2 >= 60 and topenprofit>0,0);

止盈和止损两参数在参数表内设置。

 

debugout(\'最新开仓价tavgenterprice=%2.f\',tavgenterprice);出来的结果始终是四啥五入的整数,想了解程序在计算中是按这个四啥五入的结果清果还是按真实的持仓成本

 


--  作者:leonxu
--  发布时间:2012/11/29 12:54:54
--  
另外多策略情况下,电脑轮询的顺序是不是按本地预警窗口内的策略顺序来进行的,如果这样需要调整顺序时好象没有提供控件,建议可以提供这个,
--  作者:jinzhe
--  发布时间:2012/11/29 13:01:12
--  
后台用extgbdataset和extgbdataget这两个来取/赋值全局变量
--  作者:leonxu
--  发布时间:2012/11/29 13:54:38
--  
请详细一点
--  作者:leonxu
--  发布时间:2012/11/29 13:55:37
--  
即不能用variable?
--  作者:jinzhe
--  发布时间:2012/11/29 14:00:14
--  
这个图表用的,我给你的两个函数你好好参考一下函数解释,用法和 variable差不多,都是满足 条件后赋值
--  作者:leonxu
--  发布时间:2012/11/29 15:10:32
--  嵌入式VBS、JS 脚本帮助文档

就这个例子应该怎么改呢,这是一个独立的程序


--  作者:leonxu
--  发布时间:2012/11/29 15:46:40
--  

请帮忙看一下这样改是否正确

 

if islastbar then extgbdataset(\'maxprofit\',0);

debugout(\'最新开仓价tavgenterprice=%2.f\',tavgenterprice);


//判断当前持仓状态下的最大盈利
win:=0;
win2:=0;

if tholding2 > 0 and tenterbars >=0 then
begin
 win:=(c-tavgenterprice)/tavgenterprice*100; //记录最大盈利
 if win > extgbdata(\'maxprofit\') then
  extgbdataset(\'maxprofit\',win);
 
 win2:=( extgbdata(\'maxprofit\')-win)/ extgbdata(\'maxprofit\')*100; //最大盈利后的回调幅度
end

if tholding2 < 0 and tenterbars >=0 then
begin
 win:=(tavgenterprice-c)/tavgenterprice*100; //记录最大盈利
 if win > extgbdata(\'maxprofit\') then
  extgbdataset(\'maxprofit\',win);
 
 win2:=(extgbdata(\'maxprofit\')-win)/ extgbdata(\'maxprofit\')*100; //最大盈利后的回调幅度
end

//出现浮动亏损比如2%平仓
多止损:tSELL(win<=-1*止损,0);
空止损:tSELLshort(win<=-1*止损,0);
 
//出现最高盈利后,回落到盈利的40%平仓出场
多止赢:tSELL( extgbdata(\'maxprofit\')>止盈 and win2 >= 60 and topenprofit>0,0);
空止赢:tSELLshort( extgbdata(\'maxprofit\')>止盈 and win2 >= 60 and topenprofit>0,0);


--  作者:jinzhe
--  发布时间:2012/11/29 16:28:19
--  

EXTGBDATASET( \'a\',0);给A赋值0

 EXTGBDATA(\'a\' );取A的值

 

比如移动止损时记录最高价

 

if 开仓条件  then begin

 

tbuy();

extgbdataset(\'a\',h);

 

end//最高价赋值给a

 

if h>extgbdataget(\'a\') then extgbdataset(\'a\',h);//当H大于A时,把H赋值给A