策略邏輯是,當均線多頭排列,且5日平均交易量大於1000張,且日還原價創20日新高時進場作多;然後當5MA與20MA死亡交叉時賣出。但不知道為什麼進場點和我的邏輯不一樣?謝謝小幫手。
如圖,很明顯沒有創20日新高卻買進。

語法如下:
//均線多頭排列
input:Leng1(5),Leng2(10),Leng3(20);
variable: ma1(0), ma2(0), ma3(0);
SetInputName(1,"短均線");
SetInputName(2,"中均線");
SetInputName(3,"長均線");
settotalbar(30);
ma1 = average(close, Leng1);
ma2 = average(close, Leng2);
ma3 = average(close, Leng3);
condition1 = close > ma1;
condition2 = ma1 > ma2;
condition3 = ma2 > ma3;
//五日移動平均量大於千張
if average(volume[1], 5) >= 1000
then condition4=true;
//日還原價創20日新高
input:period(20,"計算天數");
Value1 = highest(Getfield("收盤價","AD")[1],period);
Value2 = highest(Getfield("開盤價","AD")[1],period);
Value3 = highest(Getfield("最高價","AD"), 1);
if Value2 > Value1 and Value3 > Value2
Or Value1 > Value2 and Value3 > Value1
then condition5=true;
//進場
if condition1 and condition2 and condition3 and condition4 and condition5
and position = 0 then
setposition (1,market);
//出場
if ma1 Cross Under ma3 then setposition(0,market);
1 評論