//+------------------------------------------------------------------+ //| UniLineBreak_v2.8 600+.mq4 | //| Copyright © 2019, TrendLaboratory | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2003@yahoo.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2019, TrendLaboratory" #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" #property link "http://newdigital-world.com/forum.php" #property indicator_chart_window #property indicator_buffers 12 #property indicator_color1 clrLimeGreen #property indicator_color2 clrLightCoral #property indicator_width1 3 #property indicator_width2 3 #property indicator_color3 clrOrangeRed #property indicator_color4 clrDodgerBlue #property indicator_color5 clrDodgerBlue #property indicator_color6 clrOrangeRed #property indicator_color7 clrDodgerBlue #property indicator_color8 clrDodgerBlue #property indicator_color9 clrDodgerBlue #property indicator_color10 clrOrangeRed #property indicator_width9 2 #property indicator_width10 2 #property indicator_color11 clrAquamarine #property indicator_color12 clrDarkSalmon #property indicator_width11 2 #property indicator_width12 2 #property strict enum ENUM_PRICE { close, // Close open, // Open high, // High low, // Low median, // Median typical, // Typical weightedClose, // Weighted Close medianBody, // Median Body (Open+Close)/2 average, // Average (High+Low+Open+Close)/4 trendBiased, // Trend Biased trendBiasedExt, // Trend Biased(extreme) haClose, // Heiken Ashi Close haOpen, // Heiken Ashi Open haHigh, // Heiken Ashi High haLow, // Heiken Ashi Low haMedian, // Heiken Ashi Median haTypical, // Heiken Ashi Typical haWeighted, // Heiken Ashi Weighted Close haMedianBody, // Heiken Ashi Median Body haAverage, // Heiken Ashi Average haTrendBiased, // Heiken Ashi Trend Biased haTrendBiasedExt // Heiken Ashi Trend Biased(extreme) }; //---- input parameters input ENUM_TIMEFRAMES TimeFrame = 0; // Timeframe input ENUM_PRICE UpBandPrice = 0; // Upper Band Price input ENUM_PRICE LoBandPrice = 0; // Lower Band Price input int NumberLines = 3; // Number Lines input double MinHeight = 0; // Min Height in pips input int PreSmooth = 1; // PreSmoothing Period input int Pole = 1; // Pole: 1-EMA(1 pole),2-DEMA(2 poles),3-TEMA(3 poles),4-QEMA(4 poles)... input int Order = 1; // Smoothing Order(min. 1) input double WeightFactor = 2; // Weight Factor(ex.Wilder=1,EMA=2) input double DampingFactor = 1; // Damping Factor input bool ShowBars = true; // Show Bars input bool ShowLevels = false; // Show Levels input bool ShowSignals = false; // Show Signals input bool ShowBreakoutSignals = false; // Show Hi/Lo Breakout Signals input int CountBars = 0; // Number of bars counted: 0-all bars input string Alerts = "=== Alerts, Emails & Notifications ==="; input bool AlertOn = false; // Alert On/Off input int AlertShift = 1; // Alert Shift:0-current bar,1-previous bar input int SoundsNumber = 5; // Number of sounds after Signal input int SoundsPause = 5; // Pause in sec between sounds input string UpTrendSound = "alert.wav"; // Upflip Sound Name input string DnTrendSound = "alert2.wav"; // Downflip Sound Name input bool EmailOn = false; // Email On/Off input int EmailsNumber = 1; // Emails Number input bool PushNotificationOn = false; // Push Notification On/Off //---- indicator buffers double upTrendBar[]; double dnTrendBar[]; double uplevel[]; double upLevel1[]; double upLevel2[]; double dnlevel[]; double dnLevel1[]; double dnLevel2[]; double upSignal[]; double dnSignal[]; double upBreak[]; double dnBreak[]; double tlbtrend[]; double brktrend[]; int timeframe, number, sumlength, cBars, draw_begin; double _point, uphigh[2], dnlow[2]; string IndicatorName, TF; datetime brktime; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { timeframe = TimeFrame; if(timeframe <= Period()) timeframe = Period(); TF = tf(timeframe); IndicatorDigits(Digits); //---- indicator line IndicatorBuffers(14); SetIndexBuffer( 0,upTrendBar); SetIndexStyle( 0,DRAW_HISTOGRAM); SetIndexBuffer( 1,dnTrendBar); SetIndexStyle( 1,DRAW_HISTOGRAM); SetIndexBuffer( 2, uplevel); SetIndexStyle( 2, DRAW_LINE); SetIndexBuffer( 3, upLevel1); SetIndexStyle( 3, DRAW_LINE); SetIndexBuffer( 4, upLevel2); SetIndexStyle( 4, DRAW_LINE); SetIndexBuffer( 5, dnlevel); SetIndexStyle( 5, DRAW_LINE); SetIndexBuffer( 6, dnLevel1); SetIndexStyle( 6, DRAW_LINE); SetIndexBuffer( 7, dnLevel2); SetIndexStyle( 7, DRAW_LINE); SetIndexBuffer( 8, upSignal); SetIndexStyle( 8, DRAW_ARROW); SetIndexArrow( 8,233); SetIndexBuffer( 9, dnSignal); SetIndexStyle( 9, DRAW_ARROW); SetIndexArrow( 9,234); SetIndexBuffer(10, upBreak); SetIndexStyle(10, DRAW_ARROW); SetIndexArrow(10,233); SetIndexBuffer(11, dnBreak); SetIndexStyle(11, DRAW_ARROW); SetIndexArrow(11,234); SetIndexBuffer(12, tlbtrend); SetIndexBuffer(13, brktrend); //---- IndicatorName = WindowExpertName(); string short_name = IndicatorName + "["+TF+"]("+(string)UpBandPrice+","+(string)LoBandPrice+","+(string)NumberLines+")"; IndicatorShortName(short_name); SetIndexLabel( 0,"UniLineBreak Close"); SetIndexLabel( 1,"UniLineBreak Open" ); SetIndexLabel( 2,"Upper Level"); SetIndexLabel( 3,NULL); SetIndexLabel( 4,NULL); SetIndexLabel( 5,"Lower Level"); SetIndexLabel( 6,NULL); SetIndexLabel( 7,NULL); SetIndexLabel( 8,"Uptrend Signal"); SetIndexLabel( 9,"Dntrend Signal"); SetIndexLabel(10,"Hi Breakout Signal"); SetIndexLabel(11,"Lo Breakout Signal"); //---- sumlength = PreSmooth; if(CountBars == 0) cBars = timeframe/Period()*(iBars(NULL,timeframe) - sumlength); else cBars = CountBars*timeframe/Period(); draw_begin = Bars - cBars; SetIndexDrawBegin( 0,draw_begin); SetIndexDrawBegin( 1,draw_begin); SetIndexDrawBegin( 2,draw_begin); SetIndexDrawBegin( 3,draw_begin); SetIndexDrawBegin( 4,draw_begin); SetIndexDrawBegin( 5,draw_begin); SetIndexDrawBegin( 6,draw_begin); SetIndexDrawBegin( 7,draw_begin); SetIndexDrawBegin( 8,draw_begin); SetIndexDrawBegin( 9,draw_begin); SetIndexDrawBegin(10,draw_begin); SetIndexDrawBegin(11,draw_begin); //---- number = MathMax(NumberLines,1); ArrayResize(minprice,number); ArrayResize(maxprice,number); uniema_size = Pole*Order; ArrayResize(uniema_tmp,2*uniema_size); ArrayResize(uniema_prevtime,2); _point = Point*MathPow(10,Digits%2); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| UniLineBreak_v2.9 600+ | //+------------------------------------------------------------------+ int start() { int i,shift,limit = 0, counted_bars = IndicatorCounted(); if(counted_bars > 0) limit = Bars - counted_bars - 1; if(counted_bars < 0) return(0); if(counted_bars < 1) { limit = MathMin(Bars - 2,(cBars + sumlength)*timeframe/Period()); for(i=0;i 0) {upLevel1[shift] = uplevel[shift]; dnLevel1[shift] = dnlevel[shift];} } if(ShowSignals) { upSignal[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,NumberLines,MinHeight,PreSmooth,Pole,Order,WeightFactor,DampingFactor,ShowBars,ShowLevels,ShowSignals,ShowBreakoutSignals,CountBars, "",AlertOn,AlertShift,SoundsNumber,SoundsPause,UpTrendSound,DnTrendSound,EmailOn,EmailsNumber,PushNotificationOn,8,y); dnSignal[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,NumberLines,MinHeight,PreSmooth,Pole,Order,WeightFactor,DampingFactor,ShowBars,ShowLevels,ShowSignals,ShowBreakoutSignals,CountBars, "",AlertOn,AlertShift,SoundsNumber,SoundsPause,UpTrendSound,DnTrendSound,EmailOn,EmailsNumber,PushNotificationOn,9,y); } if(ShowBreakoutSignals) { upBreak[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,NumberLines,MinHeight,PreSmooth,Pole,Order,WeightFactor,DampingFactor,ShowBars,ShowLevels,ShowSignals,ShowBreakoutSignals,CountBars, "",AlertOn,AlertShift,SoundsNumber,SoundsPause,UpTrendSound,DnTrendSound,EmailOn,EmailsNumber,PushNotificationOn,10,y); dnBreak[shift] = iCustom(NULL,TimeFrame,IndicatorName,0,UpBandPrice,LoBandPrice,NumberLines,MinHeight,PreSmooth,Pole,Order,WeightFactor,DampingFactor,ShowBars,ShowLevels,ShowSignals,ShowBreakoutSignals,CountBars, "",AlertOn,AlertShift,SoundsNumber,SoundsPause,UpTrendSound,DnTrendSound,EmailOn,EmailsNumber,PushNotificationOn,11,y); } } if(ShowLevels) { for(shift=limit;shift>=0;shift--) { upLevel2[shift] = EMPTY_VALUE; dnLevel2[shift] = EMPTY_VALUE; if(uplevel[shift] > uplevel[shift+1]) { upLevel2[shift] = uplevel[shift]; upLevel2[shift+1] = uplevel[shift+1]; } if(dnlevel[shift] > dnlevel[shift+1]) { dnLevel2[shift] = dnlevel[shift]; dnLevel2[shift+1] = dnlevel[shift+1]; } } } if(CountBars > 0) { draw_begin = Bars - cBars; SetIndexDrawBegin( 0,draw_begin); SetIndexDrawBegin( 1,draw_begin); SetIndexDrawBegin( 2,draw_begin); SetIndexDrawBegin( 3,draw_begin); SetIndexDrawBegin( 4,draw_begin); SetIndexDrawBegin( 5,draw_begin); SetIndexDrawBegin( 6,draw_begin); SetIndexDrawBegin( 7,draw_begin); SetIndexDrawBegin( 8,draw_begin); SetIndexDrawBegin( 9,draw_begin); SetIndexDrawBegin(10,draw_begin); SetIndexDrawBegin(11,draw_begin); } return(0); } for(shift=limit;shift>=0;shift--) { double upBand = EMPTY_VALUE; double loBand = EMPTY_VALUE; tlbtrend[shift] = nLineBreak(upBand,loBand,UpBandPrice,LoBandPrice,number,MinHeight,PreSmooth,Pole,Order,WeightFactor,DampingFactor,shift); if(ShowBars) { upTrendBar[shift] = upBand; dnTrendBar[shift] = loBand; } if(shift > Bars - 4) continue; if(ShowLevels) { upLevel1[shift] = EMPTY_VALUE; upLevel2[shift] = EMPTY_VALUE; dnLevel1[shift] = EMPTY_VALUE; dnLevel2[shift] = EMPTY_VALUE; for(i=0;i<2;i++) { if(tlbtrend[shift+i] > 0) { if(upLevel1[shift+1+i] == EMPTY_VALUE) { if(upLevel1[shift+2+i] == EMPTY_VALUE) { upLevel1[shift+i] = uplevel[shift+i]; upLevel1[shift+1+i] = uplevel[shift+1+i]; upLevel2[shift+i] = EMPTY_VALUE; dnLevel1[shift+i] = dnlevel[shift+i]; dnLevel1[shift+1+i] = dnlevel[shift+1+i]; dnLevel2[shift+i] = EMPTY_VALUE; } else { upLevel2[shift+i] = uplevel[shift+i]; upLevel2[shift+1+i] = uplevel[shift+1+i]; upLevel1[shift+i] = EMPTY_VALUE; dnLevel2[shift+i] = dnlevel[shift+i]; dnLevel2[shift+1+i] = dnlevel[shift+1+i]; dnLevel1[shift+i] = EMPTY_VALUE; } } else { upLevel1[shift+i] = uplevel[shift+i]; upLevel2[shift+i] = EMPTY_VALUE; dnLevel1[shift+i] = dnlevel[shift+i]; dnLevel2[shift+i] = EMPTY_VALUE; } } } } if(ShowSignals) { upSignal[shift] = EMPTY_VALUE; dnSignal[shift] = EMPTY_VALUE; if(tlbtrend[shift] > 0 && tlbtrend[shift+1] < 0) upSignal[shift] = loband[0]; if(tlbtrend[shift] < 0 && tlbtrend[shift+1] > 0) dnSignal[shift] = upband[0]; } if(ShowBreakoutSignals) { if(brktime != Time[shift]) { uphigh[1] = uphigh[0]; dnlow[1] = dnlow[0]; brktime = Time[shift]; } uphigh[0] = uphigh[1]; dnlow[0] = dnlow[1]; if(tlbtrend[shift] > 0) { if(tlbtrend[shift+1] < 0) uphigh[0] = High[shift]; dnlow[0] = 0; } else { if(tlbtrend[shift+1] > 0) dnlow[0] = Low[shift]; uphigh[0] = 0; } brktrend[shift] = brktrend[shift+1]; if(Close[shift] > uphigh[0] && uphigh[0] > 0 && brktrend[shift+1] <= 0) brktrend[shift] = 1; if(Close[shift] < dnlow[0] && dnlow[0] > 0 && brktrend[shift+1] >= 0) brktrend[shift] =-1; upBreak[shift] = EMPTY_VALUE; dnBreak[shift] = EMPTY_VALUE; if(brktrend[shift] > 0) { if(brktrend[shift+1] != brktrend[shift]) { upBreak[shift] = loband[0]; uphigh[0] = 0; } } else { if(brktrend[shift+1] != brktrend[shift]) { dnBreak[shift] = upband[0]; dnlow[0] = 0; } } } } if(AlertOn || EmailOn || PushNotificationOn) { bool uptrend = (ShowSignals && tlbtrend[AlertShift] > 0 && tlbtrend[AlertShift+1] <= 0)||(ShowBreakoutSignals && upBreak[AlertShift] > 0 && upBreak[AlertShift] != EMPTY_VALUE); bool dntrend = (ShowSignals && tlbtrend[AlertShift] < 0 && tlbtrend[AlertShift+1] >= 0)||(ShowBreakoutSignals && dnBreak[AlertShift] > 0 && dnBreak[AlertShift] != EMPTY_VALUE); if(uptrend || dntrend) { if(isNewBar(timeframe)) { if(AlertOn) { BoxAlert(uptrend," : BUY Signal @ " +DoubleToStr(Close[AlertShift],Digits)); BoxAlert(dntrend," : SELL Signal @ "+DoubleToStr(Close[AlertShift],Digits)); } if(EmailOn) { EmailAlert(uptrend,"BUY" ," : BUY Signal @ " +DoubleToStr(Close[AlertShift],Digits),EmailsNumber); EmailAlert(dntrend,"SELL"," : SELL Signal @ "+DoubleToStr(Close[AlertShift],Digits),EmailsNumber); } if(PushNotificationOn) { PushAlert(uptrend," : BUY Signal @ " +DoubleToStr(Close[AlertShift],Digits)); PushAlert(dntrend," : SELL Signal @ "+DoubleToStr(Close[AlertShift],Digits)); } } else { if(AlertOn) { WarningSound(uptrend,SoundsNumber,SoundsPause,UpTrendSound,Time[AlertShift]); WarningSound(dntrend,SoundsNumber,SoundsPause,DnTrendSound,Time[AlertShift]); } } } } if(CountBars > 0) { draw_begin = Bars - cBars; SetIndexDrawBegin( 0,draw_begin); SetIndexDrawBegin( 1,draw_begin); SetIndexDrawBegin( 2,draw_begin); SetIndexDrawBegin( 3,draw_begin); SetIndexDrawBegin( 4,draw_begin); SetIndexDrawBegin( 5,draw_begin); SetIndexDrawBegin( 6,draw_begin); SetIndexDrawBegin( 7,draw_begin); SetIndexDrawBegin( 8,draw_begin); SetIndexDrawBegin( 9,draw_begin); SetIndexDrawBegin(10,draw_begin); SetIndexDrawBegin(11,draw_begin); } return(0); } //---- int trend[2], upcount[2], dncount[2]; double mprice[2], hiprice[2], loprice[2], upband[2], loband[2], minprice[][2], maxprice[][2]; datetime prevtime; int nLineBreak(double& uptrend,double& dntrend,int upp,int lop,int num,double minh,int presm,int pole,int order,double wf,double df,int bar) { int i; double upPrice = 0, loPrice = 0; if(prevtime != Time[bar]) { hiprice[1] = hiprice[0]; loprice[1] = loprice[0]; upcount[1] = upcount[0]; dncount[1] = dncount[0]; upband[1] = upband[0]; loband[1] = loband[0]; trend[1] = trend[0]; for(i=num-1;i>=0;i--) {maxprice[i][1] = maxprice[i][0]; minprice[i][1] = minprice[i][0];} prevtime = Time[bar]; } if(upp <= 10) upPrice = getPrice(upp,bar); else if(upp > 10 && upp <= 21) upPrice = HeikenAshi(0,upp-11,MathMin(Bars-1,cBars+sumlength),bar); if(lop <= 10) loPrice = getPrice(lop,bar); else if(lop > 10 && lop <= 21) loPrice = HeikenAshi(1,lop-11,MathMin(Bars-1,cBars+sumlength),bar); if(bar > MathMin(Bars-1,cBars+sumlength) - presm) return(EMPTY_VALUE); hiprice[0] = NormalizeDouble(UniXMA(0,upPrice,presm,pole,order,wf,df,MathMin(Bars-1,cBars+sumlength) - presm,bar),_Digits); loprice[0] = NormalizeDouble(UniXMA(1,loPrice,presm,pole,order,wf,df,MathMin(Bars-1,cBars+sumlength) - presm,bar),_Digits); if(bar == MathMin(Bars-1,cBars+sumlength) - presm) { if(hiprice[0] >= hiprice[1]) { trend[0] = 1; upcount[0] = 0; } else if(loprice[0] < loprice[1]) { trend[0] =-1; dncount[0] = 0; } maxprice[0][0] = hiprice[0]; minprice[0][0] = loprice[0]; for(i=num-1;i>0;i--) {maxprice[i][0] = maxprice[i-1][0]; minprice[i][0] = minprice[i-1][0];} upband[0] = maxprice[0][0]; loband[0] = minprice[0][0]; } else if(bar < MathMin(Bars-1,cBars+sumlength) - presm) { trend[0] = trend[1]; upband[0] = upband[1]; loband[0] = loband[1]; upcount[0] = upcount[1]; dncount[0] = dncount[1]; for(i=num-1;i>=0;i--) {maxprice[i][0] = maxprice[i][1]; minprice[i][0] = minprice[i][1];} if(hiprice[0] > upband[0] + minh*_point && hiprice[0] > hiprice[1] && trend[1] < 0) {trend[0] = 1; upcount[0] = 0;} if(loprice[0] < loband[0] - minh*_point && loprice[0] < loprice[1] && trend[1] > 0) {trend[0] =-1; dncount[0] = 0;} if(trend[0] > 0) { if(hiprice[0] - maxprice[0][0] > minh*_point) { for(i=num-1;i>0;i--) maxprice[i][0] = maxprice[i-1][0]; maxprice[0][0] = hiprice[0]; for(i=num-1;i>0;i--) minprice[i][0] = minprice[i-1][0]; minprice[0][0] = maxprice[0][1]; if(trend[1] > 0) upcount[0] = upcount[0] + 1; } if(trend[1] < 0) loband[0] = minprice[0][1]; else { if(upcount[0] <= num-1) loband[0] = loband[1]; else if(upcount[0] > num-1) loband[0] = minprice[num-1][0]; } upband[0] = maxprice[0][0]; uptrend = maxprice[0][0]; dntrend = minprice[0][0]; } if(trend[0] < 0) { if(minprice[0][0] - loprice[0] > minh*_point ) { for(i=num-1;i>0;i--) minprice[i][0] = minprice[i-1][0]; minprice[0][0] = loprice[0]; for(i=num-1;i>0;i--) maxprice[i][0] = maxprice[i-1][0]; maxprice[0][0] = minprice[0][1]; if(trend[1] < 0) dncount[0] = dncount[0] + 1; } if(trend[1] > 0) upband[0] = maxprice[0][1]; else { if(dncount[0] <= num - 1) upband[0] = upband[1]; else if(dncount[0] > num - 1) upband[0] = maxprice[num-1][0]; } loband[0] = minprice[0][0]; uptrend = minprice[0][0]; dntrend = maxprice[0][0]; } if(ShowLevels) { uplevel[bar] = upband[0]; dnlevel[bar] = loband[0]; } } return(trend[0]); } //----- int uniema_size; double uniema_tmp[][2]; datetime uniema_prevtime[]; double UniXMA(int index,double price,int len,int pole,int order,double wf,double df,int cbars,int bar) { int j, k, m = index*uniema_size; double uniema = price, alpha = (wf*order)/(len + wf*order-1); if(uniema_prevtime[index] != Time[bar]) { for(k=0;k= cbars - 1) uniema_tmp[m+pole*k+j][0] = price; else { uniema_tmp[m+pole*k+j][0] = (1 - alpha)*uniema_tmp[m+pole*k+j][1] + alpha*uniema; if(j > 0) uniema += df*(uniema_tmp[m+pole*k][0] - uniema_tmp[m+pole*k+j][0]); else uniema = uniema_tmp[m+pole*k+j][0]; } } } return(uniema); } double getPrice(int price,int bar) { double close = Close[bar]; double open = Open [bar]; double high = High [bar]; double low = Low [bar]; switch(price) { case 0: return(close); break; case 1: return(open ); break; case 2: return(high ); break; case 3: return(low ); break; case 4: return((high + low)/2); break; case 5: return((high + low + close)/3); break; case 6: return((high + low + 2*close)/4); break; case 7: return((close + open)/2); break; case 8: return((high + low + close + open)/4); break; case 9: if(close > open) return((high + close)/2); else return((low + close)/2); break; case 10: if(close > open) return(high); else return(low); break; default: return(close); break; } } // HeikenAshi Price double haClose[2][2], haOpen[2][2], haHigh[2][2], haLow[2][2]; datetime prevhatime[2]; double HeikenAshi(int index,int price,int cbars,int bar) { if(prevhatime[index] != Time[bar]) { haClose[index][1] = haClose[index][0]; haOpen [index][1] = haOpen [index][0]; haHigh [index][1] = haHigh [index][0]; haLow [index][1] = haLow [index][0]; prevhatime[index] = Time[bar]; } if(bar == cbars) { haClose[index][0] = Close[bar]; haOpen [index][0] = Open [bar]; haHigh [index][0] = High [bar]; haLow [index][0] = Low [bar]; } else if(bar < cbars) { haClose[index][0] = (Open[bar] + High[bar] + Low[bar] + Close[bar])/4; haOpen [index][0] = (haOpen[index][1] + haClose[index][1])/2; haHigh [index][0] = MathMax(High[bar],MathMax(haOpen[index][0],haClose[index][0])); haLow [index][0] = MathMin(Low [bar],MathMin(haOpen[index][0],haClose[index][0])); } switch(price) { case 0: return(haClose[index][0]); break; case 1: return(haOpen [index][0]); break; case 2: return(haHigh [index][0]); break; case 3: return(haLow [index][0]); break; case 4: return((haHigh [index][0] + haLow [index][0])/2); break; case 5: return((haHigh[index][0] + haLow[index][0] + haClose[index][0])/3); break; case 6: return((haHigh[index][0] + haLow[index][0] + 2*haClose[index][0])/4); break; case 7: return((haClose[index][0] + haOpen[index][0])/2); break; case 8: return((haHigh[index][0] + haLow[index][0] + haClose[index][0] + haOpen[index][0])/4); break; case 9: if(haClose[index][0] > haOpen[index][0]) return((haHigh[index][0] + haClose[index][0])/2); else return((haLow[index][0] + haClose[index][0])/2); break; case 10: if(haClose[index][0] > haOpen[index][0]) return(haHigh[index][0]); else return(haLow[index][0]); break; default: return(haClose[index][0]); break; } } string tf(int itimeframe) { string result = ""; switch(itimeframe) { case PERIOD_M1: result = "M1" ; case PERIOD_M5: result = "M5" ; case PERIOD_M15: result = "M15"; case PERIOD_M30: result = "M30"; case PERIOD_H1: result = "H1" ; case PERIOD_H4: result = "H4" ; case PERIOD_D1: result = "D1" ; case PERIOD_W1: result = "W1" ; case PERIOD_MN1: result = "MN1"; default: result = "N/A"; } if(result == "N/A") { if(itimeframe < PERIOD_H1 ) result = "M" + (string)itimeframe; if(itimeframe >= PERIOD_H1 ) result = "H" + (string)(itimeframe/PERIOD_H1); if(itimeframe >= PERIOD_D1 ) result = "D" + (string)(itimeframe/PERIOD_D1); if(itimeframe >= PERIOD_W1 ) result = "W" + (string)(itimeframe/PERIOD_W1); if(itimeframe >= PERIOD_MN1) result = "MN" + (string)(itimeframe/PERIOD_MN1); } return(result); } datetime prevnbtime; bool isNewBar(int tf) { bool res = false; if(tf >= 0) { if(iTime(NULL,tf,0) != prevnbtime) { res = true; prevnbtime = iTime(NULL,tf,0); } } else res = true; return(res); } string prevmess; bool BoxAlert(bool cond,string text) { string mess = IndicatorName + "("+Symbol()+","+TF + ")" + text; if (cond && mess != prevmess) { Alert (mess); prevmess = mess; return(true); } return(false); } datetime pausetime; bool Pause(int sec) { if(TimeLocal() >= pausetime + sec) {pausetime = TimeLocal(); return(true);} return(false); } datetime warningtime; void WarningSound(bool cond,int num,int sec,string sound,datetime curtime) { static int i; if(cond) { if(curtime != warningtime) i = 0; if(i < num && Pause(sec)) {PlaySound(sound); warningtime = curtime; i++;} } } string prevemail; bool EmailAlert(bool cond,string text1,string text2,int num) { string subj = "New " + text1 +" Signal from " + IndicatorName + "!!!"; string mess = IndicatorName + "("+Symbol()+","+TF + ")" + text2; if (cond && mess != prevemail) { if(subj != "" && mess != "") for(int i=0;i