AllTrendEnvelopes_v1.1.mq4
AllTrendEnvelopes_v1.1.mq4 FOREX MetaTrader4 Indicators Download
AllTrendEnvelopes_v1.1.mq4 download link will appear after 10 seconds.
AllTrendEnvelopes_v1.1.mq4 Programming source code.
// List of MAs: // MA_Method= 0: SMA - Simple Moving Average // MA_Method= 1: EMA - Exponential Moving Average // MA_Method= 2: Wilder - Wilder Exponential Moving Average // MA_Method= 3: LWMA - Linear Weighted Moving Average // MA_Method= 4: SineWMA - Sine Weighted Moving Average // MA_Method= 5: TriMA - Triangular Moving Average // MA_Method= 6: LSMA - Least Square Moving Average (or EPMA, Linear Regression Line) // MA_Method= 7: SMMA - Smoothed Moving Average // MA_Method= 8: HMA - Hull Moving Average by Alan Hull // MA_Method= 9: ZeroLagEMA - Zero-Lag Exponential Moving Average // MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy // MA_Method=11: T3 - T3 by T.Tillson // MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers // MA_Method=13: Median - Moving Median // MA_Method=14: GeoMean - Geometric Mean // MA_Method=15: REMA - Regularized EMA by Chris Satchwell // MA_Method=16: ILRS - Integral of Linear Regression Slope // MA_Method=17: IE/2 - Combination of LSMA and ILRS // MA_Method=18: TriMAgen - Triangular Moving Average generalized by J.Ehlers // MA_Method=19: VWMA - Volume Weighted Moving Average // MA_Method=20: JSmooth - Smoothing by Mark Jurik // List of Prices: // Price = 0 - Close // Price = 1 - Open // Price = 2 - High // Price = 3 - Low // Price = 4 - Median Price = (High+Low)/2 // Price = 5 - Typical Price = (High+Low+Close)/3 // Price = 6 - Weighted Close = (High+Low+Close*2)/4 // Price = 7 - Heiken Ashi Close // Price = 8 - Heiken Ashi Open // Price = 9 - Heiken Ashi High // Price =10 - Heiken Ashi Low #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 LightBlue #property indicator_color2 Tomato #property indicator_width1 2 #property indicator_width2 2 #property indicator_color3 LightBlue #property indicator_color4 Tomato #property indicator_width3 1 #property indicator_width4 1 //---- extern int TimeFrame = 0; //TimeFrame in min extern int UpBandPrice = 2; //Upper Band's Price = 0...10 (see List of Prices) extern int LoBandPrice = 3; //Lower Band's Price = 0...10 (see List of Prices) extern int UpBandPeriod = 10; //Upper Band's Period extern int LoBandPeriod = 10; //Lower Band's Period extern int UpBandMethod = 0; //Upper Band MA's Method = 0...20 (see List of MAs) extern int LoBandMethod = 0; //Lower Band MA's Mathod = 0...20 (see List of MAs) extern double UpBandDeviation = 0.0; //Upper Band's Deviation in decimals extern double LoBandDeviation = 0.0; //Lower Band's Deviation in decimals extern int SignalMode = 1; //Switch of Signal mode(0-off,1-on) extern int AlertMode = 1; //Sound Alert switch(0...2) extern int WarningMode = 0; //Warning Mode (0-off,1-on) double UpTrend[]; double DnTrend[]; double UpSignal[]; double DnSignal[]; double sig[]; //---- double tmp[][12]; double haClose[][2], haOpen[][2], haHigh[][2], haLow[][2]; int draw_begin, mBars, pBars, mcnt_bars; string up_name, lo_name; datetime pTime; bool UpTrendAlert=false, DnTrendAlert=false; string TF; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); if(SignalMode > 0) { SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,108); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,108); } if(TimeFrame == 0 || TimeFrame < Period()) TimeFrame = Period(); draw_begin=MathMax(UpBandPeriod,LoBandPeriod)*TimeFrame/Period(); //---- switch(LoBandMethod) { case 1 : up_name="EMA("; break; case 2 : up_name="Wilder("; break; case 3 : up_name="LWMA("; break; case 4 : up_name="SineWMA("; break; case 5 : up_name="TriMA("; break; case 6 : up_name="LSMA("; break; case 7 : up_name="SMMA("; break; case 8 : up_name="HMA("; break; case 9 : up_name="ZeroLagEMA("; break; case 10: up_name="DEMA("; break; case 11: up_name="T3("; break; case 12: up_name="InstTrend("; break; case 13: up_name="Median("; break; case 14: up_name="GeometricMean("; break; case 15: up_name="REMA("; break; case 16: up_name="ILRS("; break; case 17: up_name="IE/2("; break; case 18: up_name="TriMA_gen("; break; case 19: up_name="VWMA("; break; case 20: up_name="JSmooth("; break; default: LoBandMethod=0; up_name="SMA("; } switch(UpBandMethod) { case 1 : lo_name="EMA("; break; case 2 : lo_name="Wilder("; break; case 3 : lo_name="LWMA("; break; case 4 : lo_name="SineWMA("; break; case 5 : lo_name="TriMA("; break; case 6 : lo_name="LSMA("; break; case 7 : lo_name="SMMA("; break; case 8 : lo_name="HMA("; break; case 9 : lo_name="ZeroLagEMA("; break; case 10: lo_name="DEMA("; break; case 11: lo_name="T3("; break; case 12: lo_name="InstTrend("; break; case 13: lo_name="Median("; break; case 14: lo_name="GeometricMean("; break; case 15: lo_name="REMA("; break; case 16: lo_name="ILRS("; break; case 17: lo_name="IE/2("; break; case 18: lo_name="TriMA_gen("; break; case 19: lo_name="VWMA("; break; case 20: lo_name="JSmooth("; break; default: UpBandMethod=0; lo_name="SMA("; } switch(TimeFrame) { case 1 : TF = "M1"; break; case 5 : TF = "M5"; break; case 15 : TF = "M15"; break; case 30 : TF = "M30"; break; case 60 : TF = "H1"; break; case 240 : TF = "H4"; break; case 1440 : TF = "D1"; break; case 10080 : TF = "W1"; break; case 43200 : TF = "MN1"; break; default : TF = "Current"; } SetIndexDrawBegin(0,draw_begin); SetIndexLabel(0,"UpTrend["+TF+"]("+LoBandPrice+","+up_name+LoBandPeriod+","+DoubleToStr(LoBandDeviation,4)+")"); SetIndexLabel(1,"DnTrend["+TF+"]("+UpBandPrice+","+lo_name+UpBandPeriod+","+DoubleToStr(UpBandDeviation,4)+")"); if(SignalMode > 0) { SetIndexLabel(2,"UpSignal["+TF+"]("+LoBandPrice+","+up_name+LoBandPeriod+","+DoubleToStr(LoBandDeviation,4)+")"); SetIndexLabel(3,"DnSignal["+TF+"]("+UpBandPrice+","+lo_name+UpBandPeriod+","+DoubleToStr(UpBandDeviation,4)+")"); } //---- SetIndexDrawBegin(0,draw_begin); SetIndexDrawBegin(1,draw_begin); //---- IndicatorBuffers(5); SetIndexBuffer(0,UpTrend); SetIndexBuffer(1,DnTrend); if(SignalMode > 0) { SetIndexBuffer(2,UpSignal); SetIndexBuffer(3,DnSignal); SetIndexDrawBegin(2,draw_begin); SetIndexDrawBegin(3,draw_begin); } SetIndexBuffer(4,sig); //---- return(0); } //+------------------------------------------------------------------+ //| AllTrendEnvelopes_v1.1 | //+------------------------------------------------------------------+ int start() { int limit, y, i, shift, cnt_bars=IndicatorCounted(); double upPrice[], loPrice[], mUpMA[], mLoMA[], mUp[], mLo[], mUpsig[], mDnsig[], mUpTrend[], mDnTrend[],trend[]; if(TimeFrame!=Period()) mBars = iBars(NULL,TimeFrame); else mBars = Bars; if(mBars != pBars) { ArrayResize(upPrice,mBars); ArrayResize(loPrice,mBars); ArrayResize(mUpMA,mBars); ArrayResize(mLoMA,mBars); ArrayResize(mUp,mBars); ArrayResize(mLo,mBars); ArrayResize(trend,mBars); ArrayResize(mUpTrend,mBars); ArrayResize(mDnTrend,mBars); if(SignalMode > 0) { ArrayResize(mUpsig,mBars); ArrayResize(mDnsig,mBars); } if((UpBandMethod==10 || UpBandMethod==11 || UpBandMethod==20) || (LoBandMethod==10 || LoBandMethod==11 || LoBandMethod==20)) ArrayResize(tmp,mBars); if((UpBandPrice > 6 && UpBandPrice <= 10) || (LoBandPrice > 6 && LoBandPrice <= 10)) { ArrayResize(haClose,mBars); ArrayResize(haOpen,mBars); ArrayResize(haHigh,mBars); ArrayResize(haLow,mBars); } pBars = mBars; } if(cnt_bars<1) { for(i=1;i<=draw_begin;i++) { UpTrend[Bars-i] = EMPTY_VALUE; DnTrend[Bars-i] = EMPTY_VALUE; UpSignal[Bars-i]= EMPTY_VALUE; DnSignal[Bars-i]= EMPTY_VALUE; } mcnt_bars = 0; } //---- if(mcnt_bars > 0) mcnt_bars--; for(y=mcnt_bars;y6 && UpBandPrice <= 10) upPrice[y] = HeikenAshi(0,TimeFrame,UpBandPrice-7,mBars-y-1); if(LoBandPrice <= 6) loPrice[y] = iMA(NULL,TimeFrame,1,0,0,LoBandPrice,mBars-y-1); else if(LoBandPrice > 6 && LoBandPrice <= 10) loPrice[y] = HeikenAshi(1,TimeFrame,LoBandPrice-7,mBars-y-1); switch(UpBandMethod) { case 1 : mUpMA[y] = EMA(upPrice[y],mUpMA,UpBandPeriod,y); break; case 2 : mUpMA[y] = Wilder(upPrice,mUpMA,UpBandPeriod,y); break; case 3 : mUpMA[y] = LWMA(upPrice,UpBandPeriod,y); break; case 4 : mUpMA[y] = SineWMA(upPrice,UpBandPeriod,y); break; case 5 : mUpMA[y] = TriMA(upPrice,UpBandPeriod,y); break; case 6 : mUpMA[y] = LSMA(upPrice,UpBandPeriod,y); break; case 7 : mUpMA[y] = SMMA(upPrice,mUpMA,UpBandPeriod,y); break; case 8 : mUpMA[y] = HMA(upPrice,UpBandPeriod,y); break; case 9 : mUpMA[y] = ZeroLagEMA(upPrice,mUpMA,UpBandPeriod,y); break; case 10: mUpMA[y] = DEMA(0,upPrice[y],UpBandPeriod,1,y); break; case 11: mUpMA[y] = T3(0,upPrice[y],UpBandPeriod,0.7,y); break; case 12: mUpMA[y] = ITrend(upPrice,mUpMA,UpBandPeriod,y); break; case 13: mUpMA[y] = Median(upPrice,UpBandPeriod,y); break; case 14: mUpMA[y] = GeoMean(upPrice,UpBandPeriod,y); break; case 15: mUpMA[y] = REMA(upPrice[y],mUpMA,UpBandPeriod,0.5,y); break; case 16: mUpMA[y] = ILRS(upPrice,UpBandPeriod,y); break; case 17: mUpMA[y] = IE2(upPrice,UpBandPeriod,y); break; case 18: mUpMA[y] = TriMA_gen(upPrice,UpBandPeriod,y); break; case 19: mUpMA[y] = VWMA(upPrice,UpBandPeriod,y); break; case 20: mUpMA[y] = JSmooth(0,upPrice[y],UpBandPeriod,1,y); break; default: mUpMA[y] = SMA(upPrice,UpBandPeriod,y); break; } switch(LoBandMethod) { case 1 : mLoMA[y] = EMA(loPrice[y],mLoMA,LoBandPeriod,y); break; case 2 : mLoMA[y] = Wilder(loPrice,mLoMA,LoBandPeriod,y); break; case 3 : mLoMA[y] = LWMA(loPrice,LoBandPeriod,y); break; case 4 : mLoMA[y] = SineWMA(loPrice,LoBandPeriod,y); break; case 5 : mLoMA[y] = TriMA(loPrice,LoBandPeriod,y); break; case 6 : mLoMA[y] = LSMA(loPrice,LoBandPeriod,y); break; case 7 : mLoMA[y] = SMMA(loPrice,mLoMA,LoBandPeriod,y); break; case 8 : mLoMA[y] = HMA(loPrice,LoBandPeriod,y); break; case 9 : mLoMA[y] = ZeroLagEMA(loPrice,mLoMA,LoBandPeriod,y); break; case 10: mLoMA[y] = DEMA(6,loPrice[y],LoBandPeriod,1,y); break; case 11: mLoMA[y] = T3(6,loPrice[y],LoBandPeriod,0.7,y); break; case 12: mLoMA[y] = ITrend(loPrice,mLoMA,LoBandPeriod,y); break; case 13: mLoMA[y] = Median(loPrice,LoBandPeriod,y); break; case 14: mLoMA[y] = GeoMean(loPrice,LoBandPeriod,y); break; case 15: mLoMA[y] = REMA(loPrice[y],mLoMA,LoBandPeriod,0.5,y); break; case 16: mLoMA[y] = ILRS(loPrice,LoBandPeriod,y); break; case 17: mLoMA[y] = IE2(loPrice,LoBandPeriod,y); break; case 18: mLoMA[y] = TriMA_gen(loPrice,LoBandPeriod,y); break; case 19: mLoMA[y] = VWMA(loPrice,LoBandPeriod,y); break; case 20: mLoMA[y] = JSmooth(6,loPrice[y],LoBandPeriod,1,y); break; default: mLoMA[y] = SMA(loPrice,LoBandPeriod,y); break; } mUp[y] = mUpMA[y]*(1+UpBandDeviation); mLo[y] = mLoMA[y]*(1-LoBandDeviation); trend[y] = trend[y-1]; if(iClose(NULL,TimeFrame,mBars-y-1) > mUp[y-1] && trend[y-1]<=0) trend[y]= 1; if(iClose(NULL,TimeFrame,mBars-y-1) < mLo[y-1] && trend[y-1]>=0) trend[y]=-1; if(trend[y] > 0) { if(mLo[y] < mLo[y-1]) mLo[y] = mLo[y-1]; mUpTrend[y] = mLo[y]; if(trend[y-1] <= 0 && SignalMode > 0) { mUpsig[y] = mLo[y]; if (WarningMode>0 && y==mBars-1) PlaySound("alert2.wav"); } else mUpsig[y]= EMPTY_VALUE; mDnsig[y]= EMPTY_VALUE; mDnTrend[y]= EMPTY_VALUE; } else if (trend[y] < 0) { if(mUp[y] > mUp[y-1]) mUp[y] = mUp[y-1]; mDnTrend[y] = mUp[y]; if(trend[y-1] >= 0 && SignalMode > 0) { mDnsig[y] = mUp[y]; if (WarningMode>0 && y==mBars-1) PlaySound("alert2.wav"); } else mDnsig[y]= EMPTY_VALUE; mUpTrend[y]= EMPTY_VALUE; mUpsig[y]= EMPTY_VALUE; } if(TimeFrame == Period()) { UpTrend[mBars-y-1] = mUpTrend[y]; DnTrend[mBars-y-1] = mDnTrend[y]; if(SignalMode > 0) { UpSignal[mBars-y-1] = mUpsig[y]; DnSignal[mBars-y-1] = mDnsig[y]; } sig[mBars-y-1] = trend[y]; //Buffer for EAs //Print("sig=",sig[mBars-y-1]); } } mcnt_bars = mBars-1; if(TimeFrame > Period()) { if(cnt_bars>0) cnt_bars--; limit = Bars-cnt_bars+TimeFrame/Period()-1; for(shift=0,y=0;shift 0) { UpSignal[shift] = mUpsig[mBars-y-1]; DnSignal[shift] = mDnsig[mBars-y-1]; } sig[shift] = trend[mBars-y-1]; //Buffer for EAs } } //---------- string Message; if (trend[mBars-3]<0 && trend[mBars-2]>0 && !UpTrendAlert && AlertMode == 1) { Message = " "+Symbol()+" "+TF+":AllTrendEnvelopes Signal for BUY"; if (isNewBar()) Alert (Message); UpTrendAlert=true; DnTrendAlert=false; } else if (trend[mBars-3]>0 && trend[mBars-2]<0 && !DnTrendAlert && AlertMode == 1) { Message = " "+Symbol()+" "+TF+":AllTrendEnvelopes Signal for SELL"; if (isNewBar()) Alert (Message); DnTrendAlert=true; UpTrendAlert=false; } //---- return(0); } // MA_Method=0: SMA - Simple Moving Average double SMA(double array[],int per,int bar) { double Sum = 0; for(int i = 0;i < per;i++) Sum += array[bar-i]; return(Sum/per); } // MA_Method=1: EMA - Exponential Moving Average double EMA(double price,double array[],int per,int bar) { if(bar == 2) double ema = price; else if(bar > 2) ema = array[bar-1] + 2.0/(1+per)*(price - array[bar-1]); return(ema); } // MA_Method=2: Wilder - Wilder Exponential Moving Average double Wilder(double array1[],double array2[],int per,int bar) { if(bar == per) double wilder = SMA(array1,per,bar); else if(bar > per) wilder = array2[bar-1] + (array1[bar] - array2[bar-1])/per; return(wilder); } // MA_Method=3: LWMA - Linear Weighted Moving Average double LWMA(double array[],int per,int bar) { double Sum = 0; double Weight = 0; for(int i = 0;i < per;i++) { Weight+= (per - i); Sum += array[bar-i]*(per - i); } if(Weight>0) double lwma = Sum/Weight; else lwma = 0; return(lwma); } // MA_Method=4: SineWMA - Sine Weighted Moving Average double SineWMA(double array[],int per,int bar) { double pi = 3.1415926535; double Sum = 0; double Weight = 0; for(int i = 0;i < per;i++) { Weight+= MathSin(pi*(i+1)/(per+1)); Sum += array[bar-i]*MathSin(pi*(i+1)/(per+1)); } if(Weight>0) double swma = Sum/Weight; else swma = 0; return(swma); } // MA_Method=5: TriMA - Triangular Moving Average double TriMA(double array[],int per,int bar) { double sma; int len = MathCeil((per+1)*0.5); double sum=0; for(int i = 0;i < len;i++) { sma = SMA(array,len,bar-i); sum += sma; } double trima = sum/len; return(trima); } // MA_Method=6: LSMA - Least Square Moving Average (or EPMA, Linear Regression Line) double LSMA(double array[],int per,int bar) { double Sum=0; for(int i=per; i>=1; i--) Sum += (i-(per+1)/3.0)*array[bar-per+i]; double lsma = Sum*6/(per*(per+1)); return(lsma); } // MA_Method=7: SMMA - Smoothed Moving Average double SMMA(double array1[],double array2[],int per,int bar) { if(bar == per) double smma = SMA(array1,per,bar); else if(bar > per) { double Sum = 0; for(int i = 0;i < per;i++) Sum += array1[bar-i-1]; smma = (Sum - array2[bar-1] + array1[bar])/per; } return(smma); } // MA_Method=8: HMA - Hull Moving Average by Alan Hull double HMA(double array[],int per,int bar) { double tmp[]; int len = MathSqrt(per); ArrayResize(tmp,len); if(bar == per) double hma = array[bar]; else if(bar > per) { for(int i = 0; i < len;i++) tmp[len-i-1] = 2*LWMA(array,per/2,bar-i) - LWMA(array,per,bar-i); hma = LWMA(tmp,len,len-1); } return(hma); } // MA_Method=9: ZeroLagEMA - Zero-Lag Exponential Moving Average double ZeroLagEMA(double array1[],double array2[],int per,int bar) { double alfa = 2.0/(1+per); int lag = 0.5*(per - 1); if(bar == lag) double zema = array1[bar]; else if(bar > lag) zema = alfa*(2*array1[bar] - array1[bar-lag]) + (1-alfa)*array2[bar-1]; return(zema); } // MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy double DEMA(int num,double price,int per,double v,int bar) { if(bar == 2) {double dema = price; tmp[bar][num] = dema; tmp[bar][num+1] = dema;} else if(bar > 2) { tmp[bar][num] = tmp[bar-1][num] + 2.0/(1+per)*(price - tmp[bar-1][num]); tmp[bar][num+1] = tmp[bar-1][num+1] + 2.0/(1+per)*(tmp[bar][num] - tmp[bar-1][num+1]); dema = (1+v)*tmp[bar][num] - v*tmp[bar][num+1]; } return(dema); } // MA_Method=11: T3 by T.Tillson double T3(int num,double price,int per,double v,int bar) { if(bar == 2) { double T3 = price; for(int k=0;k<=5;k++) tmp[bar][k] = T3; } else if(bar > 2) { double dema1 = DEMA(num,price,per,v,bar); double dema2 = DEMA(num+2,dema1,per,v,bar); T3 = DEMA(num+4,dema2,per,v,bar); } return(T3); } // MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers double ITrend(double price[],double array[],int per,int bar) { double alfa = 2.0/(per+1); if(bar > 7) double it = (alfa - 0.25*alfa*alfa)*price[bar]+ 0.5*alfa*alfa*price[bar-1]-(alfa - 0.75*alfa*alfa)*price[bar-2]+ 2*(1-alfa)*array[bar-1] - (1-alfa)*(1-alfa)*array[bar-2]; else it = (price[bar] + 2*price[bar-1]+ price[bar-2])/4; return(it); } // MA_Method=13: Median - Moving Median double Median(double price[],int per,int bar) { double array[]; ArrayResize(array,per); for(int i = 0; i < per;i++) array[i] = price[bar-i]; ArraySort(array); int num = MathRound((per-1)/2); if(MathMod(per,2)>0) double median = array[num]; else median = 0.5*(array[num]+array[num+1]); return(median); } // MA_Method=14: GeoMean - Geometric Mean double GeoMean(double price[],int per,int bar) { double gmean = MathPow(price[bar],1.0/per); for(int i = 1; i < per;i++) gmean *= MathPow(price[bar-i],1.0/per); return(gmean); } // MA_Method=15: REMA - Regularized EMA by Chris Satchwell double REMA(double price,double array[],int per,double lambda,int bar) { double alpha = 2.0/(per + 1); if(bar <= 3) double rema = price; else if(bar > 3) rema = (array[bar-1]*(1+2*lambda) + alpha*(price - array[bar-1]) - lambda*array[bar-2])/(1+lambda); return(rema); } // MA_Method=16: ILRS - Integral of Linear Regression Slope double ILRS(double price[],int per,int bar) { double sum = per*(per-1)*0.5; double sum2 = (per-1)*per*(2*per-1)/6.0; double sum1 = 0; double sumy = 0; for(int i=0;i 0) double vwma = Sum/Weight; else vwma = 0; return(vwma); } // MA_Method=20: JSmooth - Smoothing by Mark Jurik double JSmooth(int num,double price,int per,double pow,int bar) { double beta = 0.45*(per-1)/(0.45*(per-1)+2); double alpha = MathPow(beta,pow); if(bar == 2) {tmp[bar][num+4] = price; tmp[bar][num+0] = price; tmp[bar][num+2] = price;} else if(bar > 2) { tmp[bar][num+0] = (1-alpha)*price + alpha*tmp[bar-1][num+0]; tmp[bar][num+1] = (price - tmp[bar][num+0])*(1-beta) + beta*tmp[bar-1][num+1]; tmp[bar][num+2] = tmp[bar][num+0] + tmp[bar][num+1]; tmp[bar][num+3] = (tmp[bar][num+2] - tmp[bar-1][num+4])*MathPow((1-alpha),2) + MathPow(alpha,2)*tmp[bar-1][num+3]; tmp[bar][num+4] = tmp[bar-1][num+4] + tmp[bar][num+3]; } return(tmp[bar][num+4]); } // HeikenAshi Price: 7 - Close,8 - Open,9 - High,10 - Low double HeikenAshi(int indx,int tf,int price,int bar) { if(bar == iBars(NULL,TimeFrame)- 1) { haClose[bar][indx] = iClose(NULL,tf,bar); haOpen[bar][indx] = iOpen(NULL,tf,bar); haHigh[bar][indx] = iHigh(NULL,tf,bar); haLow[bar][indx] = iLow(NULL,tf,bar); } else { haClose[bar][indx] = (iOpen(NULL,tf,bar)+iHigh(NULL,tf,bar)+iLow(NULL,tf,bar)+iClose(NULL,tf,bar))/4; haOpen[bar][indx] = (haOpen[bar+1][indx]+haClose[bar+1][indx])/2; haHigh[bar][indx] = MathMax(iHigh(NULL,tf,bar),MathMax(haOpen[bar][indx], haClose[bar][indx])); haLow[bar][indx] = MathMin(iLow(NULL,tf,bar),MathMin(haOpen[bar][indx], haClose[bar][indx])); } switch(price) { case 0: return(haClose[bar][indx]);break; case 1: return(haOpen[bar][indx]);break; case 2: return(haHigh[bar][indx]);break; case 3: return(haLow[bar][indx]);break; } } bool isNewBar() { bool res=false; if (iTime(NULL,TimeFrame,0)!=pTime) { res=true; pTime=iTime(NULL,TimeFrame,0); } return(res); }