century 發表於 11-8-12 18:48

請問唐奇安定時的寫法

例如進場10天後賣掉,以下為語法,不知道哪裡寫錯了

var:va(0);
if marketposition<>0
then
va=currentbar;
if marketposition=0
then
va=0;
if currentbar-va=10
then
   sell this bar;

謝謝大家

maison6579 發表於 11-8-12 20:55

請改用BarsSinceEntry

if Marketposition <> 0and BarsSinceEntry(0) >= 10 then sell this bar;

century 發表於 11-8-12 22:00

本帖最後由 century 於 11-8-12 10:56 PM 編輯

太感謝了,我研究了一天原來只需要一句話....
另外可以請問一下,為什麼有些保留字可以用在訊號,可是不能畫出圖形,而有些相反,
例如 BarsSinceEntry 不能畫在圖形當指標,
i_OpenEquity可以畫在圖形但是不能用在strategy,有什麼解決方法嗎?
再次感謝...

samuelho 發表於 11-8-12 23:51

基本上能畫在圖上的應該都是H,L,O,C,V所組成運算出的數值或指標吧...
barssinceentry就是個敘述.要畫成什麼呢????
但是如果把它當作函數的一部分就可以畫出來,
例如 x=highest(c,barssinceentry)=>進場後c的最高值
plot(x,"1")
i_openequity沒用過所以不知道他的意思,如果知道,
其實應該可以把它翻成白話用在策略。

minime 發表於 11-8-13 12:59

i_OpenEquity可以畫在圖形但是不能用在strategy,有什麼解決方法嗎?
century 發表於 11-8-12 10:00 PM http://coco-in.net/images/common/back.gif

I_OpenEquity (Reserved Word)Used in a study (Indicator, ShowMe, PaintBar, etc.) to return the open equity for a strategy.The open equity is the sum of the net profit or loss of closed positions and the profit or loss of the strategy's open position, if the strategy has an open position.
Remarks
The reserved word I_OpenEquity provides a way to access strategy performance-related reserved word values in a study.Most strategy performance-related reserved words, notably those without the "I_" prefix, are available for use only in strategies.In this case, I_OpenEquity is equal to the sum of a strategy's closed position p/l and any open position p/l based on the values of the strategy reserved words NetProfit and OpenPositionProfit.

所以在 strategy 裡應該是 NetProfit + OpenPositionProfit

century 發表於 11-8-13 13:41

不好意思又遇到問題了...
如果運用maison6579 大的語法:
if Marketposition <> 0and BarsSinceEntry(0) >= 10 then sell this bar;
會遇到下一筆單買進後馬上賣出的問題,例如設進場點為收盤價,進場後10天賣在當天收盤價,
結果第一筆單的賣出日剛好是第二筆單的進場日(同樣的價位),第二筆單就在第11天已收盤價買進,結果因為Marketposition <> 0和BarsSinceEntry(0) >= 10還受到第一筆單的影響全都符合條件,就在買進後馬上賣在同一個收盤價的位置了,請問該如何解決?
ps:等於說第1天1口新倉,第11天在收盤價的位置有1口平倉後增加1口新倉結果馬上又1口平倉了,第11天總共3口單,希望最後1口平倉不要有,謝謝
不好意思我已經好幾本書在旁邊翻了,每個問題自己都搞了至少半天才會拿出來問,看來還有很長的路要走...

samuelho 發表於 11-8-13 15:45

因為你用了 barssinceentry>=10,這是指10天以後的每一天阿,因此111213...都符合條件,
當然都會賣掉,如果只要第10天就不要加>,大大指的是這問題嗎???
如果不要第10天,那條件當然要更嚴謹.縮小,例如>=10and 突破xx線   then....

century 發表於 11-8-13 16:47

本帖最後由 century 於 11-8-13 04:48 PM 編輯

回復 7# samuelho


    抱歉沒有說清楚,我的意思是,以barssinceentry來說,如果上一筆賣出跟這一筆買進在同一根K棒,他似乎會判斷錯誤?假設我想要在買進的隔天賣掉,用語法barssinceentry=1來操作,第一筆賣單確實在隔天賣掉(barssinceentry=1),結果第二筆單在第一筆單賣掉的價位買進(買點剛好出現),這時barssinceentry對第二筆單來說應該是0才對,可是TS似乎會把他判定成1,造成買進之後馬上又賣出,為什麼會這樣...

我的想法是第二筆單應該是要在第三天賣掉,謝謝大家

samuelho 發表於 11-8-14 16:36

vars:z(0);
if date<>date then z=0;
if makretposition>0 and barssinceentry=10 and z=0 then begin
sell ..................;
z=1;
end;

century 發表於 11-8-14 17:50

感謝大大,我會再試試看
頁: [1]
查看完整版本: 請問唐奇安定時的寫法