关于新交易日重置累计值失效的问题
Params
	//此处添加参数
	Numeric StdDevMultiplier(2.0);  // 标准差倍数(默认2.0)
    Numeric TimeFrame(225);        // 分钟周期(默认日线),按照商品交易分钟数填写

Vars
	//此处添加变量
	Series<Numeric> CumulativePV;     // 累计价格×成交量
    Series<Numeric> CumulativeVol;    // 累计成交量
    Series<Numeric> CumulativeVar;    // 累计方差((TypicalPrice - VWAP)^2 × Volume)
    Series<Numeric> VWAP_Value;       // VWAP值
    Series<Numeric> StdDev;           // 标准差
    Series<Numeric> UpperBand;        // 上轨
    Series<Numeric> LowerBand;        // 下轨
    Series<Numeric> UpperBand2;        // 上轨
    Series<Numeric> LowerBand2;        // 下轨
    Bool IsNewDay;                    // 判断是否新交易日

Defs
	//此处添加公式函数
	
Events
	//此处实现事件函数
	
	//初始化事件函数,策略运行期间,首先运行且只有一次
	OnInit()
	{
		
	}


	//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
	OnBar(ArrayRef<Integer> indexs)
	{
		//--- 判断是否新交易日 ---
    	IsNewDay = Date != Date[1];
    
    	//--- 新交易日重置累计值 ---
    	If (IsNewDay)
    	{
        	CumulativePV = 0;
        	CumulativeVol = 0;
        	CumulativeVar = 0;
    	}
    
    	//--- 计算典型价格 ---
    	Numeric TypicalPrice = (High + Low + Close) / 3;
    
    	//--- 更新累计价格×成交量 ---
   
        
        // 计算标准差

    
  	    //--- 绘制线形 ---
    	PlotNumeric("VWAP", VWAP_Value);

	}

以上代码希望可以按照日对整体变量进行刷新重置,通过以下代码进行操作,但实际运行中发现每日开盘后并未实现重置需求,咨询一下是哪里出了问题?

