设计模型的资金管理

版权声明:17602128911 https://blog.csdn.net/bus_lupe/article/details/85012756

获取账户资金

  • 系统函数
  • 账户函数

A_FreeMargin 返回当前公式应用的交易帐户的可用资金。 不能使用于历史测试,仅适用于实时行情交易。

商品保证金比率

  • 系统函数
  • 属性函数

MarginRatio当前公式应用商品的默认保证金比率,返回值为浮点数,仅对期货有效。

将浮点数转换成整型

Intpart

一手所需资金

一手10单,加上商品保证金比率。

Params
	Numeric length(3);
	// 交易手数
	Numeric lots(6);
	// 账户可用资金
	Numeric AvailableFunds(100000);
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 (Open > 49500) 
	{
		// 60%资金量成交, 1手10单,另加商品保证金
		t_lots = (AvailableFunds * 0.6) / (Close * (1 + MarginRatio()) * 10);
	}
	Else
	{
		t_lots = (AvailableFunds * 0.4) / (Close * (1 + MarginRatio()) * 10);
	}
	If (t_lots < 1) 
	{
		t_lots = 1;
	}
	// 最高价突破,做多单, 建仓次数小于5,成交量放大近3根k线平均值3倍
	If (H == hp And CurrentEntries < 2 And V > 1.5 * average_v) 
	{
		Buy(IntPart(t_lots), Close);
	}
	// 最低价突破,做反手单
	If (L == lp)
	{
		// 持空单返回负数,所以使用绝对值
		Sell(Abs(CurrentContracts()), Close);
	}
	PlotNumeric("ma", ma);
End


更多精彩内容