布林通道
1 inputs: baolin_price(close), //用于 计算宝林通道 2 current_price(close), //当前价格 3 length(20), 4 up_std(2), 5 dn_std(2), 6 long_ma_day(120), //长期趋势线 上升时购买 7 diaodeng_para(2);// 吊灯止损 2 = 2% 8 9 vars: up_band(0), 10 dn_band(0), 11 buy_cnt(0), 12 diaodeng_peice(0), 13 day_long_ma(0), 14 first_buy_price(0), 15 first_buy_barcnt(0), 16 mid_price(0); 17 18 up_band = BollingerBand( baolin_price, length, up_std ) ;//宝林带 通道上 19 dn_band = BollingerBand( baolin_price, length, -up_std ) ;//宝林带 通道下 20 day_long_ma=AverageFC(baolin_price,long_ma_day);//长平均线 用来判断趋势 21 mid_price=((high+low+close)/3); //中轴线 用于 吊灯止损 22 23 24 25 26 // 不是1一条线(必须有) 当前价格在宝林通道上限的上面 趋势属于上升趋势 27 if (CurrentBar > 1) and (current_price> up_band) and (day_long_ma>day_long_ma[1]*1.001) then 28 begin 29 buy ( "buy" ) 1 shares next bar at open; //下个开盘价买入1手 30 if(buy_cnt=0) then 31 begin 32 first_buy_price =close; 33 first_buy_barcnt = CurrentBar; 34 end; 35 buy_cnt=buy_cnt+1; 36 37 end; 38 39 // 不是1一条线(必须有) 当前价格在宝林通道下限的下面 并且 有持仓 40 if (CurrentBar > 1) and (current_price < dn_band) and (buy_cnt>0) then 41 Begin 42 sell ("sell") buy_cnt shares next bar at open; //全部销售 43 diaodeng_peice=0; //止损线 清零 44 end; 45 46 // 止损 中轴线 吊灯止损 并且 有持仓 47 if(mid_price< diaodeng_peice* (1-0.01 *diaodeng_para)) and (buy_cnt>0) then 48 begin 49 sell ("diaodeng_zisun") buy_cnt shares next bar at open; //全部销售 50 diaodeng_peice=0; //止损线 清零 51 end; 52 53 54 //更新 吊灯止损线 55 if(mid_price>diaodeng_peice) then 56 diaodeng_peice=mid_price; 57 58 59 //止损 开始价 低于 60 If (first_buy_barcnt> CurrentBar+1) and (close< first_buy_price*0.995) and (buy_cnt>0) then 61 Begin 62 sell ("diyi_zisun") buy_cnt shares next bar at open; //全部销售 63 diaodeng_peice=0; //止损线 清零 64 65 end; 66 67 //plot1(up_band,"up_band"); 68 //plot2(dn_band,"dn_band"); 69 //plot3(day_long_ma,"day_long_ma"); 70 //plot4(diaodeng_peice,"diaodeng_peice");