//+------------------------------------------------------------------+ //| BinaryWave.mq4 | //| Copyright © 2009, LeMan | //| b-market@mail.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, LeMan" #property link "b-market@mail.ru" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Blue //--- Вес индикаторов. Если ноль, индикатор не участвует в расчете волны extern double WeightMA = 1.0; extern double WeightMACD = 1.0; extern double WeightOsMA = 1.0; extern double WeightCCI = 1.0; extern double WeightMOM = 1.0; extern double WeightRSI = 1.0; extern double WeightADX = 1.0; //---- Параметры скользящего среднего extern int MAPeriod = 13; extern int MAType = 1; extern int MAPrice = 0; //---- Параметры OsMA extern int FastMACD = 12; extern int SlowMACD = 26; extern int SignalMACD = 9; extern int PriceMACD = 0; //---- Параметры OsMA extern int FastPeriod = 12; extern int SlowPeriod = 26; extern int SignalPeriod = 9; extern int OsMAPrice = 0; //---- Параметры CCI extern int CCIPeriod = 14; extern int CCIPrice = 5; //---- Параметры Момента extern int MOMPeriod = 14; extern int MOMPrice = 0; //---- Параметры RSI extern int RSIPeriod = 14; extern int RSIPrice = 0; //---- Параметры ADX extern int ADXPeriod = 14; extern int ADXPrice = 0; //---- Включение сглаживания волны extern int MovWavePer = 1; extern int MovWaveType = 0; //---- buffers double WaveBuffer[]; double TempBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorDigits(Digits); IndicatorBuffers(2); double ws = WeightMA+WeightMACD+WeightOsMA+WeightCCI+WeightMOM+WeightRSI+WeightADX; string short_name = "Binary Wave ("+DoubleToStr(ws,Digits)+")"; //---- indicators IndicatorShortName(short_name); SetIndexBuffer(0,WaveBuffer); SetIndexBuffer(1,TempBuffer); SetIndexStyle(0,DRAW_LINE); //---- return(0); } //---- Определяем положение цены закрытия относительно скользящего среднего double MAClose(int i = 0) { if (WeightMA > 0) { if ((Close[i]-iMA(NULL,0,MAPeriod,0,MAType,MAPrice,i)) > 0) return(WeightMA); if ((Close[i]-iMA(NULL,0,MAPeriod,0,MAType,MAPrice,i)) < 0) return(-WeightMA); if ((Close[i]-iMA(NULL,0,MAPeriod,0,MAType,MAPrice,i)) == 0) return(0); } else { return(0); } } //---- Определяем наклон MACD double MACD(int i = 0) { if (WeightMACD > 0) { if (iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i)-iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i+1) > 0) return(WeightMACD); if (iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i)-iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i+1) < 0) return(-WeightMACD); if (iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i)-iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i+1) == 0) return(0); } else { return(0); } } //---- Определяем положение OsMa относительно нуля double OsMA(int i = 0) { if (WeightOsMA > 0) { if (iOsMA(NULL,0,FastPeriod,SlowPeriod,SignalPeriod,OsMAPrice,i) > 0) return(WeightOsMA); if (iOsMA(NULL,0,FastPeriod,SlowPeriod,SignalPeriod,OsMAPrice,i) < 0) return(-WeightOsMA); if (iOsMA(NULL,0,FastPeriod,SlowPeriod,SignalPeriod,OsMAPrice,i) == 0) return(0); } else { return(0); } } //---- Определяем положение CCI относительно нуля double CCI(int i = 0) { if (WeightCCI > 0) { if (iCCI(NULL,0,CCIPeriod,CCIPrice,i) > 0) return(WeightCCI); if (iCCI(NULL,0,CCIPeriod,CCIPrice,i) < 0) return(-WeightCCI); if (iCCI(NULL,0,CCIPeriod,CCIPrice,i) == 0) return(0); } else { return(0); } } //---- Определяем положение Momentum относительно 100 double MOM(int i = 0) { if (WeightMOM > 0) { if (iMomentum(NULL,0,MOMPeriod,MOMPrice,i) > 100) return(WeightMOM); if (iMomentum(NULL,0,MOMPeriod,MOMPrice,i) < 100) return(-WeightMOM); if (iMomentum(NULL,0,MOMPeriod,MOMPrice,i) == 100) return(0); } else { return(0); } } //---- Определяем положение RSI относительно 50 double RSI(int i = 0) { if (WeightRSI > 0) { if (iRSI(NULL,0,RSIPeriod,RSIPrice,i) > 50) return(WeightRSI); if (iRSI(NULL,0,RSIPeriod,RSIPrice,i) < 50) return(-WeightRSI); if (iRSI(NULL,0,RSIPeriod,RSIPrice,i) == 50) return(0); } else { return(0); } } //---- Определяем положение DMI double ADX(int i = 0) { if (WeightADX > 0) { if (iADX(NULL,0,ADXPeriod,ADXPrice,MODE_PLUSDI,i) > iADX(NULL,0,ADXPeriod,RSIPrice,MODE_MINUSDI,i)) return(WeightADX); if (iADX(NULL,0,ADXPeriod,ADXPrice,MODE_PLUSDI,i) < iADX(NULL,0,ADXPeriod,RSIPrice,MODE_MINUSDI,i)) return(-WeightADX); if (iADX(NULL,0,ADXPeriod,ADXPrice,MODE_PLUSDI,i) == iADX(NULL,0,ADXPeriod,RSIPrice,MODE_MINUSDI,i)) return(0); } else { return(0); } } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i, limit, counted_bars=IndicatorCounted(); //---- if (counted_bars > 0) counted_bars--; limit = Bars-counted_bars; //---- macd for (i = 0; i < limit; i++) TempBuffer[i] = MAClose(i)+MACD(i)+OsMA(i)+CCI(i)+MOM(i)+RSI(i)+ADX(i); //---- int max = MathMax(MAPeriod,MathMax(SlowPeriod,MathMax(CCIPeriod,MathMax(SlowMACD,MOMPeriod)))); //---- if (Bars <= max) return(0); //---- initial zero if (counted_bars < 1) for (i = 1; i <= max; i++) WaveBuffer[Bars-i] = 0.0; //---- i = Bars-max-1; if (counted_bars >= max) i = Bars-counted_bars-1; while(i >= 0) { if (MovWavePer > 1) { WaveBuffer[i] = iMAOnArray(TempBuffer,0,MovWavePer,0,MovWaveType,i); } else { WaveBuffer[i] = TempBuffer[i]; } i--; } return(0); } //+------------------------------------------------------------------+