求問~何處有誤,為何運算後的搜尋值不正確

  •   86 
  • 最後發表   xqyi  2024 七月 12
xqyi 發文於   2024/06/06

setBarBack(500);
Vars: i(0), intrabarpersist  maxLessThanLow(-999999), intrabarpersist minGreaterThanHigh(999999)
,intrabarpersist mTlow(0), intrabarpersist mThigh(0);
Array: values[18](0) ;

values[1] = round(average(getField("收盤價","W"),5),2);
values[2] = round(xf_EMA("w",getField("收盤價","W"),12),2) ;
values[3] = round(xf_EMA("W",getField("收盤價","W"),26),2) ;
values[4] = round(average(getField("收盤價","W"),60),2);
values[5] = round(average(Close,5),2);
values[6] = round(EMA( Close,12),2) ;
values[7] = round(EMA( Close,26),2) ;
values[8] = round(average(Close,60),2);
values[9] = round(high,2);
values[10] = round(close,2);
values[11] = round(low,2);
values[12] = round( bollingerband(Close, 20, 2),2);
values[13] = round(average(close, 20),2);
values[14] = round( bollingerband(Close, 20, -1 * 2),2);
values[15] = round(highest(high,250),2);//百日高
values[16] = round(Lowest(low,250),2);
values[17] = round(highw(0),2);//周高
values[18] = round(Loww(0),2);

For i = 1 to 18 begin
     // 找出大于 high 的最小值 壓力
    if values[i] > highD(0) then begin
        if values[i] < minGreaterThanHigh then
            MThigh = values[i];
    end;

    // 找出小于 low 的最大值 支撐
    if values[i] < lowd(0) then begin
        if values[i] > maxLessThanLow then
            MTlow = values[i];
   end;
end;

Plot1(MThigh, "壓力價");
Plot2(MTlow, "支撐價");
//plot3(第二壓力價) ?
//plot4(第二支撐價) ?

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

程式可以運作,但要說明清楚「運算後的搜尋值不正確」指的是什麼?

xqyi 發文於   2024/06/06

如圖 以2542為例

今高high=47.65 搜尋出的壓力價應高是年高50.0,看似正確,但移到不同K棒就有錯誤

今低low=46.65 應是D5的46.52 但卻是周低的45.45,這個在哪個K棒位置都是錯的 (大部分都是在周低)

虎科大許教授 發文於   2024/06/06

你提供的資訊不完整,很難協助。什麼是D5?你應該在腳本中將陣列的18個元素註解。你只註解百日高及周高,誰看得懂D5是什麼?另外,今低low明明是46.65,怎麼應是D5的46.52?實在看不懂你在表達什麼。

xqyi 發文於   2024/06/06

恩恩

因為是兩個腳本,

上方圖第一個腳本,之前教授協助的,是經過排序的價位。(難度高,我寫不出如何不重複程式碼,加入第二個腳本)

下方圖第二個腳本,是簡要的,只找出符合想要的兩個價位 (但找出來的值有誤)

18個元素加上標註如下 

今低 ->round(low,2);->(價位46.65)

D5(5日均價) ->round(average(Close,5),2); ->(價位46.52)

加註後程式碼如下
原本還要寫第二壓力和第二支撐的價位提醒,但真的想不出該怎麼寫

setBarBack(500);
Vars: i(0), intrabarpersist  maxLessThanLow(-999999), intrabarpersist minGreaterThanHigh(999999)
,intrabarpersist mTlow(0), intrabarpersist mThigh(0);
Array: values[18](0) ;

values[1] = round(average(getField("收盤價","W"),5),2);//W5
values[2] = round(xf_EMA("w",getField("收盤價","W"),12),2) ;//WE12
values[3] = round(xf_EMA("W",getField("收盤價","W"),26),2) ;//WE26
values[4] = round(average(getField("收盤價","W"),60),2);//W60
values[5] = round(average(Close,5),2);//D5
values[6] = round(EMA( Close,12),2) ;//DE12
values[7] = round(EMA( Close,26),2) ;//DE26
values[8] = round(average(Close,60),2);//D60
values[9] = round(high,2);//今高
values[10] = round(close,2);//今收
values[11] = round(low,2);//今低
values[12] = round( bollingerband(Close, 20, 2),2);//布林上
values[13] = round(average(close, 20),2);//布林中
values[14] = round( bollingerband(Close, 20, -1 * 2),2);//布林下
values[15] = round(highest(high,250),2);//年高
values[16] = round(Lowest(low,250),2);//年低
values[17] = round(highw(0),2);//周高
values[18] = round(Loww(0),2);//周低

