//+------------------------------------------------------------------+ //| PriceSound_channel.mq4 | //| Roll | //| Канал со звуком. | //+------------------------------------------------------------------+ #property copyright "Roll" #property link "http://www.mql4.com/ru/users/Roll" #property indicator_chart_window /* Источники: 1)- индикатор PriceAlert(v.1.1)от api.http://codebase.mql4.com/download/17987. Индикатор PriceAlert работает с горизонтальной(ми) линией(ми). "Индикатор автоматически определяет момент пересечения ценой линии и активизирует сигнал"(api). 2)- Индикатор PriceSound_trendline от Roll.http://codebase.mql4.com/ru/7601. Индикатор PriceSound_trendline работает с трендовой(ми) линией(ми) Для сигнала предпочтение отдается звуку,поэтому звуковой файл должен быть индивидуальным и продолжительностью проигрывания несколько секунд). На графике может находится несколько таких трендовых линий с различными названиями (несколько индикаторов PriceSound_trendline). ======================================================================= - Индикатор PriceSound_channel работает с "каналами",которые сопровождают трендовые линии. Работает в тестере. В индикаторе используется функция,выполненная из индикатора PriceSound_trendline. То есть индикатор PriceSound_channel имеет свойства,характерные для индикатора PriceSound_trendline. ======================================================================== */ extern bool Sound_Play=true; //разрешение на звук extern string UniqueName1="Trend_Price 1";//название 1 трендовой линии extern color LineColor1=Pink; //цвет 1 линии extern int LineWidth1=2; //ширина 1 линии extern string Sound1="ready.wav"; //название звукового файла для 1 трендовой линии extern string UniqueName2="Trend_Price 2";//название 2 трендовой линии extern color LineColor2=YellowGreen; //цвет 2 линии extern int LineWidth2=2; //ширина 2 линии extern string Sound2="ready.wav"; //название звукового файла для 2 трендовой линии extern color ChannelColor=DarkTurquoise; //цвет канала extern bool Create_Channel=true; //разрешение/запрет на образование канала extern string Name_Channel="Channel_1"; //название канала extern bool Del_Channel=false; //запрет/разрешение на удаление заданного канала int ArrShift;bool Active;string PipsTextName; double LastLevel,LastPrice,TradePoint; static double lastLevel_1,lastLevel_2,lastPrice_1,lastPrice_2; int init() {if(Digits==3||Digits==5)TradePoint=Point*10;else TradePoint=Point; LastPrice=0;lastLevel_1=0;lastLevel_2=0;lastPrice_1=0;lastPrice_2=0;Active=true;return(0);} int deinit() {if(UninitializeReason()==REASON_REMOVE) {ObjectDelete(Name_Channel);ObjectDelete(UniqueName1);ObjectDelete(UniqueName2);PipsTextName=UniqueName1+" Pips";ObjectDelete(PipsTextName); PipsTextName=UniqueName2+" Pips";ObjectDelete(PipsTextName);lastLevel_2=0;lastLevel_1=0;}return(0);} //+--------Custom indicator iteration function-----------------------+ int start() {datetime c0,cc0,c2,cc2,c4;double c1,c3,cc1,cc3,c5,a,b,c,cp,cp2; switch(Period()) {case PERIOD_M1: if(Period()==PERIOD_M1) {ArrShift=10; break;} case PERIOD_M5: if(Period()==PERIOD_M5) {ArrShift=12; break;} case PERIOD_M15:if(Period()==PERIOD_M15){ArrShift=15; break;} case PERIOD_M30:if(Period()==PERIOD_M30){ArrShift=30; break;} case PERIOD_H1: if(Period()==PERIOD_H1) {ArrShift=50; break;} case PERIOD_H4: if(Period()==PERIOD_H4) {ArrShift=100;break;} case PERIOD_D1: if(Period()==PERIOD_D1) {ArrShift=200;break;} case PERIOD_W1: if(Period()==PERIOD_W1) {ArrShift=500;break;} case PERIOD_MN1:if(Period()==PERIOD_MN1){ArrShift=1000;break;}} if(Del_Channel) {if(ObjectFind(UniqueName1)==0) PriceSound_trendline(UniqueName1,LineColor1,Sound1,ArrShift,lastLevel_1,lastPrice_1); if(ObjectFind(UniqueName2)==0) PriceSound_trendline(UniqueName2,LineColor2,Sound2,ArrShift,lastLevel_2,lastPrice_2); if(ObjectFind(Name_Channel)==0)ObjectDelete(Name_Channel);return(0);} if(ObjectFind(Name_Channel)!=0&&Create_Channel) {cp=Close[0]+(10+ArrShift)*TradePoint;cp2=cp+ArrShift*TradePoint; ObjectCreate(Name_Channel,OBJ_CHANNEL,0,Time[25],cp,Time[0],cp,Time[12],cp2); ObjectSet(Name_Channel,OBJPROP_COLOR,ChannelColor); ObjectSet(Name_Channel,OBJPROP_STYLE,1);} else if((ObjectFind(Name_Channel)==0&&!Create_Channel)||ObjectFind(Name_Channel)==0) {if(ObjectFind(Name_Channel)==0&&!Create_Channel) {ObjectSet(Name_Channel,OBJPROP_COLOR,ChannelColor); ObjectSet(Name_Channel,OBJPROP_STYLE,1);} c0=ObjectGet(Name_Channel,0);c1=ObjectGet(Name_Channel,1);c2=ObjectGet(Name_Channel,2); c3=ObjectGet(Name_Channel,3);c4=ObjectGet(Name_Channel,4);c5=ObjectGet(Name_Channel,5);} else if(ObjectFind(Name_Channel)!=0){Alert("No Channel - ",Name_Channel," !");Sleep(3000); return(0);} if(ObjectFind(UniqueName1)!=0) {ObjectCreate(UniqueName1,OBJ_TREND,0,c0,c1,c2,c3);ObjectSetText(UniqueName1,"Price alert level1",0); ObjectSet(UniqueName1,OBJPROP_COLOR,LineColor1);ObjectSet(UniqueName1,OBJPROP_WIDTH,LineWidth1);} if(ObjectFind(UniqueName1)==0) {ObjectMove(UniqueName1,0,c0,c1);ObjectMove(UniqueName1,1,c2,c3); PriceSound_trendline(UniqueName1,LineColor1,Sound1,ArrShift,lastLevel_1,lastPrice_1);} if(ObjectFind(UniqueName2)!=0) {a=ObjectGetValueByShift(UniqueName1,c2);a=a+c5;cc1=a; ObjectCreate(UniqueName2,OBJ_TREND,0,c0,cc1,c4,c5);ObjectSetText(UniqueName2,"Price alert level2",0); ObjectSet(UniqueName2,OBJPROP_COLOR,LineColor2);ObjectSet(UniqueName2,OBJPROP_WIDTH,LineWidth2);} if(ObjectFind(UniqueName2)==0) {int t=iBarShift(0,0,c4); a=ObjectGetValueByShift(UniqueName1,t);b=ObjectGet(UniqueName1,1);cc1=b+(c5-a); ObjectMove(UniqueName2,0,c0,cc1);ObjectMove(UniqueName2,1,c4,c5); PriceSound_trendline(UniqueName2,LineColor2,Sound2,ArrShift,lastLevel_2,lastPrice_2);} return(0);} //+------------------------------------------------------------------+ void PriceSound_trendline(string UniqueName,color LineColor,string Sound,int arrShift,double lastLevel,double lastPrice) {PipsTextName=StringConcatenate(UniqueName," ","Pips"); ArrShift=arrShift;LastLevel=lastLevel;LastPrice=lastPrice; if(ObjectFind(PipsTextName)==-1) {double cp=LastLevel;if(cp==0)cp=Close[0]+(10+ArrShift)*TradePoint; ObjectCreate(PipsTextName,OBJ_TEXT,0,Time[0],cp);} ObjectSet(PipsTextName,OBJPROP_TIME1,Time[0]); 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];} if(UniqueName==UniqueName2){lastLevel_2=LastLevel;lastPrice_2=Close[0];}} //+------------------------------------------------------------------+