台指期移動停利

  •   484 
  • 最後發表   桂桂  2024 十月 01
桂桂 發文於   2024/09/25

非逐筆交易(60分鐘線)小型台指

請問我在9/25 18:00 收K進場小台 出場如下 進場點22927

想詢問為什麼在9/25 23:00 這個K棒收盤沒出場

9/25 23:00 最高價 23032   (23032-成本價22927=105點) 啟動移動停利回跌/回跌50點出場

9/25 22:00 這個K棒收盤沒出場(收盤價在22954)最高23032-22954=78點  /有回掉78點應該要出場...?

還是我理解錯誤...

 

input: profit_point(50, "停利(點)");  

input: profit_drawback_point(50, "停利回跌(點)");  

input: loss_point(50, "停損(點)");  

  

  

if profit_point = 0 then raiseruntimeerror("請設定停利(點)");  

if profit_drawback_point = 0 then raiseruntimeerror("請設定停利回跌(點)");  

if profit_drawback_point > profit_point then raiseruntimeerror("停利(點)需大於停利回跌(點)");  

  

  

  

if Position > 0 and Filled > 0 then begin  

var: intrabarpersist max_profit_point(0); { 啟動停利後最大獲利點 }  

  

if loss_point > 0 and Close <= FilledAvgPrice - loss_point then begin  

{ 停損 }  

SetPosition(0);  

max_profit_point = 0;  

  

end else begin  

  

{ 判斷是否要啟動停利 }  

if max_profit_point = 0 and Close >= FilledAvgPrice + profit_point then begin  

max_profit_point = Close;  

end;  

  

if max_profit_point <> 0 then begin   

if Close <= max_profit_point - profit_drawback_point then begin  

{ 停利 }  

SetPosition(0);  

max_profit_point = 0;  

end else if Close > max_profit_point then begin  

{ 移動最大獲利點 }  

max_profit_point = Close;  

end;   

end;   

end;  

  

end;  

 

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

我之前有提供修正過後的移動停利程式碼,你並沒有使用。還是拿有問題的程式碼出來問,那之前別人的建議被當作什麼?若別人的建議有問題,你也應該適當回饋,看哪裡有問題。

桂桂 發文於   2024/09/26

謝謝你都幫忙即時回答,縮短等待時間,但也覺得很沮喪,不知道那裡讓你誤會了

我查過我所有的提問沒有這個相關問題,也用相關詞查詢,關於移動停利(點)小編有回答都是依照內建範例

至於教授的回答,,https://forum.xq.com.tw/thread/%e6%96%b0%e6%89%8b%e8%ab%8b%e7%9b%8a-%e7%a7%bb%e5%8b%95%e5%81%9c%e5%88%a9%e8%a7%b8%e7%99%bc%e5%95%8f%e9%a1%8c/?order=all#postcontent-32835d7f-f787-4638-8f3c-b1f40097a432 這篇文章我有擷取語法執行,但執行後無法有動作

如果你是因為這個,我很抱歉,沒用這個出來詢問!

我的確是非常新手完全沒學習過,也很努力翻查資料,但理解能力差,只能用自己的讓小編幫忙修改才能理解成自己的!

也是因為在學習,才想理解範例為什麼不能正確執行,一行一行解讀看不出來,想知道是哪裡錯誤,或是自己解讀錯程式邏輯

我也算跟公司租程式,消費者的觀點上..  如果範例是錯誤的,不是應該修正?  或者在範例前方註明(非準確)?

我就是完全外行,每個建議我都很尊重!  

如果我的問題讓你覺得不愉快,請你不要回答,我可以等待公司回覆

 

 

虎科大許教授 發文於   2024/09/26

抱歉,錯怪你了,之前的文章是回覆另外一位網友,你們使用的參數一模一樣。請你參考以下的貼文看看。

https://forum.xq.com.tw/thread/%e6%96%b0%e6%89%8b%e8%ab%8b%e7%9b%8a-%e7%a7%bb%e5%8b%95%e5%81%9c%e5%88%a9%e8%a7%b8%e7%99%bc%e5%95%8f%e9%a1%8c/?order=all#comment-d08e78e5-5b8a-408f-96c5-b1f4018a6bec

桂桂 發文於   2024/09/26

謝謝教授  ~ 我不希望自己成為伸手牌..會努力爬文~   但有時候提問能節省很多時間也是自己的權利! 時間就是金錢 : (

教授您的這篇回覆我有看也有複製程式碼!

 

請問教授您說我給的範例程式碼是錯誤的..?  這個是誤會還是內建範例是真的錯誤...?

我用教授的跟內建去修改

回測出來9成一樣~ 有點搞混了

input: profit_point(50, "停利(點)");  

input: profit_drawback_point(50, "停利回跌(點)");  

input: loss_point(50, "停損(點)");  

  

  

if profit_point = 0 then raiseruntimeerror("請設定停利(點)");  

if profit_drawback_point = 0 then raiseruntimeerror("請設定停利回跌(點)");  

if profit_drawback_point > profit_point then raiseruntimeerror("停利(點)需大於停利回跌(點)");  

  

  

  

if Position > 0 and Filled > 0 then begin  

var: profit(0), intraBarPersist max_profit_point(0);

  

if loss_point > 0 and Close <= FilledAvgPrice - loss_point then begin  

{ 停損 }  

SetPosition(0);  

max_profit_point = 0;  

  

end else begin  

  

{ 判斷是否要啟動停利 } 

        profit = c - FilledAvgPrice;

        if profit > max_profit_point then max_profit_point=profit;

        if profit > 0 then 

            if c <= max_profit_point - profit_drawback_point then 

                begin 

                    { 停利 } 

                    SetPosition(0); 

                    max_profit_point = 0; 

                    profit = 0;

end else if Close > max_profit_point then begin  

{ 移動最大獲利點 }  

max_profit_point = Close;  

end;   

end;   

end;  

      

XS小編 發文於   2024/10/01

Hello 桂桂,

 

就以您一開始詢問的例子來說,60分鐘非逐筆洗價代表只會在每根Bar結束時運算,腳本中用來判斷移動停利的價格都用 close,那麼就不會移動到最高價 23032。

要使用逐筆洗價才會比較接近實際情況。

建議可以在腳本中加上 print 印出相關資訊,會比較容易理解腳本的運作。

 

感謝 虎科大許教授 的熱心回覆。

發表回覆
Close