[請益]兩商品價差的開高低收計算
又來發問了想請問如果我想對兩商品的價格去做價差計算
例如:電子期金融期 5分K
碰到一個問題
價差的OPEN,CLOSE可以順利計算出來
但HIGH,LOW無法
直觀上會想說直接用電子HIGH減金融HIGH
計算出來的值只是表示這五分鐘裡面電子最高價與金融最高價的相差而已
電子最高價與金融最高價發生時間可能不一樣 (一個在03"00一個在04"50)
但這沒啥意義
除非用TICK BY TICK 去計算才是最正確的
但礙於計算速度和及時下單
所以我想計算每分鐘的電金最高價價差SPREAD_H_in1min
套到五分鐘頻率看這五根最高的SPREAD_H_in1min當作五分鐘的SPREAD_H_in5min
AB字典中的timeset系列似乎是解答
但這塊我比較陌生 想請問各位前輩可否指點
謝謝
假設用一個數列 X=Y(電子期)-Z(金融)則 用X來畫K線即可{:4_93:} moneymaker 發表於 12-11-1 19:16 static/image/common/back.gif
假設用一個數列 X=Y(電子期)-Z(金融)則 用X來畫K線即可
sp_c=0;
for( i = 1; i < BarCount; i++ )
{
sp_c=AA/BB;
}
大大意思是上面這樣吧...
不過...還是畫不出我要的開高低收蠟燭線
本帖最後由 joshsmi 於 12-11-2 00:36 編輯
@Zhack,
not sure if this is what you are looking forName_ = Name();
Ticker1 = ParamStr( "Symbol 1", Name_ );
Ticker2 = ParamStr( "Symbol 2", Name_ );
SetForeign( Ticker1 );
Open1 = O;
High1 = H;
Low1 = L;
Close1= C;
RestorePriceArrays();
SetForeign( Ticker2 );
Open2 = O;
High2 = H;
Low2 = L;
Close2= C;
RestorePriceArrays();
SpreadO = Open1 / Open2;
SpreadH = High1 / High2;
SpreadL = Low1 / Low2;
SpreadC = Close1 / Close2;
GraphXSpace = Param( "Stretch/Compress Chart", 5, -50, 100, 1 );
SetChartOptions( 0, chartShowArrows | chartShowDates );
//Plot(SpreadC, "Spread - Ratio", ParamColor("Color", colorCycle ), styleLine );
PlotOHLC( 1.0*SpreadO, 1.0* SpreadH , 1.0* SpreadL, 1.0* SpreadC, "Spread - Ratio", ParamColor( "Color", colorGrey40 ), styleCandle );
http://img542.imageshack.us/img542/6691/spread.png
http://img811.imageshack.us/img811/6691/spread.png
本帖最後由 joshsmi 於 12-11-2 01:01 編輯
Spread-Ratio Version 1.1function Maxarray( array1, array2, array3, array4 )
{
Maxarray1 = Max( array1, array2 );
Maxarray2 = Max( array3, Maxarray1 );
Maxarray3 = Max( array4, Maxarray2 );
return Maxarray3;
}
function Minarray( array1, array2, array3, array4 )
{
Minarray1 = Min( array1, array2 );
Minarray2 = Min( array3, Minarray1 );
Minarray3 = Min( array4, Minarray2 );
return Minarray3;
}
Name_ = Name();
Ticker1 = ParamStr( "Symbol 1", Name_ );
Ticker2 = ParamStr( "Symbol 2", Name_ );
SetForeign( Ticker1 );
Open1 = O;
High1 = H;
Low1 = L;
Close1= C;
RestorePriceArrays();
SetForeign( Ticker2 );
Open2 = O;
High2 = H;
Low2 = L;
Close2= C;
RestorePriceArrays();
SpreadO = Open1 / Open2;
SpreadH = High1 / High2;
SpreadL = Low1 / Low2;
SpreadC = Close1 / Close2;
SpreadH = Maxarray( SpreadO, SpreadH, SpreadL, SpreadC );
SpreadL = Minarray( SpreadO, SpreadH, SpreadL, SpreadC );
GraphXSpace = Param( "Stretch/Compress Chart", 5, -50, 100, 1 );
SetChartOptions( 0, chartShowArrows | chartShowDates );
//Plot(SpreadC, "Spread - Ratio", ParamColor("Color", colorCycle ), styleLine );
PlotOHLC( 1.0 * SpreadO, 1.0 * SpreadH, 1.0 * SpreadL, 1.0 * SpreadC, "", ParamColor( "Color of Price (Out-)Line", colorGrey40 ), styleCandle );
Coltitle = ParamColor( "Color Of Title font", colorLightGrey );
_N( Title = StrFormat( EncodeColor( Coltitle ) + "{{NAME}} - " + EncodeColor( colorRed ) + "Spread-Ratio" + EncodeColor( Coltitle ) +
" - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", SpreadO, SpreadH, SpreadL, SpreadC, SelectedValue( ROC( SpreadC, 1 ) ) ) ); Name_ = Name();
Ticker1 = ParamStr( "Symbol 1", Name_ );
Ticker2 = ParamStr( "Symbol 2", Name_ );
SetForeign( Ticker1 );
Open1 = O;
High1 = H;
Low1 = L;
Close1= C;
RestorePriceArrays();
SetForeign( Ticker2 );
Open2 = O;
High2 = H;
Low2 = L;
Close2= C;
RestorePriceArrays();
SpreadO = Open1 - Open2;
SpreadH = High1 - Low2;
SpreadL = Low1 - High2;
SpreadC = Close1 - Close2;
GraphXSpace = Param( "Stretch/Compress Chart", 5, -50, 100, 1 );
SetChartOptions( 0, chartShowArrows | chartShowDates );
//Plot(SpreadC, "Spread - Diff", ParamColor("Color", colorCycle ), styleLine );
PlotOHLC( SpreadO, SpreadH , SpreadL, SpreadC, "Spread - Diff", ParamColor( "Color", colorGrey40 ), styleCandle ); 感謝兩位的解答
Tanks for your answers
但還是無法解決我的問題 (因為沒有考慮到最高最低價發生的時間是否一致)
But still can't solve my problem (Because without considering the prices of HIGH &LOW happen in the same moment or not)
我把跑出來的數據貼給你們看
Following is the outcome of your answer
30M O H L C
10:30 867 907 531 644
10M O H L C
10:10 867 907 861 861
10:20 865 875 525 658
10:30 573 658 557 644
5M O H L C
10:05 867 915 867 915
10:10 913 940 861 861
10:15 865 875 762 763
10:20 763 763 525 658
10:25 573 658 557 641
10:30 657 665 574 644
我想找出30分k的價差(比率)開高低收
但30分k跑出來的HIGH是907,LOW是531
我把頻率調成10分鐘
HIGH最高是907,LOW最低是525
如果把頻率又下調到5M
HIGH最高是940,LOW最低是525
所以我只是把30分鐘的HIGH,LOW算出來
卻不是最低頻率的1M的HIGH,LOW
下方是我希望寫出來的目標
30M O H L C
10:30 867 915 573 644
10M O H L C
10:10 867 867 861 861
10:20 865 865 658 658
10:30 573 644 573 644
5M O H L C
10:05 867 915 867 915
10:10 913 913 861 861
10:15 865 865 763 763
10:20 763 763 658 658
10:25 573 641 573 641
10:30 657 657 644 644
我替換掉5m的HIGH_in5min=MAX(OPEN_in5min,CLOSE_in5min)
LOW_in5min=Min(OPEN_in5min,CLOSE_in5min)
然後連續觀察6根
把30m的HIGH,LOW替換成最小頻率(這邊用5M,但我希望是1M)
的HHV(HIGH_in5min,6) LLV(LOW_in5min,6)
有點複雜 對價差而言一般都僅考慮兩個商品的成交價畫成一條線.. 所以上面為了要畫k線 只好以簡單的方式,最大可能的區間 做為高和低 {:4_186:} moneymaker 發表於 12-11-2 12:47 static/image/common/back.gif
所以上面為了要畫k線 只好以簡單的方式,最大可能的區間 做為高和低...
謝謝
我懂這個的難處
不然我也不會上來這裡問了
難道無法收集一分鐘的資訊
拿來當五分鐘,30分鐘,的高低價位嗎
ZHACK 發表於 12-11-2 13:14 static/image/common/back.gif
謝謝
我懂這個的難處
不然我也不會上來這裡問了
TimeFrame 限制如下,
Please note that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.
------
假設您是跑 15分 圖,是無法透過 TimeFrameSet 取得小於 15分 週期的資訊的。
可以換個角度思考看看說不定有解喔!
頁:
[1]