MC布林帶震蕩策略源碼:
inputs: Len(20); // 輸入 參數(shù);
variables:midline(0),upband(0),dnband(0),
sell_con(false),buy_con(false); // 變量的命名;
midline=Average(close,Len); // 布林帶的中軌
upband=BollingerBand(close,Len,2); // 布林帶上軌
dnband=BollingerBand(close,Len,-2); // 布林帶下軌
sell_con=close crosses under upband; // 下穿布林帶上軌時(shí),賣(mài)空開(kāi)倉(cāng)
buy_con=close crosses over dnband; // 上穿布林帶下軌時(shí), 買(mǎi)進(jìn)開(kāi)倉(cāng)
if sell_con and marketposition=0 then // 下穿布林帶上軌時(shí),賣(mài)空開(kāi)倉(cāng)
sellshort next bar at market;
if buy_con and marketposition=0 then // 上穿布林帶下軌時(shí), 買(mǎi)進(jìn)開(kāi)倉(cāng)
buy next bar at market;
if marketposition=-1 and close<midline then // 賣(mài)空開(kāi)倉(cāng)后,價(jià)格回到中軌,空單平倉(cāng)。
buytocover next bar at market;
if marketposition=1 and close>midline then // 買(mǎi)進(jìn)開(kāi)倉(cāng)后,價(jià)格回到中軌,多單平倉(cāng)。
sell next bar at market;