Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共2 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:移动止盈止损的代码,欢饮大家测试:

1楼
msedu 发表于:2018/6/2 12:35:07
//参数说明:stpDiff,止损距离;stpLinePeriod,止损移动均线周期;pbDiff,平保距离

input:stpDiff(10,5,50),stpLinePeriod(89,23,255),pbDiff(1,1,10);

stpLinePeriodValue:=ma(c,stpLinePeriod);
cond_exttime:=(currenttime>145900 and currenttime<150000) or (currenttime>232900 and currenttime<233000);

if Not(cond_exttime) Then Begin 
//空仓时初始化变量
If holding=0 Then Begin
stpLongEx:=0; //中间变量,在持有多单时,取移动止损值的时候,只有比上一个止损值更高的价位才会被采用
stpShortEx:=0; //中间变量,在持有空单时,。。。。
stpLong:=0; //多单止损值
stpShort:=0; //空单止损值
End
//多单移动止损
If holding>0  Then Begin
If close>AVGENTERPRICE+stpDiff Then Begin //这里注意处理信号消失的问题
pbValue:=AVGENTERPRICE+pbDiff;
stpValue:=max(pbValue,stpLinePeriodValue[1]);
End
Else Begin
stpValue:=AVGENTERPRICE-stpDiff;
End
If stpValue>stpLongEx or stpLongEx=0 Then Begin
stpLong:=stpValue;
stpLongEx=stpValue;
End
Else Begin
stpLong:=stpLongEx;
End
Sell(1,0,stopr,stpLong);
End
//空单移动止损
If holding<0 Then Begin
if close<AVGENTERPRICE-stpDiff Then Begin //这里注意处理信号消失的问题
pbValue:=AVGENTERPRICE-pbDiff;
stpValue:=min(pbValue,stpLinePeriodValue[1]);
End
Else Begin
stpValue:=AVGENTERPRICE+stpDiff;
End
If stpValue<stpShortEx or stpShortEx=0 Then Begin
stpShort:=stpValue;
stpShortEx:=stpValue;
End
Else Begin
stpShort:=stpShortEx;
End
Sellshort(1,0,stopr,stpShort);
End
End
Else Begin
Sell(holding>0,0,market);
Sellshort(holding<0,0,market);
End
2楼
cdqwy781 发表于:2018/6/2 23:09:41
好好好谢谢分享能讲解下就更好了
共2 条记录, 每页显示 10 条, 页签: [1]


Powered By Dvbbs Version 8.3.0
Processed in .07813 s, 2 queries.