想在主圖畫出前兩天大量15分K的開盤價

  •   48 
  • 最後發表   DOMISTAR02  2025 八月 04
DOMISTAR02 發文於   2025/07/30

SetBackBar(300);

 

Vars:

    i(0),

    today(0),

    day1(0), day2(0),          // 前兩個交易日

    maxVol(0), prevOpen(0),

    isComputed(false),         // 是否已經計算過

    currDate(0), barCount(0);

 

// 取得今天日期

today = GetField("Date");

 

// 每根 K 棒進場都判斷

currDate = GetField("Date");

if currDate <> today[1] then begin

    // 新的一天,重置旗標與 count

    isComputed = false;

    barCount = 0;

end;

 

// barCount 計算到第 1 根就觸發計算

barCount = barCount + 1;

if barCount = 1 and not isComputed then begin

    // 1) 找出昨天與前天

    day1 = 0; day2 = 0;

    for i = 1 to 300 begin

        if GetField("Date")[i] < today then begin

            if day1 = 0 then

                day1 = GetField("Date")[i]

            else if day2 = 0 and GetField("Date")[i] <> day1 then

                day2 = GetField("Date")[i];

            if day1 <> 0 and day2 <> 0 then break;

        end;

    end;

 

    // 2) 對這兩天找最大量開盤價

    maxVol = 0; prevOpen = 0;

    for i = 1 to 300 begin

        if GetField("Date")[i] = day1 or GetField("Date")[i] = day2 then begin

            if GetField("Volume")[i] > maxVol then begin

                maxVol = GetField("Volume")[i];

                prevOpen = GetField("Open")[i];

            end;

        end;

    end;

 

    isComputed = true;  // 標記已計算

end;

 

// 3) 畫線:只畫這次計算出的 prevOpen,不再更新

if prevOpen > 0 then

    Plot1(prevOpen, "前兩日最大量開盤價");


我的問題如下
1.我想要主圖畫出前兩天大量15分K的開盤價,也想要能夠顯示在1分K跟5分K
2.我要的只是一條線,不要因為數字起伏就跳動
3.主圖放大縮小他的線會亂跑(如附圖)
4.我要怎麼讓他跳通知 價格碰到

附加文件

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/07/30

XQ是序列語言,邏輯與傳統的程式語言不大一樣。迴圈是沒效率的做法且往往是不必要的。你的需求,只要幾行指令就能搞定。

input:days(2,"N天前");
var: BeginBar(0),EndBar(0);
BeginBar=getBarOffset(GetField("日期", "D")[days],090000);
EndBar=getBarOffset(GetField("日期", "D"),090000)+1;
value1=simplehighestBar(volume[EndBar],BeginBar-EndBar+1);
value2=open[EndBar+value1];
plotline(1,currentBar-BeginBar,value2,currentBar,value2);
setPlotLabel(1,"過去"+numtoStr(days,0)+"天最大量出現在"+numtoStr(datetime[EndBar+value1],0)+"開盤價");

 

XS小編 發文於   2025/08/04

Hello DOMISTAR02,

 

小編補充,如果要讓XQ在條件符合時跳通知的話,您可以使用策略雷達 (警示腳本) 來達成。

 

發表回覆
Close