策略語法如下:
MA1 = average(Close,Shortlength); MA2 = average(Close,Shortlength*5); Slope = LinearRegSlope(close,Shortlength*5); condition1 = MA1 < MA2 and Slope < 0;
if condition1 and close cross under MA1 and close < open and (close - MA1) < -1 then begin value3 = high+2; _breakthrough = True; end; if _breakthrough = True and close cross over MA1 or condition1 = False then _breakthrough = False; if _breakthrough = True and condition1 and marketposition= 0 and condition4 then sellshort 2 contracts next bar at low-2 stop; if marketposition = -1 then buytocover("_stoploss") next bar at value3 stop;
大致上是在長短均線空頭排列時,且長均線斜率為負時,K棒向下跌破短均線時在最低點-2進場作空2口,進場後停損守跌破K棒的高點。
但圖中箭頭很明顯並未打到停損點,可是卻停損出場了。
我自己的理解是我的value3是個變動值而不是固定值,它在反向突破短均線時,value3變成突破後K棒的近期高點+2。但我看不出我的語法那裡有問題,再請各位幫忙回覆,感謝 !!
抱歉,策略中的and condition4是多打的,忘記刪掉,可以忽略,謝謝~
您好,
您的 Value3 看起來在 00:50 那根綠 K 條件成立改變數值了,
所以停止單設定價位在那根綠 K 高點+2,
建議您可以使用 Print 指令將條件數值輸出比對。
您好:
print結果如下:
messagelog(date,time,value3);
1180501.00 100.0010617.00 1180501.00 105.0010616.00 1180501.00 110.0010616.00 1180501.00 115.0010616.00 1180501.00 120.0010616.00 1180501.00 125.0010616.00 1180501.00 130.0010616.00 1180501.00 135.0010616.00
看起來它是把每5分K的高點+2紀錄起來,這並不是我想要的語法,不知道該如何修改比較好呢?
謝謝您~
你的程式碼 value3 不是紀錄 5 分K 高點呀,
是下面這段條件成立才變更不是嗎?
if condition1 and close cross under MA1 and close < open and (close - MA1) < -1 then begin value3 = high+2;
你可以看看數值變更的時間點是不是滿足你上面列的那些條件
已解決,謝謝您~