變數紀錄high問提

  •   150 
  • 最後發表   阿林  2023 三月 20
阿林 發文於   2023/03/16

小幫手您好 以下是我的腳本

if barfreq <> "Min" or Barinterval <> 2 then RaiseRuntimeError("請設定頻率為2分鐘");

var:highfrequency(0);//紀錄當日兩分k上影次數

if issessionFirstBar then begin highfrequency = 0; end;//每日重置變數

if close <= high*0.994 and GetQuote("振幅") >= 2.5 and high[1] < high and 

   high[2] < high and 

   high >= GetField("收盤價", "D")[1]*1.02//紀錄上影線 且前兩根high必須小於當根high

   then dhighfrequency += 1;

 

我腳本是希望寫出 頻率兩分鐘上影線 然後上影線前面必須至少要兩根k棒的high小於當根high

然後至少要有三根有這種條件的上影 可是我有問題的是 我想要這三根上影線的high 都在正負1%內 

三根上影線的高點相差不能超過1% 可是問題來了 有辦法紀錄上影線  但我不知道要怎麼寫出

每根上影線high的數值

XQ小幫手 發文於   2023/03/20

 Hello 阿林,

 

您可以用變數或陣列紀錄最近3個達成條件 Bar 的 High。

舉例來說:

if barfreq <> "Min" or Barinterval <> 2 then RaiseRuntimeError("請設定頻率為2分鐘");

 

var:highfrequency(0);//紀錄當日兩分k上影次數

 

if issessionFirstBar then begin 

    highfrequency = 0; 

    value1 = 0;

    value2 = 0;

    value3 = 0;

    end;//每日重置變數

 

if close <= high*0.994 and GetQuote("振幅") >= 2.5 and high[1] < high and 

   high[2] < high and 

   high >= GetField("收盤價", "D")[1]*1.02//紀錄上影線 且前兩根high必須小於當根high

   then begin

   highfrequency+= 1;

   value3 = value2;

   value2 = value1;

   value1 = high;

   end;

 

這樣當 highfrequency 是3以上時,value1 ~ value3 就會是最近3次符合條件的高點,接下來只要計算是否有在1%內即可:

condition1 = highfrequency >= 3 and 100 * (maxlist(value1, value2, value3) - minlist(value1, value2, value3)) / minlist(value1, value2, value3) <= 1;

發表回覆
Close