For i = 1 to 18 begin
     // 找出大于 high 的最小值 壓力1
    if values[i] > high then begin
        if values[i] < minGreaterThanHigh then
            MThigh = values[i];
    end;

    // 找出小于 low 的最大值 支撐1
    if values[i] < low then begin
        if values[i] > maxLessThanLow then
            MTlow = values[i];
   end;
end;

Plot1(MThigh, "壓力1價位");
Plot2(MTlow, "支撐1價位");


虎科大許教授 發文於   2024/06/06

setBarBack(500);

var:i(0);

array: Arr[18,2](0);

array: strArr[18]("");

 

arr[1,1]=round(average(getField("收盤價","W"),5),2);//W5

arr[2,1]=round(xf_EMA("w",getField("收盤價","W"),12),2) ;//WE12

arr[3,1]=round(xf_EMA("W",getField("收盤價","W"),26),2) ;//WE26

arr[4,1]=round(average(getField("收盤價","W"),60),2);//W60

arr[5,1]=round(average(Close,5),2);//D5

arr[6,1]=round(EMA( Close,12),2) ;//DE12

arr[7,1]=round(EMA( Close,26),2) ;//DE26

arr[8,1]=round(average(Close,60),2);//D60

arr[9,1]=round(high,2);//今高

arr[10,1]=round(close,2);//今收

arr[11,1]=round(low,2);//今低

arr[12,1]=round( bollingerband(Close, 20, 2),2);//布林上

arr[13,1]=round(average(close, 20),2);//布林中

arr[14,1]=round( bollingerband(Close, 20, -1 * 2),2);//布林下

arr[15,1]=round(highest(high,250),2);//年高

arr[16,1]=round(Lowest(low,250),2);//年低

arr[17,1]=round(highw(0),2);//周高

arr[18,1]=round(Loww(0),2);//周低

arr[1,2]=1;

arr[2,2]=2;

arr[3,2]=3;

arr[4,2]=4;

arr[5,2]=5;

arr[6,2]=6;

arr[7,2]=7;

arr[8,2]=8;

arr[9,2]=9;

arr[10,2]=10;

arr[11,2]=11;

arr[12,2]=12;

arr[13,2]=13;

arr[14,2]=14;

arr[15,2]=15;

arr[16,2]=16;

arr[17,2]=17;

arr[18,2]=18;

array_sort2d(arr, 1, 18, 1, false);

for i=1 to 18

begin

switch(Arr[i,2])

begin

case 1:

strArr[i]="W5";

case 2:

strArr[i]="WE12";

case 3:

strArr[i]="WE26";

case 4:

strArr[i]="W60";

case 5:

strArr[i]="D5";

case 6:

strArr[i]="DE12";

case 7:

strArr[i]="DE26";

case 8:

strArr[i]="D60";

case 9:

strArr[i]="今高";

case 10:

strArr[i]="今收";

case 11:

strArr[i]="今低";

case 12:

strArr[i]="布林上";

case 13:

strArr[i]="布林中";

case 14:

strArr[i]="布林下";

case 15:

strArr[i]="年高";

case 16:

strArr[i]="年低";

case 17:

strArr[i]="周高";

case 18:

strArr[i]="周低";

end;

end;

plot(1,Arr[1,1],checkbox:=0);

setplotLabel(1,strArr[1]);

plot(2,Arr[2,1],checkbox:=0);

setplotLabel(2,strArr[2]);

plot(3,Arr[3,1],checkbox:=0);

setplotLabel(3,strArr[3]);

plot(4,Arr[4,1],checkbox:=0);

setplotLabel(4,strArr[4]);

plot(5,Arr[5,1],checkbox:=0);

setplotLabel(5,strArr[5]);

plot(6,Arr[6,1],checkbox:=0);

setplotLabel(6,strArr[6]);

plot(7,Arr[7,1],checkbox:=0);

setplotLabel(7,strArr[7]);

plot(8,Arr[8,1],checkbox:=0);

setplotLabel(8,strArr[8]);

plot(9,Arr[9,1],checkbox:=0);

setplotLabel(9,strArr[9]);

plot(10,Arr[10,1],checkbox:=0);

setplotLabel(10,strArr[10]);

