COCO研究院

 找回密碼
 註冊
搜索
查看: 13224|回復: 18

請問如何取最後一筆進場的價格?

[複製鏈接]
發表於 11-8-18 17:50 | 顯示全部樓層 |閱讀模式
請問各位大大有人知道要怎麼在Multicharts中,取得最後(最新)一筆的交易的進場價格呢?我本來用entryprice(0),後來發現這個指令,並不會隨著第二筆、第三筆進場至第n筆進場的價格變動,只會維持在第一次進場的價格!

請問大大們,有什麼好方法嗎?marketposition,好像也不會示出以進了幾口單的,只會空單-1,多1。

date, set, marketposition, entryprice
1110615.00,    0.00,    0.00,    0.00
1110616.00,    1.00,    0.00,    0.00
1110617.00,    2.00,   -1.00, 8492.00
1110620.00,    2.00,   -1.00, 8492.00
1110621.00,    2.00,   -1.00, 8492.00
1110622.00,    2.00,   -1.00, 8492.00
1110623.00,    2.00,   -1.00, 8492.00
1110624.00,    2.00,   -1.00, 8492.00
1110627.00,    3.00,   -1.00, 8492.00
1110628.00,    3.00,   -1.00, 8492.00
1110629.00,    3.00,   -1.00, 8492.00
1110630.00,    3.00,   -1.00, 8492.00
1110701.00,    3.00,   -1.00, 8492.00
1110704.00,    3.00,   -1.00, 8492.00
1110705.00,    3.00,   -1.00, 8492.00
1110706.00,    3.00,   -1.00, 8492.00
1110707.00,    3.00,   -1.00, 8492.00
1110708.00,    3.00,   -1.00, 8492.00
1110711.00,    3.00,   -1.00, 8492.00
1110712.00,    3.00,   -1.00, 8492.00
發表於 11-8-18 20:01 | 顯示全部樓層
試試看設變數呢
vars:x(0);
if...進場條件then begin buy ...at market;x=entryprice;end;  (用變數來存進場價)

marketposition並不是計數的函數,只是用來代表多空零倉位,也可以考慮用變數來計算,
if......then begin buy ...at market;b=b+1;end;(進場就+1)
if.... then begin exitlong next bar at market;b=b-1;end;(出場就-1)
空方可以再設另外變數。
如果是當沖得每天變數歸0 if date[1]<>date[0] then begin b=0;x=0;end;
試試看囉,小的沒實際跑過加碼單,所以純粹用簡單方法表達,
程式裡頭是有內建counter的函數拉,但是每個平台不同,所以就沒用過。
還有,上述是ts語法,希望有幫到點小忙。
 樓主| 發表於 11-8-19 09:13 | 顯示全部樓層
回復 2# samuelho


   謝謝Samuelho大,晚點來試試看!但是entryprice價格都不會變動,存進去不知會不會變!謝謝!
 樓主| 發表於 11-8-19 15:08 | 顯示全部樓層
用變數存entryprice,還是值還是沒有變化,看樣子問題應該還是出在Entryprice,這個指令不會取得最新的交易價格,只會停留在第一筆的進場價!

if UseFailsafe = true and close <= SEF then begin
        sellshort ("FSE") Units contracts next bar at market;
        TagSEF = 1;
        set = set + 1;
        value1=entryprice_checked;
        value2=entryprice;
End;

print(date, ", ", set, ", ", marketposition, ", ", entryprice, ", ", value1, ", ", value2);
1110615.00,    0.00,    0.00,    0.00,    0.00,    0.00
1110616.00,    1.00,    0.00,    0.00,    0.00,    0.00
1110617.00,    2.00,   -1.00, 8492.00, 8492.00, 8492.00
1110620.00,    2.00,   -1.00, 8492.00, 8492.00, 8492.00
1110621.00,    2.00,   -1.00, 8492.00, 8492.00, 8492.00
1110622.00,    2.00,   -1.00, 8492.00, 8492.00, 8492.00
1110623.00,    2.00,   -1.00, 8492.00, 8492.00, 8492.00
1110624.00,    2.00,   -1.00, 8492.00, 8492.00, 8492.00
1110627.00,    3.00,   -1.00, 8492.00, 8492.00, 8492.00
1110628.00,    3.00,   -1.00, 8492.00, 8492.00, 8492.00
1110629.00,    3.00,   -1.00, 8492.00, 8492.00, 8492.00
發表於 11-8-19 16:55 | 顯示全部樓層
本帖最後由 ilpir 於 11-8-19 05:02 PM 編輯

回復 4# titl

