迴圈的應用問題

  •   38 
  • 最後發表   biscrown  2025 八月 26
biscrown 發文於   2025/08/26

hi 小幫手

最近試著用迴圈寫條件觸發前15根內的最高價=今日最高價且K棒為30%的上影線, 但始終無法達成預期.

能否給建議是哪裡邏輯有謬誤?

謝謝

 

// 創新高後進入變色區

variable:KN(0);

IF DATE<>DATE[1] then begin

KN=0;

ENd;

KN=KN+1;

VALUE1=average(C,KN);

 

variable:ema3(0),sma10(0);

ema3=ema(close,3);

sma10=average(close,10);

condition1=ema3 cross Under value1;

condition2=ema3 cross Under sma10;

 

 

Value3=HighD(0);

 

var: barRange(0);

var: upperShadow(0);

var:i(0);

 

    i=0;

for i=0 to 15 begin

  

  if High[i]=Value3 then begin

     barRange=High[i]-Low[i];

  if barRange<>0 then

     upperShadow=High[i]-MaxList(Open[i], Close[i])/barRange;

break;

end;

  end;

 

if High[i]=Value3 and upperShadow>0.3 and High[i]<>getField("漲停價", "D") and trueAll(condition1[1]=false,5) and ema3 cross Under value1 then plot1(ema3,"進入變色區");

if High[i]=Value3 and upperShadow>0.3 and High[i]<>getField("漲停價", "D") and trueAll(condition2[1]=false,5) and ema3 cross Under sma10 then plot3(ema3,"將要進入變色區");

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

除非絕對必要,不要使用迴圈,因為它很耗資源,效率會比較差。若只是判斷目前K棒最高價等於過去15期最高價且上影線超過整根K棒30%,不需要跑迴圈。只要撰寫一行指令如下:

condition1=h=highest(h[1],15) and  upshadow>0.3;

biscrown 發文於   2025/08/26

感謝教授的說明指導

可能語義上沒有清楚說明想要的狀況 , 預設的狀況應該是為條件觸發下K棒的前15根K棒曾經發生過High=HighD(0)且此High=HighD(0)的K棒為上影線>30%.

 

虎科大許教授 發文於   2025/08/26

condition1=TrueAny(h[1]=getField("最高價","D") and upshadow[1]>0.3 ,15);

biscrown 發文於   2025/08/26

再次感謝教授解答

發表回覆
Close