学习视频课的双均线交易系统,写了EMA的双均线交易系统,但是没有信号,麻烦看看。
Params
Numeric Length1(5);
Numeric Length2(20);
Vars
series<Numeric> EMA1;
series<Numeric> EMA2;
series<Bool> bool_crossover;
series<Bool> bool_crossunder;
Events
OnBar(ArrayRef<Integer> indexs)
{
//双EMA均线 用收盘价计算两根均线
PlotNumeric("EMA1",XAverage(Close, Length1));
PlotNumeric("EMA2",XAverage(Close, Length2));
//金叉和死叉状态
bool_crossover = EMA1[1] <= EMA2[1] and EMA1 > EMA2;
bool_crossunder = EMA1[1] >= EMA2[1] and EMA1 < EMA2;
If(bool_crossover[1])
{
Buy(1,Open);
}
If(bool_crossunder[1])
{
SellShort(1,Open);
}
}

知道错误原因了,ema1和ema2的两行代码漏掉了
😅
bool_crossover = EMA1[1] <= EMA2[1] and EMA1 > EMA2; bool_crossunder = EMA1[1] >= EMA2[1] and EMA1 < EMA2;
改成:bool_crossover = EMA1[12] <= EMA2[12] and EMA1[1] > EMA2[1]; bool_crossunder = EMA1[21] >= EMA2[12] and EMA1[1] < EMA2[1];再试试。
bool_crossover = EMA1[1] <= EMA2[1] and EMA1 > EMA2; bool_crossunder = EMA1[1] >= EMA2[1] and EMA1 < EMA2; 改成:bool_crossover = EMA1[2] <= EMA2[2] and EMA1[1] > EMA2[1]; bool_crossunder = EMA1[2] >= EMA2[2] and EMA1[1] < EMA2[1];再试试。以这个为准
bool_crossover = EMA1[1] <= EMA2[1] and EMA1 > EMA2; bool_crossunder = EMA1[1] >= EMA2[1] and EMA1 < EMA2; 改成:bool_crossover = EMA1[2] <= EMA2[2] and EMA1[1] > EMA2[1]; bool_crossunder = EMA1[2] >= EMA2[2] and EMA1[1] < EMA2[1];再试试。以这个为准
谢谢回复,我试了一下,还是不行😭