采取后台多策略操作,其中单独将止盈止损策略单独列出,但似乎始终无反应,不知问题在哪,程序如下:
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);出来的结果始终是四啥五入的整数,想了解程序在计算中是按这个四啥五入的结果清果还是按真实的持仓成本
就这个例子应该怎么改呢,这是一个独立的程序
请帮忙看一下这样改是否正确
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);
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