欢迎光临
专业期货策略平台

交易开拓者止盈代码下载

交易开拓者止盈源代码下载,有网友提供分享。

Params
Numeric longpara(30);
Numeric shortpara(10);
Numeric StopWin(0.5); //止盈系数,最大盈利回吐该系数作为止盈价
Numeric WinPoint(400); //止盈起始值(以价格计算)
Vars
NumericSeries MAlong; //长周期均线
NumericSeries MAshort; //短周期均线
Bool buycond;
Bool sellcond;
Numeric BuyOpen(100000); //多单开仓价
Numeric SellOpen(0); //空单开仓价
Numeric BuyStopWin(0); //多单止盈价
Numeric SellStopWin(0); //空单止盈价
Numeric OpenBar; //开仓K线的索引值
Numeric OpenCount; //当前K线到开仓K线之间的个数
Numeric MostHigh; //开仓后达到过的最高价
Numeric MostLow; //开仓后达到过的最低价
Begin
MAlong = Average(Close, longpara);
MAshort = Average(Close, shortpara);


buycond = CrossOver(MAshort, MAlong);
sellcond = CrossUnder(MAshort, MAlong);

//止盈代码
OpenCount = CurrentBar - GetGlobalVar(1); //计算开仓K线到当前K线的个数
If(MarketPosition == 1)
{
MostHigh = Highest(High, OpenCount); //计算开仓后到当前K线为止的最高价
If(MostHigh - GetGlobalVar(0) >= WinPoint) //开仓后最大浮盈(以价格计算)超过止盈起始值
{BuyStopWin = MostHigh - (MostHigh - GetGlobalVar(0)) * StopWin;} //计算止盈价格
If(Low <= BuyStopWin) //达到止盈条件时止盈
{Sell(0, Min(Open, BuyStopWin));}
}
If(MarketPosition == -1)
{
MostLow = Lowest(Low, OpenCount);
If(GetGlobalVar(0) - MostLow >= WinPoint)
{SellStopWin = MostLow + (GetGlobalVar(0) - MostLow) * StopWin;}
If(High >= SellStopWin)
{BuyToCover(0, Max(Open, SellStopWin));}
}
//止盈代码结束


If(buycond)
{
Buy(0, Close);
SetGlobalVar(0, Close); //记录开仓价
SetGlobalVar(1, CurrentBar); //记录开仓K线位置
Return;
}
If(sellcond)
{
SellShort(0, Close);
SetGlobalVar(0, Close); //记录开仓价
SetGlobalVar(1, CurrentBar); //记录开仓K线位置
Return;
}
End
0 0 vote
Article Rating
Click to rate this post!
[Total: 0 Average: 0]
赞(0) 打赏
未经允许不得转载:A期客 » 交易开拓者止盈代码下载
订阅
提醒
guest
0 评论
Inline Feedbacks
View all comments

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

0
Would love your thoughts, please comment.x
()
x