提示信号闪烁但找不到原因

这段代码运行时一直提示信号闪烁,已经看过教学视频也没有找到原因,比如今晚的橡胶(2025年5月6日夜盘Ru888),有没有高手可以帮忙解决这个问题呢?

Params

//此处添加参数

Numeric Length(20);//中轨周期

Numeric Offset(2);   //方差

Numeric NTR(5);

Integer Fund(1000000);      //保证金

Vars

//头寸计算

Numeric RiskRatio(0.02);

Numeric Lots; // 交易手数

Series<Numeric> MidLine; //中轨

Series<Numeric> UpLine; //上轨

Series<Numeric> DownLine; //下轨

Series<Numeric> CTR;

Series<Numeric> ATR;

Series<Numeric> Stopline;

Series<Numeric> HH;

Series<Numeric> LL;

Global Numeric if_entry;  //当天有平仓则不开新仓

Global Numeric EntryPeriod;

Global Numeric EntryBar;

Global Numeric Exitbar;

Plot plt1;

Plot plt2;  

Defs

//此处添加公式函数

Events

//此处实现事件函数

//初始化事件函数,策略运行期间,首先运行且只有一次

OnInit()

{

Range[0:DataCount-1]

{

AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权

AddDataFlag(Enum_Data_AutoSwapPosition()); //设置自动换仓

AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //设置忽略换仓信号计算

}

plt1.setOption("MA1","color",Green());

       plt1.setOption("MA1","width",Enum_2Pix());

       plt1.setOption("MA1","line-display","interval");

       plt2.setOption("MA2","color",Green());

       plt2.setOption("MA2","width",Enum_2Pix());

       plt2.setOption("MA2","line-display","interval");        

       if_entry = 0;

}

//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组

OnBar(ArrayRef<Integer> indexs)

{

ATR = Average(MAX(MAX((HIGH-LOW),ABS(Close[1]-HIGH)),ABS(Close[1]-LOW)),14);

CTR = Average(Abs(Close-Close[1]),Length);

MidLine = Average(Close, Length);

UpLine = MidLine + StandardDev(Close,Length,2) * Offset;

DownLine = MidLine - StandardDev(Close,Length,2) * Offset;

PlotNumeric("mid",MidLine,MidLine);

PlotNumeric("UpLine",UpLine,UpLine);

PlotNumeric("DownLine",DownLine,DownLine);

//跟踪止损价

EntryPeriod=CurrentBar-EntryBar;

HH = Highest(Close - NTR*CTR, EntryPeriod);

LL = Lowest(Close + NTR*CTR, EntryPeriod);      

If(MarketPosition == 1 && EntryPeriod >= Length){   //进场后ATRMD出现过超买即可

Stopline = Max(HH, MidLine);

plt1.line("MA1",Date+Time,Stopline);

}

If(MarketPosition == -1 && EntryPeriod >= Length){

Stopline = min(LL, MidLine);

plt2.line("MA2",Date+Time,Stopline);

}

If(MarketPosition == 1  && Low <= Stopline[1] && EntryPeriod >= Length){

Sell(0,min(Stopline[1],Open));

if_entry = 1;

Exitbar = CurrentBar;

}

If(MarketPosition == 1  && Low <= Midline[1] && EntryPeriod > 0){

Sell(0,min(Midline[1],Open));

if_entry = 1;

Exitbar = CurrentBar;

}

If(MarketPosition == -1 && High >= Stopline[1] && EntryPeriod >= Length){

BuyToCover(0,Max(Stopline[1],Open));

if_entry = 1;

Exitbar = CurrentBar;

}

If(MarketPosition == -1 && High >= Midline[1] && EntryPeriod > 0){

BuyToCover(0,Max(Midline[1],Open));

if_entry = 1;

Exitbar = CurrentBar;

}

if (MarketPosition == 0 && CurrentBar > Exitbar){

if_entry = 0;}

If(MarketPosition == 0 && High >= UpLine[1] && if_entry == 0){

Lots = Round(Fund * RiskRatio / (Abs(MidLine[1]-Max(Open,UpLine[1]))*ContractUnit()*BigPointValue()),0);

Buy(Lots,Max(Open,UpLine[1]));

EntryBar=CurrentBar;

}

If(MarketPosition == 0 && Low <= DownLine[1] && if_entry == 0){

Lots = Round(Fund * RiskRatio / (Abs(MidLine[1]-min(Open,DownLine[1]))*ContractUnit()*BigPointValue()),0);

SellShort(Lots,Min(Open,DownLine[1]));

EntryBar=CurrentBar;

}

If(MarketPosition == 0){

Stopline = Midline;

EntryBar=CurrentBar;

Stopline = MidLine;}

EntryPeriod=CurrentBar-EntryBar;

}

信号闪烁找不到原因
公式遇到信号闪烁问题,如何找原因?
查找程序闪烁的原因
信号闪烁问题
信号闪烁问题
图表有开仓信号,但系统判定信号闪烁,未进行开仓如何解决,我确认代码是没有闪烁的问题
信号闪烁的原因是vol还是adx
关于信号闪烁
信号闪烁
信号闪烁问题

先找到哪个信号闪

然后在对应信号的条件里找问题

这个位置有问题了,

If(MarketPosition == 0){

Stopline = Midline;

EntryBar=CurrentBar;

Stopline = MidLine;}

EntryBar 这个变量是全局变量被赋值为0了。EntryPeriod=CurrentBar-EntryBar;这个值跟着变化,那么tick数据和bar数据就不会一样。建议少用全局变量,改为序列变量。全局变量用一定得很小心。

EntryBar 这个变量是全局变量被赋值为CurrentBar了

感谢感谢,这样改就可以了,老板比工作人员用心得多

付费代写或者投稿都行

或者等个有缘人