给模型加入仓位控制

Params
	Numeric length(3);
	// 交易手数
	Numeric lots(6);
Vars
	// 最高价
	Numeric hp;
	// 最低价
	Numeric lp;
	// 平均成交量
	Numeric average_v; 
	// 多倍交易手数
	Numeric t_lots;
	// 均线
	Numeric ma;
Begin
	hp = Highest(High, length);
	lp = Lowest(Low, length);
	ma = Average(Open, 10);
	// 近三根k线的平均成交量
	average_v = Average(V, 60);
	If (Close > ma) 
	{
		t_lots = 2 * lots;
	}
	Else
	{
		t_lots = 1 * lots;
	}
	// 最高价突破,做多单, 建仓次数小于5,成交量放大近3根k线平均值3倍
	If (H == hp And CurrentEntries < 2 And V > 1.5 * average_v) 
	{
		Buy(t_lots, Close);
	}
	// 最低价突破,做反手单
	If (L == lp)
	{
		// 持空单返回负数,所以使用绝对值
		Sell(Abs(CurrentContracts()), Close);
	}
	PlotNumeric("ma", ma);
End

猜你喜欢

转载自blog.csdn.net/bus_lupe/article/details/85010604
今日推荐