OnBar(ArrayRef<Integer> indexs)
	{
		//--- 判断是否新交易日 ---
    	IsNewDay = Date != Date[1];
    
    	//--- 新交易日重置累计值 ---
    	If (IsNewDay)
    	{
        	CumulativePV = 0;
        	CumulativeVol = 0;
        	CumulativeVar = 0;
    	}

关于跨周期控制变量失效的问题
模拟交易账户重置
关于取指定日期交易日 或者某月交易日
算法代理失效问题?
上一个交易日的问题
程序化模型失效的风险
请教老师几个问题(信号重置、利润计算)
怎样判断1分钟周期新的BAR开始
交易日志里日期不同的问题
关于一个跨周期的新均线交叉的显示问题

焦煤是有夜盘的。夜盘第一根k线,自然日期跟前一根是一致的。

你这个判断方法只能判断没有夜盘的品种

通用方法应该用truedate判断

好的,谢谢

调整之后还是不太对,要麻烦您再帮忙看看

Params
	//此处添加参数
	Numeric StdDevMultiplier(2.0);  // 标准差倍数(默认2.0)
    Numeric TimeFrame(225);        // 分钟周期(默认日线),按照商品交易分钟数填写

Vars
	//此处添加变量
	Series<Numeric> CumulativePV;     // 累计价格×成交量
    Series<Numeric> CumulativeVol;    // 累计成交量
    Series<Numeric> CumulativeVar;    // 累计方差((TypicalPrice - VWAP)^2 × Volume)
    Series<Numeric> VWAP_Value;       // VWAP值
    Series<Numeric> StdDev;           // 标准差
    Series<Numeric> UpperBand;        // 上轨
    Series<Numeric> LowerBand;        // 下轨
    Series<Numeric> UpperBand2;        // 上轨
    Series<Numeric> LowerBand2;        // 下轨
    Bool IsNewDay;                    // 判断是否新交易日

Defs
	//此处添加公式函数
	
Events
	//此处实现事件函数
	
	//初始化事件函数,策略运行期间,首先运行且只有一次
	OnInit()
	{
		
	}


	//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
	OnBar(ArrayRef<Integer> indexs)
	{
		//--- 判断是否新交易日 ---
    	IsNewDay =  truedate(0)!= truedate(1);
    
    	//--- 新交易日重置累计值 ---
    	If (IsNewDay)
    	{
        	CumulativePV = 0;
        	CumulativeVol = 0;
        	CumulativeVar = 0;
    	}
    
    	//--- 计算典型价格 ---
    	Numeric TypicalPrice = (High + Low + Close) / 3;
    
    	//--- 更新累计价格×成交量 ---
    	CumulativePV = CumulativePV[1] + TypicalPrice * Vol;
    	CumulativeVol = CumulativeVol[1] + Vol;
    
    	//--- 计算VWAP ---
    	If (CumulativeVol > 0) 
    	{
        VWAP_Value = CumulativePV / CumulativeVol;
    	} 
    	Else 
    	{
        VWAP_Value = VWAP_Value[1];
	    }
    
    	//--- 计算累计方差 ---
   		If (CumulativeVol > 0) 
   		{
        Numeric Deviation = TypicalPrice - VWAP_Value;
        CumulativeVar = CumulativeVar[1] + (Deviation * Deviation) * Vol;
        
        // 计算标准差
        StdDev = Sqrt(CumulativeVar / CumulativeVol);
        UpperBand = VWAP_Value + StdDev;
        LowerBand = VWAP_Value - StdDev;
        UpperBand2 = VWAP_Value + StdDevMultiplier * StdDev;
        LowerBand2 = VWAP_Value - StdDevMultiplier * StdDev;
    	} 
    	Else 
    	{
        // 无成交量时沿用前值
        StdDev = StdDev[1];
        UpperBand = UpperBand[1];
        LowerBand = LowerBand[1];
        UpperBand2 = UpperBand2[1];
        LowerBand2 = LowerBand2[1];
  	    }
    
  	    //--- 绘制线形 ---
    	PlotNumeric("VWAP", VWAP_Value);
    	PlotNumeric("Upper Band", UpperBand);
    	PlotNumeric("Lower Band", LowerBand);
    	PlotNumeric("Upper Band2", UpperBand2);
    	PlotNumeric("Lower Band2", LowerBand2);

	}


我也试了苹果这类无夜盘的品种,显示还是不太对


哪里不对了?

21点这不是全都重置为0了嘛?

了解,谢谢

试了一下 除了 date应该改为truedate外,其他应该没啥问题

truedate是函数,回溯用() ,即  IsNewDay =  truedate(0)!= truedate(1);  

如果还是有问题,那就在没有发出的代码里


好的,谢谢


调整之后还是不太对,要麻烦您再帮忙看看

Params
	//此处添加参数
	Numeric StdDevMultiplier(2.0);  // 标准差倍数(默认2.0)
    Numeric TimeFrame(225);        // 分钟周期(默认日线),按照商品交易分钟数填写

Vars
	//此处添加变量
	Series<Numeric> CumulativePV;     // 累计价格×成交量
    Series<Numeric> CumulativeVol;    // 累计成交量
    Series<Numeric> CumulativeVar;    // 累计方差((TypicalPrice - VWAP)^2 × Volume)
    Series<Numeric> VWAP_Value;       // VWAP值
    Series<Numeric> StdDev;           // 标准差
    Series<Numeric> UpperBand;        // 上轨
    Series<Numeric> LowerBand;        // 下轨
    Series<Numeric> UpperBand2;        // 上轨
    Series<Numeric> LowerBand2;        // 下轨
    Bool IsNewDay;                    // 判断是否新交易日

Defs
	//此处添加公式函数
	
Events
	//此处实现事件函数
	
	//初始化事件函数,策略运行期间,首先运行且只有一次
	OnInit()
	{
		
	}


	//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
	OnBar(ArrayRef<Integer> indexs)
	{
		//--- 判断是否新交易日 ---
    	IsNewDay =  truedate(0)!= truedate(1);
    
    	//--- 新交易日重置累计值 ---
    	If (IsNewDay)
    	{
        	CumulativePV = 0;
        	CumulativeVol = 0;
        	CumulativeVar = 0;
    	}
    
    	//--- 计算典型价格 ---
    	Numeric TypicalPrice = (High + Low + Close) / 3;
    
    	//--- 更新累计价格×成交量 ---
    	CumulativePV = CumulativePV[1] + TypicalPrice * Vol;
    	CumulativeVol = CumulativeVol[1] + Vol;
    
    	//--- 计算VWAP ---
    	If (CumulativeVol > 0) 
    	{
        VWAP_Value = CumulativePV / CumulativeVol;
    	} 
    	Else 
    	{
        VWAP_Value = VWAP_Value[1];
	    }
    
    	//--- 计算累计方差 ---
   		If (CumulativeVol > 0) 
   		{
        Numeric Deviation = TypicalPrice - VWAP_Value;
        CumulativeVar = CumulativeVar[1] + (Deviation * Deviation) * Vol;
        
        // 计算标准差
        StdDev = Sqrt(CumulativeVar / CumulativeVol);
        UpperBand = VWAP_Value + StdDev;
        LowerBand = VWAP_Value - StdDev;
        UpperBand2 = VWAP_Value + StdDevMultiplier * StdDev;
        LowerBand2 = VWAP_Value - StdDevMultiplier * StdDev;
    	} 
    	Else 
    	{
        // 无成交量时沿用前值
        StdDev = StdDev[1];
        UpperBand = UpperBand[1];
        LowerBand = LowerBand[1];
        UpperBand2 = UpperBand2[1];
        LowerBand2 = LowerBand2[1];
  	    }
    
  	    //--- 绘制线形 ---
    	PlotNumeric("VWAP", VWAP_Value);
    	PlotNumeric("Upper Band", UpperBand);
    	PlotNumeric("Lower Band", LowerBand);
    	PlotNumeric("Upper Band2", UpperBand2);
    	PlotNumeric("Lower Band2", LowerBand2);

	}


我也试了苹果这类无夜盘的品种,显示还是不太对

你的代码明显可置0, 你问了这么多问题,但最简单的输出调试都没写

我认为没有基础的情况下,靠AI是没什么前途的

可能是我稍微有一点没有表达清楚,在操作上我是希望离散点在每天早上9:00重新离散。我再研究一下。