Params
//此处添加参数
Numeric Found(10000);//固定保证金
Numeric ZS(0.01);//止损比率1/100
Numeric BB(10);//ATR倍数
Numeric FastLength(12);
Numeric SlowLength(26);
Numeric MACDLength(9);
Numeric ATRLength(14);
Vars
//此处添加变量
Numeric Lots;
Numeric ATR;
Series<Numeric> DIFF;
Series<Numeric> DEA;
Numeric flag;
Series<Bool> Uptrue;
Series<Bool> Downtrue;
Series<Numeric> Counts;
Series<Numeric> MyentryPrice;
Defs
//此处添加公式函数
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次
OnInit()
{
//=========除权换月相关设置==============
AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权
AddDataFlag(Enum_Data_RolloverRealPrice()); //设置映射真实价格
AddDataFlag(Enum_Data_AutoSwapPosition()); //设置自动换仓
AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //设置忽略换仓信号计算
AddDataFlag(Enum_Data_ActivePeriod ); //设置K线分割为有效交易时段
SetOrderMap2MainSymbol(); //设置委托映射到主力
}
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
Lots = Max(1,IntPart(Found/(O/rollover*ContractUnit*BigPointValue*0.1)));
ATR = AvgTrueRange(ATRLength);
If(MarketPosition==0 && Year != Year[1])
{
Buy(Lots);
MyentryPrice == close;
}
If(MarketPosition != 0 && Close<EntryPrice*(1-ZS/1000))
{
Sell(0);//1%止损
Counts==Counts+1;
Commentary("当前位置1%止损");
}
If(MarketPosition == 0 && CrossOver(Close,MyentryPrice) && Counts>0 &&Year==Year[1])Buy(Lots);
老师 请问为什么这个MyentryPrice无法取到这个开仓价格 使用Commentary函数显示一直为0
MyentryPrice == close; 这个不是赋值,赋值是这样:MyentryPrice = close;