求大神看看跨周期使用是那個地方出現(xiàn)了問題!
作者:開拓者 TB 來源:cxh99.com 發(fā)布時間:2016年02月18日
- 咨詢內(nèi)容:
代碼如下:
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、我要調(diào)用的就是上面的D1的值。
3、在1小時中執(zhí)行的代碼是這樣的
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、為什么調(diào)用的結(jié)果卻老是不對,這問題糾結(jié)我快半個月了。救大神幫我解決解決!
- TB技術(shù)人員:
本帖最后由 Allin9999 于 2015-12-8 20:39 編輯
我不知道你具體是什么調(diào)用結(jié)果不對,粗略看了一下代碼,至少有2個問題:
(1) 寫入文件和從文件中讀取的代碼沒有完全對應(yīng)。
日線寫入到文件的代碼是:SetTBProfileString2File("f:\\r.log",Symbol,"1and2:"+strkeydate,Text(D1));
小時從文件中讀取的代碼是:dayvalue1=GetTBProfileString2File("f:\\r.log","if000","1and2"+strkeydate);
寫入時,塊名是Symbol,讀取時的塊名變成了具體的"if000",這樣的公式只適合if000一個品種。
然后是鍵名,讀取的代碼少了冒號,"1and2:",這可能是你調(diào)用不到的主要原因。
(2)存在未來數(shù)據(jù)調(diào)用,主要是這一段代碼沒寫對
If(date!=date[1])
strkeydate=DateToString(Date);
Else
strkeydate=strkeydate[1];
正確的寫法應(yīng)該是:
If(date!=date[1])
strkeydate=DateToString(Date[1]);
Else
strkeydate=strkeydate[1];
否則的話,你9點-10點那根小時線可能會讀到當(dāng)天收盤后的日線數(shù)據(jù)
- TB客服:
Allin9999 發(fā)表于 2015-12-8 20:36
我不知道你具體是什么調(diào)用結(jié)果不對,粗略看了一下代碼,至少有2個問題:
(1) 寫入文件和從文件中讀取的代 ...
現(xiàn)在15分鐘上能讀取日線的了,但是1小時的RSI卻讀不出來,檢查了幾遍,不知道問題在那里。現(xiàn)在的代碼是這樣的:
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、現(xiàn)在15分鐘上可以顯示和日線上一樣的線,但是1小時的RSI卻讀不出來。代碼檢查了幾遍不知道問題出在那里。
- 網(wǎng)友回復(fù):
Allin9999 發(fā)表于 2015-12-8 20:36
我不知道你具體是什么調(diào)用結(jié)果不對,粗略看了一下代碼,至少有2個問題:
(1) 寫入文件和從文件中讀取的代 ...
按你說的改成這樣反而和日線上的數(shù)據(jù)不一樣了
If(date!=date[1])
strkeydate=DateToString(Date[1]);
Else
strkeydate=strkeydate[1];
按原來的寫法就和日線的數(shù)據(jù)一樣。現(xiàn)在主要是調(diào)用1小時的RSI,調(diào)不出來
- 網(wǎng)友回復(fù):
xiaokakaren 發(fā)表于 2015-12-9 14:39
按你說的改成這樣反而和日線上的數(shù)據(jù)不一樣了
If(date!=date[1])
strkeydate=DateTo ...
在3#的公式中,如果你的1小時線也要寫入數(shù)據(jù),并由15分鐘線中讀取。
那么1小時的公式中,strkeyhour這個鍵名是需要繼續(xù)存在的。- strkeyhour=DateToString(Date)+":"+Text(hour);
- SetTBProfileString("HRSI","HourRSI:"+strkeyhour,Text(RSIValue));
復(fù)制代碼同時,在15分鐘的也得要聲明strkeyhour,并賦值- strkeyhour=DateToString(Date)+":"+Text(hour);
- //讀取小時線
- Hourvalue=GetTBProfileString("HRSI","HourRSI:"+strkeyhour);
復(fù)制代碼就是這個細節(jié),改過來應(yīng)該就可以取到值了。 |