條件已觸發 超過時間不進場

  •   417 
  • 最後發表   阿棠  2024 九月 01
阿棠 發文於   2024/08/29

目前我是用k棒來計算,條件已觸發,但超過幾根k棒還沒進場,則不進場

但試起來 還是沒辦法順利動作 請各位前輩看看下面兩個寫法哪裡出問題



input:in_bar;

var:count_in(0);

condition1=進場條件;

condition2=出場條件; 

 

1.

if FilledAvgPrice <> 0 then

count_in = 0 ;

 

if condition1 and FilledAvgPrice = 0 then

count_in += 1;    //進場條件觸發,還沒買進,每過1根k就+1,以此計算經過幾根k棒

 

if condition2 and FilledAvgPrice = 0 then

count_in=0;    //出場後 k棒計算歸0

 

if condition1 and FilledAvgPrice = 0 and count_in > in_bar then

setposition(o);    //進場條件觸發,還沒進場前,若經過k棒的數量大於設定數量,則不進場

end;

 

2.

if condition1 and FilledAvgPrice = 0 then

count_in=currentBar;    //進場條件觸發,還沒買進,以現在k棒當成第1根k

 

if condition2 and FilledAvgPrice = 0 then

count_in=0;    //出場後 k棒計算歸0

 

if condition1 and FilledAvgPrice = 0 and currentBar > count_in + in_bar then

setposition(o);  //進場條件觸發,還沒進場前,若經過k棒的數量大於設定數量,則不進場

end;

 

 

 

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

除非你進場的條件是類似高於均線,否則可能會已經經過足夠的K棒數,但進場條件已經改變,不再是true。這樣就不會進場。

阿棠 發文於   2024/08/30

謝謝教授  後續我有增設這個部分,如果進場條件消失就不進場

那是不是可以寫成

"超過多久時間或幾根k棒",則進場條件消失

只是這個"超過多久時間或幾根k棒"   <---這個部分一直出現2個問題,都不動作 或是 進場條件直接消失 然後不進場

 

阿棠 發文於   2024/08/30

上面是以k棒來計算

還有寫一個以時間來計算的 但也還是出現  不動作 或 直接不進場

input:time_inf

 

var: intrabarpersist time_in(0);

 

if condition1 and time_in = 0

then begin

time_in = CurrentTimeMS;

end;

 

 

if condition1 and AbsValue(timediff(CurrentTimeMS, time_in, "M")) <= time_inf

then begin....不進場

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

可用類似前三期符合進場條件condition1[3]或過去三期有出現進場條件TrueAny(condition1[1],3),再結合你的條件來操作。

  • 按讚來自於
  • oscar8014
阿棠 發文於   2024/08/30

謝謝教授提供新想法~~

我本來的進場條件是 如果這根k的收盤突破前根k的高  則下一根k進場

condition1=c>h[1];

if condition1[1] and FilledAvgprice=0 then begin 

Setposition(1,Market);

end;

如果把 condition[1]   改成   condition[3]   

就會是 本來前1期觸發進場 變成 前3期觸發進場

這樣走到第4期的時候  就不會進場了  ///     跟使用  TrueAny(condition1[1],3)  的邏輯一樣

 

我這樣理解正確嗎

 

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

if condition1[3] and FilledAvgprice=0 then begin  

代表前三期符合進場條件且目前還沒有部位(還沒進場或已進場但沒成交)。

 //進場條件觸發,還沒進場前,若經過k棒的數量大於設定數量,則不進場。

if condition1 and FilledAvgPrice = 0 and count_in > in_bar then setposition(0); 

這個邏輯與不進場的概念不同,程式這樣寫,代表送出讓庫存為0的委託單。是否你要的是condition1符合就以限價單進場,只要經過一段時間沒有成交就刪單?

 

  • 按讚來自於
  • oscar8014
阿棠 發文於   2024/08/31

對   condition1符合就以限價單進場,只要經過一段時間沒有成交就刪單

但我不是掛委託單 是以一個進場開關 true or false 作為基準     

如果condition1 則碰到價位 進場開關true 市價買進(IOC)

還沒碰到價位之前  進場開關維持false

 

出場就是 setposition(0) 然後進場開關false

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

 

有點被你搞混了。請說明清楚你的需求。

若我沒有理解錯誤,其實你不需要另外用什麼開關,只要用position控制即可。myprice就是你希望碰到的價位。

if position=0 and c>h[1] and c=myprice then setposition(1,market);

if position>0 and 出場條件 then setposition(0); 

  • 按讚來自於
  • oscar8014
阿棠 發文於   2024/08/31

好的 已把開關部分修改

if position=0 and c>h[1] and c=myprice then setposition(1,market);

 

if position=0 and c>h[1] and c<>myprice then 

count_in += 1; 

 

if count_in > in_bar then 取消進場

 

if position>0 and 出場條件 then 

setposition(0);

count_in=0;


想請教 這個取消進場的部分  應該怎麼寫比較好

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

市價進場了,一般都會成交,哪有取消進場的可能?

顯示更多回應 發表回覆
Close