Hi 程式有平倉過嗎??
或是有開允許同向委託嗎?以您print 內容來,很像是進場後就沒有出場過了.
或是第一筆進場後,就沒有再進場了.
那個set 數值只能代表條件有成立,並不表示有進場.

entryprice 一定會存入最後一筆進場價,決不會只是第一筆.
建議把print 放入if....end 內,
另外多設value3=close;
因為是用next bar at market進場,所以條件成立時的close=entryprice.

同時print: value3,entryprice ,marketposition*currentcontracts 比較.
 樓主| 發表於 11-8-19 17:47 | 顯示全部樓層
回復 5# ilpir

那是因為剛好這段還沒有平倉,我修過了!同向交易有開,倉位也有增加,但是entryprice,還是沒有改變!第一筆的close跟entryprice還是會有誤差,應該是跳空的關係吧!


value1=entryprice_checked;

value2=close;

value3=marketposition*currentcontracts;

print(date, ", ", set, ", ", marketposition, ", ", entryprice, ", ", value1, ", ", value2, ", ", value3);
   
1100505.00,    1.00,    0.00,    0.00,    0.00, 7659.00,    0.00
1100521.00,    2.00,   -1.00, 7643.00, 7643.00, 7209.00,   -1.00
1100524.00,    3.00,   -1.00, 7643.00, 7643.00, 7274.00,   -2.00
1100826.00,    1.00,    0.00,    0.00,    0.00, 7621.00,    0.00
1110211.00,    1.00,    0.00,    0.00,    0.00, 8563.00,    0.00
1110315.00,    2.00,   -1.00, 8625.00, 8625.00, 8257.00,   -1.00
1110317.00,    3.00,   -1.00, 8625.00, 8625.00, 8255.00,   -2.00
1110616.00,    1.00,    0.00,    0.00,    0.00, 8493.00,    0.00
1110617.00,    2.00,   -1.00, 8492.00, 8492.00, 8461.00,   -1.00
1110627.00,    3.00,   -1.00, 8492.00, 8492.00, 8337.00,   -2.00
 樓主| 發表於 11-8-19 17:53 | 顯示全部樓層
回復 5# ilpir



看樣子,這應該是multicharts的問題。該不會只能像他說的一樣,用平均價,再去回推吧!

http://www.multicharts.com.tw/Discuss/Discuss_List_Reply.aspx?Zone_ID=14&List_ID=634&page=1
發表於 11-8-25 02:07 | 顯示全部樓層
本帖最後由 minime 於 11-8-25 02:09 AM 編輯

根據文件
EntryPrice
Returns the entry price for the specified position.

EntryPrice(Num)
Where Num is a numeric expression representing the number of positions ago (up to a maximum of ten).Remarks
This function can only be used in the evaluation of strategies.  It does not require an input, however, by using the input Num, you can obtain the specified value from a previous position, up to ten positions ago.Example

EntryPrice(2) might return a value of 101.19 as the entry price of 2 positions ago on a chart of Microsoft stock.
============================

所以 EntryPrice 傳回的是最後一筆成交價, 非第一筆成交價
若 EntryPrice (2) 傳回的則是兩筆前的成交價
 樓主| 發表於 11-8-25 08:37 | 顯示全部樓層
回復 8# minime


   是啊!我看說明也是這樣,但是實際使用卻不是!
發表於 11-8-25 12:16 | 顯示全部樓層
本帖最後由 minime 於 11-8-25 12:19 PM 編輯
回復  minime
   是啊!我看說明也是這樣,但是實際使用卻不是!
titl 發表於 11-8-25 08:37 AM


像 ilpir 大大說的,你的 print 指令必須放在 if then begin end statement 裡, 而不是 if 外面
放在外面的結果是每一根K棒都會print 一次
 樓主| 發表於 11-8-25 12:35 | 顯示全部樓層
回復 10# minime


   第二次測試時,就是寫在IF裡面了!日期就沒有連續了!寫在外面只是每根記錄,假如結果正確,應該答案也是一樣才對!
 樓主| 發表於 11-8-25 12:57 | 顯示全部樓層
又重新寫了一個簡單的進場機制測試,結果還是一樣,看官網討論區也有這個問題,看樣子只能另想辦法了!

  1. variable: SetB(0), SetS(0);

  2. once cleardebug;

  3. if o > h[1] and SetB < 3 then begin
  4.         buy this bar at close;
  5.         SetB = SetB + 1;
  6.         SetS = 0;
  7.         print(date, ", ", close, ", ", SetB, ", ", SetS, ", ", entryprice, " ,", marketposition * currentcontracts );
  8. end;

  9. if o < L[1] and SetS < 3 then begin
  10.         sellshort this bar at close;
  11.         SetS = SetS + 1;
  12.         SetB = 0;
  13.         print(date, ", ", close, ", ", SetB, ", ", SetS, ", ", entryprice, " ,", marketposition * currentcontracts );
  14. end;
