模型改编----- (文华财经WH8赢智V8.2)

投资者咨询:模型改编----- (文华财经WH8赢智V8.2)
来源:文华财经  日期:2018-7-28 9:47

 Params 
 Numeric MACDFastLength(12);
 Numeric MACDSlowLength(26);
 Numeric MACDLength(9);
 Numeric ATRLength(20); 
 Numeric nATR(20);  //n倍的ATR止盈
 Numeric StopLoss(200); //200个点止损  
 Numeric Lots(1);//手数
 
Vars
 NumericSeries MACDValue;
 Numeric AvgMACD;
 NumericSeries MACDDiff;
 NumericSeries AvgTR;          
 Bool BuyCon1(False);
 Bool SellShortCon1(False);
 NumericSeries StopProf;
 
Begin
 //过滤集合竞价
 If(!CallAuctionFilter()) return;
 
 //MACD
 MACDValue = XAverage( Close, MACDFastLength ) - XAverage( Close, MACDSlowLength ) ; 
 AvgMACD = XAverage(MACDValue,MACDLength);
 MACDDiff = MACDValue - AvgMACD;
 
 //ATR
 AvgTR = XAverage(TrueRange,ATRLength);
 StopProf = nATR*AvgTR[1];
 
 //开平仓条件
 BuyCon1 = MACDValue[2]<0 && MACDValue[1]>0;
 SellShortCon1 = MACDValue[2]>0 && MACDValue[1]<0;
 
 //开平仓1  
 If(MarketPosition!=1 && BuyCon1)
 {
  Buy(Lots,Open);
  Commentary("开多1");
 }
 If(MarketPosition!=-1 && SellShortCon1)
 {
  SellShort(Lots,Open);
  Commentary("开空1");  
 }

 //止损
 If(MarketPosition==1 && Low<=LastEntryPrice-StopLoss)
 {
  Sell(0,Min(Open,LastEntryPrice-StopLoss));
  Commentary("多头止损");
 }  
 If(MarketPosition==-1 && High>=LastEntryPrice+StopLoss)
 {
  BuyToCover(0,Max(Open,LastEntryPrice+StopLoss));
  Commentary("空头止损");
 } 

 //止赢
 If(MarketPosition==1 && High>=LastEntryPrice+StopProf)
 {
  Sell(0,Max(Open,LastEntryPrice+StopProf));
  Commentary("多头止赢");
 }  
 If(MarketPosition==-1 && Low<=LastEntryPrice-StopProf)
 {
  BuyToCover(0,Min(Open,LastEntryPrice-StopProf));
  Commentary("空头止赢");
 }  
End

IB代码,万分感谢

技术人员回复
日期:2018-7-28 11:46
 1楼更接近文华MQ软件的宽语言语法结构,可以通过MQ软件改写实现
技术人员回复
日期:2018-7-28 11:46