求大神看看跨周期使用是那个地方出现了问题! [开拓者 TB]
- 咨询内容:
代码如下:
1、我在日线上插入的是
Vars
string strkeydate;
Numeric D1;
NumericSeries short1;
NumericSeries short2;
NumericSeries media1;
NumericSeries media2;
NumericSeries long1;
NumericSeries long2;
Begin
short1=(xaverage(Close,4)+average(Close,8)+average(Close,16))/3;
short2=(xaverage(Close,6)+average(Close,12)+average(Close,24))/3;
media1=(xaverage(Close,9)+average(Close,18)+average(Close,36))/3;
media2=(xaverage(Close,13)+average(Close,26)+average(Close,52))/3;
long1=(xaverage(Close,18)+average(Close,36)+average(Close,72))/3;
long2=(xaverage(Close,24)+average(Close,48)+average(Close,96))/3;
PlotNumeric("short1",short1,0,white);
PlotNumeric("short2",short2,0,DarkMagenta);
PlotNumeric("media1",media1,0,Blue);
PlotNumeric("media2",media2,0,Green);
PlotNumeric("long1",long1,0,Yellow);
PlotNumeric("long2",long2,0,Red);
if(MarketPosition<>1&&short1[1] > short2[1] and short2[1] > media1[1] and media1[1] > media2[1] and media2[1] > long1[1] and long1[1] > long2[1])
{
D1=1;
}
if(MarketPosition<>1&&short1[1] < short2[1] and short2[1] < media1[1] and media1[1] < media2[1] and media2[1] < long1[1] and long1[1] < long2[1])
{
D1=2;
}
strkeydate = DateToString(Date);
SetTBProfileString2File("f:\\r.log",Symbol,"1and2:"+strkeydate,Text(D1));
PlotNumeric("1and2",D1);
End
2、我要调用的就是上面的D1的值。
3、在1小时中执行的代码是这样的
Params
Numeric Length(14) ;
Numeric OverSold(30) ;
Numeric OverBought(70) ;
Vars
NumericSeries NetChgAvg( 0 );
NumericSeries TotChgAvg( 0 );
Numeric SF( 0 );
Numeric Change( 0 );
Numeric ChgRatio( 0 ) ;
Numeric RSIValue;
StringSeries strkeydate;
StringSeries strkeyhour;
String dayvalue1;
NumericSeries H1;
Numeric HH;
Begin
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 ;
}
RSIValue = 50 * ( ChgRatio + 1 );
PlotNumeric("RSI",RSIValue);
PlotNumeric("超买",OverBought);
PlotNumeric("超卖",OverSold);
If(date!=date[1])
strkeydate=DateToString(Date);
Else
strkeydate=strkeydate[1];
If(Hour!=Hour[1])
strkeyhour=DateToString(Date)+":"+Text(Hour);
Else
strkeyhour=strkeyhour[1];
dayvalue1=GetTBProfileString2File("f:\\r.log","if000","1and2"+strkeydate);
H1 = Value(dayvalue1);
If(RSIValue>70)
{
If(H1==2)
{
HH=2;
}
}
If(RSIValue<30)
{
If(H1==1)
{
HH=1;
}
}
SetTBProfileString2File("f:\\0.log",Symbol,"1and2:"+strkeyhour,Text(HH));
End
4、为什么调用的结果却老是不对,这问题纠结我快半个月了。救大神帮我解决解决! - TB技术人员:
本帖最后由 Allin9999 于 2015-12-8 20:39 编辑
我不知道你具体是什么调用结果不对,粗略看了一下代码,至少有2个问题:
(1) 写入文件和从文件中读取的代码没有完全对应。
日线写入到文件的代码是:SetTBProfileString2File("f:\\r.log",Symbol,"1and2:"+strkeydate,Text(D1));
小时从文件中读取的代码是:dayvalue1=GetTBProfileString2File("f:\\r.log","if000","1and2"+strkeydate);
写入时,块名是Symbol,读取时的块名变成了具体的"if000",这样的公式只适合if000一个品种。
然后是键名,读取的代码少了冒号,"1and2:",这可能是你调用不到的主要原因。
(2)存在未来数据调用,主要是这一段代码没写对
If(date!=date[1])
strkeydate=DateToString(Date);
Else
strkeydate=strkeydate[1];
正确的写法应该是:
If(date!=date[1])
strkeydate=DateToString(Date[1]);
Else
strkeydate=strkeydate[1];
否则的话,你9点-10点那根小时线可能会读到当天收盘后的日线数据
- TB客服:
Allin9999 发表于 2015-12-8 20:36
我不知道你具体是什么调用结果不对,粗略看了一下代码,至少有2个问题:
(1) 写入文件和从文件中读取的代 ...
现在15分钟上能读取日线的了,但是1小时的RSI却读不出来,检查了几遍,不知道问题在那里。现在的代码是这样的:
1、日线插入代码
Vars
string strkeydate;
NumericSeries pubu1;
NumericSeries pubu2;
NumericSeries pubu3;
NumericSeries pubu4;
NumericSeries pubu5;
NumericSeries pubu6;
Begin
pubu1=(xaverage(Close,4)+average(Close,8)+average(Close,16))/3;
pubu2=(xaverage(Close,6)+average(Close,12)+average(Close,24))/3;
pubu3=(xaverage(Close,9)+average(Close,18)+average(Close,36))/3;
pubu4=(xaverage(Close,13)+average(Close,26)+average(Close,52))/3;
pubu5=(xaverage(Close,18)+average(Close,36)+average(Close,72))/3;
pubu6=(xaverage(Close,24)+average(Close,48)+average(Close,96))/3;
strkeydate=DateToString(Date);
SetTBProfileString("daypubu","daypubu1:"+strkeydate,Text(pubu1));
SetTBProfileString("daypubu","daypubu2:"+strkeydate,Text(pubu2));
SetTBProfileString("daypubu","daypubu3:"+strkeydate,Text(pubu3));
SetTBProfileString("daypubu","daypubu4:"+strkeydate,Text(pubu4));
SetTBProfileString("daypubu","daypubu5:"+strkeydate,Text(pubu5));
SetTBProfileString("daypubu","daypubu6:"+strkeydate,Text(pubu6));
PlotNumeric("pubu1",pubu1,0,white);
PlotNumeric("pubu2",pubu2,0,DarkMagenta);
PlotNumeric("pubu3",pubu3,0,Blue);
PlotNumeric("pubu4",pubu4,0,Green);
PlotNumeric("pubu5",pubu5,0,Yellow);
PlotNumeric("pubu6",pubu6,0,Red);
End
2、1小时插入代码
Params
Numeric Length(14) ;
Numeric OverSold(30) ;
Numeric OverBought(70) ;
Vars
NumericSeries NetChgAvg( 0 );
NumericSeries TotChgAvg( 0 );
Numeric SF( 0 );
Numeric Change( 0 );
Numeric ChgRatio( 0 ) ;
Numeric RSIValue;
StringSeries strkeydate;
Begin
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 ;
}
RSIValue = 50 * ( ChgRatio + 1 );
strkeydate=DateToString(Date)+":"+Text(hour);
SetTBProfileString("HRSI","HourRSI:"+strkeydate,Text(RSIValue));
PlotNumeric("HourRSI",RSIValue);
PlotNumeric("超买",OverBought);
PlotNumeric("超卖",OverSold);
End
3、15分钟插入代码
Vars
NumericSeries Daypubu1;
NumericSeries Daypubu2;
NumericSeries Daypubu3;
NumericSeries Daypubu4;
NumericSeries Daypubu5;
NumericSeries Daypubu6;
NumericSeries HourRSI;
StringSeries strkeydate;
StringSeries strkeyhour;
String dayvalue1;
String dayvalue2;
String dayvalue3;
String dayvalue4;
String dayvalue5;
String dayvalue6;
String Hourvalue;
Begin
If(Date!=Date[1])
strkeydate=DateToString(Date);
Else
strkeydate=strkeydate[1];
If(Hour!=Hour[1])
strkeyhour=DateToString(Date)+":"+Text(Hour);
Else
strkeyhour=strkeyhour[1];
//读取日线
dayvalue1=GetTBProfileString("daypubu","daypubu1:"+strkeydate);
dayvalue2=GetTBProfileString("daypubu","daypubu2:"+strkeydate);
dayvalue3=GetTBProfileString("daypubu","daypubu3:"+strkeydate);
dayvalue4=GetTBProfileString("daypubu","daypubu4:"+strkeydate);
dayvalue5=GetTBProfileString("daypubu","daypubu5:"+strkeydate);
dayvalue6=GetTBProfileString("daypubu","daypubu6:"+strkeydate);
//读取小时线
Hourvalue=GetTBProfileString("HRSI","HourRSI:"+strkeydate);
Daypubu1=Value(dayvalue1);
Daypubu2=Value(dayvalue2);
Daypubu3=Value(dayvalue3);
Daypubu4=Value(dayvalue4);
Daypubu5=Value(dayvalue5);
Daypubu6=Value(dayvalue6);
HourRSI=Value(Hourvalue);
PlotNumeric("Dpb1",Daypubu1,0,white);
PlotNumeric("Dpb2",Daypubu2,0,DarkMagenta);
PlotNumeric("Dpb3",Daypubu3,0,Blue);
PlotNumeric("Dpb4",Daypubu4,0,Green);
PlotNumeric("Dpb5",Daypubu5,0,Yellow);
PlotNumeric("Dpb6",Daypubu6,0,Red);
PlotNumeric("HRSI",HourRSI);
End
4、现在15分钟上可以显示和日线上一样的线,但是1小时的RSI却读不出来。代码检查了几遍不知道问题出在那里。 - 网友回复:
Allin9999 发表于 2015-12-8 20:36
我不知道你具体是什么调用结果不对,粗略看了一下代码,至少有2个问题:
(1) 写入文件和从文件中读取的代 ...
按你说的改成这样反而和日线上的数据不一样了
If(date!=date[1])
strkeydate=DateToString(Date[1]);
Else
strkeydate=strkeydate[1];
按原来的写法就和日线的数据一样。现在主要是调用1小时的RSI,调不出来 - 网友回复:
xiaokakaren 发表于 2015-12-9 14:39
按你说的改成这样反而和日线上的数据不一样了
If(date!=date[1])
strkeydate=DateTo ...
在3#的公式中,如果你的1小时线也要写入数据,并由15分钟线中读取。
那么1小时的公式中,strkeyhour这个键名是需要继续存在的。- strkeyhour=DateToString(Date)+":"+Text(hour);
- SetTBProfileString("HRSI","HourRSI:"+strkeyhour,Text(RSIValue));
- strkeyhour=DateToString(Date)+":"+Text(hour);
- //读取小时线
- Hourvalue=GetTBProfileString("HRSI","HourRSI:"+strkeyhour);
- strkeyhour=DateToString(Date)+":"+Text(hour);
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容