//+------------------------------------------------------------------+ //| GT BB.mq4 | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red extern bool Allert = True; //+------------------------------------------------------------------+ extern int BBPeriod = 20; extern int BBDeviation = 2; extern int BBPrice = 0; //-------------------------------------------------------------------+ extern int MA = 20; // extern int Mode = 0; // 0=SMA,1=EMA,2=SSMA,3=LWMA extern int Price = 0; // 0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted //-------------------------------------------------------------------+ double BuyBuffer[],SellBuffer[]; int pre_signal = 0; //+------------------------------------------------------------------+ int init() { IndicatorShortName("GT BB"); //---- SetIndexBuffer(0, BuyBuffer); SetIndexLabel(0, "Buy"); SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 2); SetIndexArrow(0, 241); //---- SetIndexBuffer(1, SellBuffer); SetIndexLabel(1, "Sell"); SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 2); SetIndexArrow(1, 242); //---- return(0); } //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ int start() { int counted_bars = IndicatorCounted(); //---- if(counted_bars < 0) { Print("Indicator Error (Counted bars < 0)!"); return(-1); } //---- if(Bars < 17) { Print("Indicator Error (Bars < 12)!" ); return(-1); } int limit = Bars - 17; //---- if(counted_bars > 17) { limit = Bars - counted_bars; } //+------------------------------------------------------------------+ for(int i = limit; i >= 0; i --) { BuyBuffer[i] = EMPTY_VALUE; SellBuffer[i] = EMPTY_VALUE; //--------------------------------------------------------------------+ double BBup = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_UPPER,i+1); double BBlo = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_LOWER,i+1); double MAnow = iMA(NULL,0,MA,0,Mode,Price,i); double MApre = iMA(NULL,0,MA,0,Mode,Price,i+1); //--------------------------------------------------------------------+ if(Low[i+1] < BBlo && MAnow > MApre) { BuyBuffer[i] = Low[i]; } if(High[i+1] > BBup && MAnow < MApre) { SellBuffer[i] = High[i]; } } //--------------------------------------------------------------------+ if(Allert) { if(pre_signal <= 0 && BuyBuffer [i+1] != EMPTY_VALUE) { Alert("GT BB"," BUY! ",Symbol()," ", Period()); pre_signal = 1; } if(pre_signal >= 0 && SellBuffer[i+1] != EMPTY_VALUE) { Alert("GT BB"," SELL! ",Symbol()," ", Period()); pre_signal = -1; } } return(0); } //+------------------------------------------------------------------+