plot(11,Arr[11,1],checkbox:=0);

setplotLabel(11,strArr[11]);

plot(12,Arr[12,1],checkbox:=0);

setplotLabel(12,strArr[12]);

plot(13,Arr[13,1],checkbox:=0);

setplotLabel(13,strArr[13]);

plot(14,Arr[14,1],checkbox:=0);

setplotLabel(14,strArr[14]);

plot(15,Arr[15,1],checkbox:=0);

setplotLabel(15,strArr[15]);

plot(16,Arr[16,1],checkbox:=0);

setplotLabel(16,strArr[16]);

plot(17,Arr[17,1],checkbox:=0);

setplotLabel(17,strArr[17]);

plot(18,Arr[18,1],checkbox:=0);

setplotLabel(18,strArr[18]);

  • 按讚來自於
  • xqyi0502
xqyi 發文於   2024/06/12

1. 感謝提供更簡化的排序指標。

2. 壓力1價和支撐1價,之後問了好機天GPT,終於問出個端倪

Vars: intrabarpersist maxLessThanLow(-999999), intrabarpersist minGreaterThanHigh(999999),

intrabarpersist mTlow(0), intrabarpersist mThigh(0);

var:i(0);

Array: values[18](0) ;

 

values[1] = round(average(getField("收盤價","W"),5),2); // W5

values[2] = round(xf_EMA("w",getField("收盤價","W"),12),2); // WE12

values[3] = round(xf_EMA("W",getField("收盤價","W"),26),2); // WE26

values[4] = round(average(getField("收盤價","W"),60),2); // W60

values[5] = round(average(Close,5),2); // D5

values[6] = round(EMA(Close,12),2); // DE12

values[7] = round(EMA(Close,26),2); // DE26

values[8] = round(average(Close,60),2); // D60

values[9] = round(High,2); // 今高

values[10] = round(Close,2); // 今收

values[11] = round(Low,2); // 今低

values[12] = round(bollingerband(Close, 20, 2),2); // 布林上

values[13] = round(average(Close, 20),2); // 布林中

values[14] = round(bollingerband(Close, 20, -2),2); // 布林下

values[15] = round(highest(High, 250),2); // 百日高

values[16] = round(lowest(Low, 250),2); // 百日低

values[17] = round(Highw(0),2); // 周高

 

values[18] = round(Loww(0),2); // 周低

// 初始化 minGreaterThanHigh 和 maxLessThanLow

minGreaterThanHigh = 999999;

maxLessThanLow = -999999;

 

For i = 1 to 18 begin

    // 找出大于 high 的最小值 壓力

    if values[i] > High then begin

        if values[i] < minGreaterThanHigh then

            minGreaterThanHigh = values[i];

    end;

 

    // 找出小于 low 的最大值 支撐

    if values[i] < Low then begin

        if values[i] > maxLessThanLow then

            maxLessThanLow = values[i];

    end;

end;

 

// 更新壓力價和支撐價

mThigh = minGreaterThanHigh;

mTlow = maxLessThanLow;

 

Plot31(mThigh, "壓力1價");

Plot32(mTlow, "支撐1價");

但壓力2和支撐2,尚未解決!

 

虎科大許教授 發文於   2024/06/12

(1)請清楚定義第一壓力、第一支撐、第二壓力、第二支撐。

(2)你的寫法很沒效率。不需要每根K棒都跑迴圈。

xqyi 發文於   2024/07/08

1.

如上有18個價位,以當日盤中最高價和最低價作為基準,

第一個高於最高價(HighD)的為第一壓力價位,高於第一壓力價位的為第二壓力價位,依此類推

第一個低於最低價(LowD)的為第一支撐價位,低於第一支撐價位的為第二支撐價位,依此類推

2.

壓力支撐價位因為寫不出來,問於GPT寫的,教授是否能提供更有效率的?

虎科大許教授 發文於   2024/07/08

給你個提示,既然對陣列進行排序了,只要鎖定住今高的在陣列的元素編號,它的上一個編號應該就是你的第一壓力。

xqyi 發文於   2024/07/08

教授,您高看我了!

我想過,想得出方法但寫不出程式碼,這部份真的非我所強!

迴圈、陣列、begin end、case、.....  碰到類似這種 跨行 的腦袋就打結繞不出來

腦袋瓜有很多想法和對策,但礙於編寫程式碼之能力不足,80%的idea停擺!

顯示更多回應 發表回覆
Close