我使用后台多策略,所以单独将止盈止损做了一个策略如下:
variable:maxprofit=0;
debugout('最新开仓价tenterprice=%2.f',tenterprice);
//判断当前持仓状态下的最大盈利
win:=0;
win2:=0;
if tholding2 > 0 and tenterbars > 0 then
begin
win:=(c-tenterprice)/tenterprice*100; //记录最大盈利
if win > maxprofit then
maxprofit:=win;
win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end
if tholding2 < 0 and tenterbars > 0 then
begin
win:=(tenterprice-c)/tenterprice*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 openprofit>0,0);
空止赢:tSELLshort(maxprofit>止盈 and win2 >= 60 and openprofit>0,0);
其中止盈和止损两个参数放在参数表中,但实际运行时好象都完全不起作用,不知为何
用debugout('最新开仓价tenterprice=%2.f',tenterprice);检查
奇怪,运行完显示是负一,是手数?不是开仓价,是因为没有交易语句吗,但我想它做为了一个统一的总的止盈止损的策略,如何实现
问题是tenterprice=1或-1,长期如此
用法:TENTERPRICE
该函数返回常数,并且只有在后台程式化交易运行中有效
该函数依赖TBUY等交易语句或者在交易监控中的手工干预的成交记录。
所属函数组:后台程式化交易(专业版)
看看你是不是因为是手工交易的原因而导致无法得到开仓价格而导致