请版主帮看看,移动止损部分是在其他帖子上拷贝学习的,好像不能实现移动止盈的功能呢,我自己初步判断是不是high和low的数值不对,因为我是在5nK线上加载的。请帮忙看下该怎么实现移动止盈功能。
//各种变量***************************************
input:NumberOpenPositions(1,1,10),NumberStop(15,10,20),TargetProfit(30,10,1000);
variable:MaxProfit=0;
TodayOpen:valuewhen(todaybar=1,open);
MaOneMin:ma(close,12);
CrossUp:cross(MaOneMin,TodayOpen),nodraw;
CrossDown:cross(TodayOpen,MaOneMin),nodraw;
//固定止损部分***********************************
if enterprice-c>NumberStop*mindiff and holding>0 then
sell(1,holding,marketr);
if c-enterprice>NumberStop*mindiff and holding<0 then
sellshort(1,holding,marketr);
//移动止损部分***********************************
if holding>0 and enterbars>=0 then begin
win:=high-avgenterprice;
if win>MaxProfit then MaxProfit:=win;
win2:=MaxProfit-win;end
if holding<0 and enterbars>=0 then begin
win:=avgenterprice-low;
if win>MaxProfit then MaxProfit:=win;
win2:=MaxProfit-win;end
if MaxProfit>=TargetProfit*mindiff and win2>0.2*MaxProfit then begin
sell(holding>0,holding,marketr);
sellshort(holding<0,holding,marketr);
MaxProfit:=0;end
//开仓部分****************************************
//if MaOneMin>TodayOpen and holding=0 then
buyshort(CrossDown,NumberOpenPositions,marketr);
//if TodayOpen>MaOneMin and holding=0 then
buy(CrossUp,NumberOpenPositions,marketr);
当前持仓:HOLDING,COLORGRAY,LINETHICK0,nodraw;
这段代码并没有什么问题的。你觉得有问题你需要具体指出来,具体情况具体分析。比如某个K线某个价格情况下符合条件却没有移动止损之类的,给出具体例子说明,才能方便处理的。另外如果你是没办法分清里面各种开平操作的情况,可以给交易语句做一下处理:
比如
if MaxProfit>=TargetProfit*mindiff and win2>0.2*MaxProfit then begin
移动止损1:sell(holding>0,holding,marketr);
移动止损2:sellshort(holding<0,holding,marketr);
MaxProfit:=0;end
这样你也能看到具体什么位置出了止损的信号。