台指日夜盤 繪圖指標設定

  •   526 
  • 最後發表   JC  2022 三月 30
JC 發文於   2022/03/18

Hi 小幫手您好:
參考了討論區的文章,我有寫了一個關於台指日盤的CDP繪圖指標,日盤經過測試後沒有太大問題,於是想把這個指標延伸到台指夜盤上面使用。
但是如果用在夜盤,夜盤的CDP運算數值會產生錯誤,與走勢圖內的CDP相去甚遠。
請教一下是否有機會把日盤與夜盤整合在一起,還是建議日盤與夜盤分開呢?
程式碼如下:

settotalbar(2000);
var:CDP(0),AH(0),AL(0),NH(0),NL(0);
if barfreq <> "Min" then raiseruntimeerror("請運行在分鐘頻率上 (最好是1分鐘)");
value1=xfMin_GetValue("5",high,0); 
value2=xfMin_GetValue("5",low,0);
value3=xfMin_GetValue("5",closeD(1),0);
value4=xfMin_GetValue("5",open,0); 

//均價線
Value5 = GetField("AvgPrice");
CDP = (getfield("High", "D")[1] + getfield("Low", "D")[1] + getfield("Close", "D")[1] * 2) / 4;
AH = CDP + (getfield("High", "D")[1] - getfield("Low", "D")[1]);
AL = CDP - (getfield("High", "D")[1] - getfield("Low", "D")[1]);
NH = 2 * CDP  - getfield("Low", "D")[1];
NL = 2 * CDP  - getfield("High", "D")[1];

Plot1(AH,"AH");
Plot2(NH,"NH");
Plot3(CDP,"CDP");
Plot4(NH,"NH");
Plot5(NL,"NL");
Plot6(Value5,"均價線");

 

//====== 日盤 ==========================
if time>=084500 and time<=084959 then
value11=simplehighest(value1,1);
if time>=084500 and time<=084959 then
value12=SimpleLowest(value2,1);
if time>=084500 and time<=134459 then
value13=SimpleLowest(value3,1);
if time>=084500 and time<=084959 then
value14=value4;

if time>=084500 and time<134059 then
plot11(value11,"日開高") else noplot(1);

if time>=084500 and time<134059 then
plot12(value12,"日開低") else noplot(1);

if time>=084500 and time<134059 then
plot13(value13,"日盤昨收") else noplot(1);

if time>=084500 and time<134059 then
plot14(value14,"日開盤") else noplot(1);

//====== 夜盤 ==========================
if time>=150000 and time<=150459 then
value21=simplehighest(value1,1);

if time>=150000 and time<=150459 then
value22=SimpleLowest(value2,1);

if time>=150000 and time<=045959 then
value23=SimpleLowest(value3,1);

if time>=150000 and time<=150459 then
value24=value4;

if time>=150000 and time<045959  then
plot21(value21,"夜開高") else noplot(1);

if time>=150000 and time<045959 then
plot22(value22,"夜開低") else noplot(1);

if time>=150000 and time<045959 then
plot23(value23,"夜盤收") else noplot(1);

if time>=150000 and time<045959 then
plot24(value24,"夜開盤") else noplot(1);

 

排序方式: 標準 | 最新
XQ小幫手 發文於   2022/03/23

Hello JC,

 

小幫手測試比較CDP的部分,兩者是相同的。(參考附圖)

需注意您附上的腳本plot4和plot5有錯,應該為:

Plot4(NL,"NL");

Plot5(AL,"AL");

不然您的plot4其實跟plot2相同。

 

另外您夜盤部份的時間限制應該為 time >= 150000 or time <=045900,而不是and。

因為沒有時間會同時比下午3點晚但又比早上五點早。

 

小幫手無法理解您這一段想做什麼?

value1=xfMin_GetValue("5",high,0); 

value2=xfMin_GetValue("5",low,0);

value3=xfMin_GetValue("5",closeD(1),0);

value4=xfMin_GetValue("5",open,0); 

如果是要跨頻率取值的話,直接使用 GetField 就可以了。

像是 getfield("High", "5") 就會是5分鐘頻率的高。

附加文件

JC 發文於   2022/03/24

Hi 小幫手
謝謝您的協助。我的想法是
value1=xfMin_GetValue("5",high,0);  // 畫出開盤5分K第1根最高點一直到日盤結束,再從夜盤第一根K棒開始畫
value2=xfMin_GetValue("5",low,0);  //  取得開盤5分K第1根最低點一直到日盤結束,再從夜盤第一根K棒開始畫
value3=xfMin_GetValue("5",closeD(1),0); //取得前一盤收盤價當作參考
((日盤結束-->畫出日盤收盤價給夜盤參考/夜盤
結束-->畫出夜盤收盤價給夜盤參考))
value4=xfMin_GetValue("5",open,0);//畫出開盤5分K第1根開盤價一直到日盤結束,再從夜盤第一根K棒開始畫

再請您協助,感恩。

 

 

XQ小幫手 發文於   2022/03/29

Hello JC,

 

如果是要抓取特定時間的數值的話,小幫手會建議您用時間對位的方式去抓取。

舉例來說,如果您使用在1分鐘頻率上的話:

if time = 084900 or time = 150400 then begin    //日夜開盤第一根5分鐘Bar完成時

    value1 = getfield("High", "5");

    value2 = getfield("Low", "5");

    value3 = getfield("Close", "5")[1];

    value4 = getfield("Open", "5");

    end;

這樣就可以抓到正確資訊。

JC 發文於   2022/03/30

 Hi 小幫手
謝謝你的回覆與建議喔,花了一點時間調整測試後,目前已經達到指標繪圖需求。

發表回覆
Close