簡單的MACD入市策略分享:
造好:
MACD(9,26,9)慢線由零線之下升至零線之上後,繼而再發出買入訊號便入市造好,收市價升穿20SMA止賺或RSI(7)跌至20止蝕。
造淡:
MACD(9,26,9)慢線由零線之上跌至零線之下後,繼而再發出沽出訊號便入市造淡,收市價跌穿20SMA止賺或RSI(7)升至80止蝕。
SetPositionSize(1,spsShares);
red=Ref(Signal(9,26,9),-1)<0 AND Signal(9,26,9)>0;
dark=Ref(Signal(9,26,9),-1)>0 AND Signal(9,26,9)<0;
Buy=0;
Sell=0;
Short=0;
Cover=0;
MACDarray=MACD(9,26);
Signalarray=Signal(9,26,9);
GoldCross = Cross(MACDarray, Signalarray);
DeadCross = Cross(Signalarray, MACDarray);
rsiARRAY=RSI(7);
MAarray=MA(Close,20);
Higharray=High;
Lowarray=Low;
Closearray=Close;
Buysignal=False;
Shortsignal=False;
positionhold=0;
for (i=0; i <BarCount; i++)
{
if (red[i]==True AND positionhold==0)
{
Buysignal=True;
}
else if (Buysignal==True AND GoldCross[i] AND positionhold==0)
{
Buy[i]=1;
positionhold++;
}
else if (positionhold>0 AND Closearray[i]>MAarray[i] OR RSIARRAY[i]<20)
{
Sell[i]=1;
positionhold=0;
}
else if (dark[i]==True AND positionhold==0)
{
Shortsignal=True;
}
else if (Shortsignal==True AND DeadCross[i] AND positionhold==0)
{
Short[i]=1;
positionhold--;
}
else if (positionhold<0 AND Closearray[i]<MAarray[i]OR RSIARRAY[i]>80)
{
Cover[i]=1;
positionhold=0;
}
}
PlotShapes( Buy*shapeUpArrow, colorBlue, 0, Low -2);
PlotShapes (Sell*shapeDownArrow, colorPink, 0, High + 2);
PlotShapes( Short*shapeDownArrow, colorRed, 0, High +2);
PlotShapes (Cover*shapeUpArrow,colorGreen, 0, Low -2);
資料來源: 量化交易研究中心(QUANTS) |