老师, 我使用如下代码,进行跨工作区调用TBF000 RSI日线数据的数据。发现调用的数据不是程序中设计的数据(上一个交易日的RRSI),调用工作区是15分钟周期,不知道哪里除了问题。其它多个具体的合约共同调用这个数据,各个合约调用出来的数据也不同,有些是三天前的,有些还是5天前的,很乱。
日线RSI工作区公式
//------------------------------------------------------------------------
// 简称: proRSI
// 名称:
// 类别: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
Params
Numeric Length(14) ; //周期
Numeric OverSold(300000) ; //超卖 30 乘以10000
Numeric OverBought(700000) ; //超买 70 乘以10000
Vars
Series<Numeric> NetChgAvg( 0 );
Series<Numeric> TotChgAvg( 0 );
Numeric SF( 0 );
Numeric Change( 0 );
Numeric ChgRatio( 0 ) ;
Numeric RSIValue;
Numeric BigIndexRSIValue;
string strkeyBigIndexRSI;//时间
string strValueBigIndexRSI;
Numeric BigTT888;
string strkeyBigTT888;//时间
string strValueBigTT888;
Events
OnBar(ArrayRef<Integer> indexs)
{
If(CurrentBar <= Length - 1)
{
NetChgAvg = ( Close - Close[Length] ) / Length ;
TotChgAvg = Average( Abs( Close - Close[1] ), Length ) ;
}Else
{
SF = 1/Length;
Change = Close - Close[1] ;
NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;
}
If( TotChgAvg <> 0 )
{
ChgRatio = NetChgAvg / TotChgAvg;
}else
{
ChgRatio = 0 ;
}
//TT888 = round(10000*50 * ( ChgRatio + 1 ),0);
BigIndexRSIValue = round(10000*50 * ( ChgRatio + 1 ),0);
PlotNumeric(\"RSI\",BigIndexRSIValue);
PlotNumeric(\"超买\",OverBought);
PlotNumeric(\"超卖\",OverSold);
///////////////////////////////////////////////////////////////////////
// strKeyTT888 = DateToString(trueDate(0));
//strValueTT888 = Text(TT888);
//SetTBProfileString(text(888*nkk), strKeyTT888,strKeyTT888);
strKeyBigIndexRSI = DateToString(trueDate(0));
strValueBigIndexRSI = Text(BigIndexRSIValue);
SetTBProfileString(\"BigIndexRSIValue\",strkeyBigIndexRSI,strValueBigIndexRSI);
Commentary(\"BigIndexRSIValue=\"+Text(BigIndexRSIValue));
使用工作区调用的公式如下(15分钟周期)
var
series<Numeric> BigIndexRSIValue;
Series<string> strkeyBigIndexRSI;//时间
string strValueBigIndexRSI;
Events
OnBar(ArrayRef<Integer> indexs)
{
If(trueDate(0)!=trueDate(1) and time!=time[1])
{
strKeyBigindexRSI = DateToString(trueDate(1));
}Else
{
strKeyBigindexRSI = strKeyBigindexRSI[1];
}
strValueBigIndexRSI = GetTBProfileString(\"BigIndexRSIValue\",strkeyBigIndexRSI);
If(strValueBigIndexRSI != InvalidString)
{
BigIndexRSIValue = Value(strValueBigIndexRSI);
}Else
{
BigIndexRSIValue = BigIndexRSIValue[1];
}
Commentary(\"BigIndexRSIValue = \"+text(BigIndexRSIValue));
}
用基础数据的方式 不要用这种SetTBProfileString