複製代碼


1110323.00, 8448.00,    0.00,    1.00,    0.00 ,   0.00
1110325.00, 8579.00,    1.00,    0.00, 8448.00 ,  -1.00
1110330.00, 8590.00,    2.00,    0.00, 8579.00 ,   1.00
1110406.00, 8838.00,    3.00,    0.00, 8579.00 ,   2.00
1110419.00, 8627.00,    0.00,    1.00, 8579.00 ,   3.00
1110420.00, 8791.00,    1.00,    0.00, 8627.00 ,  -1.00
1110421.00, 8993.00,    2.00,    0.00, 8791.00 ,   1.00
1110426.00, 8970.00,    0.00,    1.00, 8791.00 ,   2.00
1110427.00, 9060.00,    1.00,    0.00, 8970.00 ,  -1.00
1110428.00, 9010.00,    2.00,    0.00, 9060.00 ,   1.00
1110511.00, 9020.00,    3.00,    0.00, 9060.00 ,   2.00
1110512.00, 9030.00,    0.00,    1.00, 9060.00 ,   3.00
1110516.00, 8922.00,    0.00,    2.00, 9030.00 ,  -1.00
1110517.00, 8914.00,    0.00,    3.00, 9030.00 ,  -2.00
1110519.00, 8840.00,    1.00,    0.00, 9030.00 ,  -3.00
1110523.00, 8738.00,    0.00,    1.00, 8840.00 ,   1.00
1110526.00, 8787.00,    1.00,    0.00, 8738.00 ,  -1.00
1110530.00, 8820.00,    0.00,    1.00, 8787.00 ,   1.00
1110531.00, 9021.00,    1.00,    0.00, 8820.00 ,  -1.00
1110602.00, 9031.00,    0.00,    1.00, 9021.00 ,   1.00
1110610.00, 8829.00,    1.00,    0.00, 9031.00 ,  -1.00
1110613.00, 8744.00,    0.00,    1.00, 8829.00 ,   1.00
1110616.00, 8493.00,    0.00,    2.00, 8744.00 ,  -1.00
1110622.00, 8444.00,    1.00,    0.00, 8744.00 ,  -2.00
1110627.00, 8337.00,    0.00,    1.00, 8444.00 ,   1.00
1110628.00, 8308.00,    1.00,    0.00, 8337.00 ,  -1.00
1110701.00, 8570.00,    2.00,    0.00, 8308.00 ,   1.00
1110704.00, 8603.00,    3.00,    0.00, 8308.00 ,   2.00
1110711.00, 8598.00,    0.00,    1.00, 8308.00 ,   3.00
1110712.00, 8419.00,    0.00,    2.00, 8598.00 ,  -1.00
1110720.00, 8698.00,    1.00,    0.00, 8598.00 ,  -2.00
1110722.00, 8691.00,    2.00,    0.00, 8698.00 ,   1.00
1110725.00, 8608.00,    0.00,    1.00, 8698.00 ,   2.00
1110728.00, 8728.00,    0.00,    2.00, 8608.00 ,  -1.00
1110802.00, 8574.00,    0.00,    3.00, 8608.00 ,  -2.00
1110816.00, 7773.00,    1.00,    0.00, 8608.00 ,  -3.00
1110818.00, 7500.00,    0.00,    1.00, 7773.00 ,   1.00
1110819.00, 7251.00,    0.00,    2.00, 7500.00 ,  -1.00
發表於 11-8-25 13:08 | 顯示全部樓層
這可能真的是個問題.
http://www.multicharts.com/discu ... t=entryprice#p38824

At the moment entryprice works the following way:

Returns a numerical value, indicating the price at the initial entry into the specified position.

EntryPrice(PosBack)

Where: PosBack - a numerical expression, specifying the position:

0 - open position;
1 - one position back (the last position closed);
2 - two positions back, etc.

If PosBack is not specified, a value for the open position will be returned.

If you use pyramiding, entryprice(0) will return average price for position.

加碼的話, MC 會用平均值
 樓主| 發表於 11-8-25 14:26 | 顯示全部樓層
回復 13# minime


   平均值有平均值的指令,entryprice應該算是bug吧!現在如果要取得最新的進場價,看樣子只能用算的,或是等他把entryprice修正了吧!謝謝M大!
發表於 11-8-25 14:32 | 顯示全部樓層
MC tech support 說 TS 也是這樣設計, 他們只是照抄而已, 以維持相容性.

他們說下一版會另外寫新函式

真要用目前就只有自己寫了
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-5-3 20:31

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook