//+------------------------------------------------------------------+ //| PriceSound_MA_Shift_Y.mq4 | //| Roll | //+------------------------------------------------------------------+ #property copyright "Roll" #property link "http://www.mql4.com/ru/users/Roll" /*Источники: 1.- индикатор Moving Averages(Custom Moving Average.mq4)из штатного набора пользовательских индикаторов терминала МТ4. MetaQuotes Software Corp.http://www.metaquotes.net/ 2. - индикатор PriceSound_trendline http://codebase.mql4.com/ru/7601 */ #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Magenta #property indicator_width1 2 //---- indicator parameters extern int MA_Period=13; extern int MA_Shift_Y=5;//Сдвиг МА по вертикали (в пунктах) extern int MA_Shift=10;//Сдвиг МА по горизонтали (в барах) extern int MA_Method=0;//метод построения МА: sma, ema, smma, lwma extern string UniqueName1="TL1"; //название трендовой линии extern bool Sound_Play=true; //разрешение на звук extern color LineColor_UP=Yellow; //цвет трендовой линии (направление вверх) extern color LineColor_DN=Magenta; //цвет трендовой линии (направление вниз) extern int LineWidth1=2; //ширина трендовой линии extern string Sound1="ready.wav";//название звукового файла для трендовой линии extern int Ind_Bar=0; //номер бара (смещение) для индикации пунктов extern int DistPips=0; //Если меньше 10-авт.установка.Регулировка расстояния от изображения числа пунктов до соотв.прямой int ExtCountedBars=0,i,k,pos,ArrShift,t,Shift=1; double ExtMapBuffer[],MA_ShiftY,sum,LastLevel,LastPrice,TradePoint; bool Active;string PipsTextName; static double lastLevel_1,lastPrice_1; //+------------------------------------------------------------------+ int init(){if(Digits==3||Digits==5){MA_Shift_Y=MA_Shift_Y*10;TradePoint=Point*10;} else{TradePoint=Point;MA_ShiftY=MA_Shift_Y*Point;}LastPrice=0;lastLevel_1=0; int draw_begin;string short_name; SetIndexStyle(0,DRAW_LINE);SetIndexShift(0,MA_Shift); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); if(MA_Period<2)MA_Period=13;draw_begin=MA_Period-1; switch(MA_Method) {case 1:short_name="EMA(";draw_begin=0;break;case 2:short_name="SMMA(";break; case 3:short_name="LWMA(";break;default:MA_Method=0;short_name="SMA(";} IndicatorShortName(short_name+MA_Period+")"); SetIndexDrawBegin(0,draw_begin);SetIndexBuffer(0,ExtMapBuffer); switch(Period()) {case PERIOD_M1: ArrShift=10 ;break;case PERIOD_M5: ArrShift=12;break; case PERIOD_M15:ArrShift=15 ;break;case PERIOD_M30:ArrShift=30;break; case PERIOD_H1: ArrShift=50 ;break;case PERIOD_H4:ArrShift=100;break; case PERIOD_D1: ArrShift=200 ;break;case PERIOD_W1:ArrShift=500;break; case PERIOD_MN1:ArrShift=1000;break;}return(0);} int deinit(){if(UninitializeReason()==REASON_REMOVE) {ObjectDelete(UniqueName1);PipsTextName=UniqueName1+" Pips";ObjectDelete(PipsTextName); lastLevel_1=0;lastPrice_1=0;}return(0);} //+------------------------------------------------------------------+ int start() {if(Bars<=MA_Period)return(0);ExtCountedBars=IndicatorCounted();if(ExtCountedBars<0)return(-1); if(ExtCountedBars>0)ExtCountedBars--; switch(MA_Method){case 0:sma();break;case 1:ema();break;case 2:smma();break;case 3:lwma();break;} double c1=ExtMapBuffer[MA_Shift];datetime c0=Time[0]+Shift*Period()*60; double c2=ExtMapBuffer[Shift];color LineColor; if(c1>c2)LineColor= LineColor_DN;if(c1<=c2)LineColor=LineColor_UP; if(ObjectFind(UniqueName1)!=0) {ObjectCreate(UniqueName1,OBJ_TREND,0,Time[0],c1,c0,c1);ObjectSetText(UniqueName1,"Price alert level1",0); ObjectSet(UniqueName1,OBJPROP_COLOR,LineColor);ObjectSet(UniqueName1,OBJPROP_WIDTH,LineWidth1);} if(ObjectFind(UniqueName1)==0){ObjectMove(UniqueName1,0,Time[2],c1);ObjectMove(UniqueName1,1,c0,c1); PriceSound_trendline(UniqueName1,LineColor,Sound1,ArrShift,lastLevel_1,lastPrice_1);}return(0);} //+---------------Simple Moving Average------------------------------+ void sma() {sum=0;pos=Bars-ExtCountedBars-1; if(pos=0) {sum+=Close[pos]; ExtMapBuffer[pos]=sum/MA_Period+MA_ShiftY; sum-=Close[pos+MA_Period-1];pos--;} if(ExtCountedBars<1)for(i=1;i2)pos=Bars-ExtCountedBars-1; while(pos>=0) {if(pos==Bars-2)ExtMapBuffer[pos+1]=Close[pos+1]+MA_ShiftY; ExtMapBuffer[pos]=(Close[pos]+MA_ShiftY)*pr+ExtMapBuffer[pos+1]*(1-pr);pos--;}} //+---------------Smoothed Moving Average ---------------------------+ void smma() {sum=0;pos=Bars-ExtCountedBars+1;pos=Bars-MA_Period; if(pos>Bars-ExtCountedBars) pos=Bars-ExtCountedBars; while(pos>=0) {if(pos==Bars-MA_Period) {for(i=0,k=pos;i=0) {ExtMapBuffer[pos]=sum/weight+MA_ShiftY; if(pos==0)break; pos--; i--; price=Close[pos]; sum=sum-lsum+price*MA_Period; lsum-=Close[i]; lsum+=price;} if(ExtCountedBars<1)for(i=1;i=10)ArrShift=DistPips;else ArrShift=arrShift; LastLevel=lastLevel;LastPrice=lastPrice; if(ObjectFind(PipsTextName)==-1){double cp=LastLevel;if(cp==0)cp=LastLevel+(10+ArrShift)*TradePoint; ObjectCreate(PipsTextName,OBJ_TEXT,0,Time[0],cp);}if(Ind_Bar>0)t=Ind_Bar;else t=0; ObjectSet(PipsTextName,OBJPROP_TIME1,Time[t]);double newlevel=ObjectGetValueByShift(UniqueName,0); if(Active){ObjectSet(UniqueName,OBJPROP_COLOR,LineColor);ObjectSetText(UniqueName,"Price sound level - Active",0); double Pips=MathAbs(NormalizeDouble((newlevel-Close[0])/TradePoint,Digits)); if(Digits==3||Digits==5)ObjectSetText(PipsTextName,DoubleToStr(Pips,1),14,"Terminal",LineColor); else ObjectSetText(PipsTextName,DoubleToStr(Pips,0),14,"Terminal",LineColor);} if(Close[0]>newlevel)ObjectSet(PipsTextName,OBJPROP_PRICE1,newlevel-ArrShift*TradePoint); if(Close[0]=LastLevel)||(LastPrice>LastLevel&&Close[0]<=LastLevel))) {if(Sound_Play)PlaySound(Sound);else Active=false;ObjectSetText(PipsTextName,"",14,"Terminal",LineColor); ObjectSetText(UniqueName,"Price sound level - Inactive",0);ObjectSet(UniqueName,OBJPROP_COLOR,Blue);} if(UniqueName==UniqueName1){lastLevel_1=LastLevel;lastPrice_1=Close[0];}} //-----------------------------------------------------+