//+------------------------------------------------------------------+ //| _tp BrianIndex (SinglePair) V2.03.mq4 | //| | //| V2.00 | //| 1) Add 90% & 30% lines | //| | //| V2.01 | //| 1) Show multiple history week value | //| | //| V2.02 | //| 1) Fix ObjectCreate error | //| | //| V2.03 | //| 1) Fix the wrong calculation of Cur | //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 5 #property indicator_color1 Blue #property indicator_color2 Orange #property indicator_color3 Orange #property indicator_color4 Lime #property indicator_color5 Lime #property indicator_style1 STYLE_SOLID #property indicator_style2 STYLE_DOT #property indicator_style3 STYLE_DOT #property indicator_style4 STYLE_DOT #property indicator_style5 STYLE_DOT #property indicator_level1 0 #property indicator_levelcolor DarkGray extern double Level1Factor = 2.3; extern double Level2Factor = 0.85; extern int HistoryWeek = 104; extern int FontSize = 16; string TimeFrame_value = "TimeFrame(0,M5,M15,M30,H1,D1)"; string TimeFrame = "0"; string MA_Type_value = "SMA, EMA, LWMA"; string MA_Type = "SMA"; int timeFrame = 0; double pair1Close; int totalWeek = 0; int lastDay = 0; int maType; double BufBI[]; double BufBIHHLevel1[]; double BufBIHHLevel2[]; double BufBILLLevel2[]; double BufBILLLevel1[]; int MaxWeek = 0; double WeekCloseArray[]; double WeekHHpipsArray[]; double WeekLLpipsArray[]; int History2, History3, History4, History5; datetime LastWeekDateTime = 0; int LastWeekBarShift; string sShortName = "_tp BI (SP) V2.03"; int objectcnt=1; int init() { IndicatorBuffers(5); IndicatorShortName(sShortName); SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_LINE); SetIndexStyle(3,DRAW_LINE); SetIndexStyle(4,DRAW_LINE); SetIndexLabel(0,"BI"); SetIndexLabel(1,"HH1"); SetIndexLabel(2,"HH22"); SetIndexLabel(3,"LL2"); SetIndexLabel(4,"LL1"); SetIndexBuffer(0,BufBI); SetIndexBuffer(1,BufBIHHLevel1); SetIndexBuffer(2,BufBIHHLevel2); SetIndexBuffer(3,BufBILLLevel2); SetIndexBuffer(4,BufBILLLevel1); if (MA_Type == "SMA") { maType = MODE_SMA; } else if (MA_Type == "EMA") { maType = MODE_EMA; } else if (MA_Type == "LWMA") { maType = MODE_LWMA; } else { maType = MODE_SMA; } if (TimeFrame == "M5") { timeFrame = PERIOD_M5; } else if (TimeFrame == "M15") { timeFrame = PERIOD_M15; } else if (TimeFrame == "M30") { timeFrame = PERIOD_M30; } else if (TimeFrame == "H1") { timeFrame = PERIOD_H1; } else if (TimeFrame == "D1") { timeFrame = PERIOD_D1; } else { timeFrame = 0; } // HistoryWeek = MathMin(HistoryWeek+1, iBars(NULL,PERIOD_W1)) - 1; ArrayResize(WeekCloseArray, HistoryWeek); ArrayResize(WeekHHpipsArray, HistoryWeek); ArrayResize(WeekLLpipsArray, HistoryWeek); return(0); } int deinit() { ObjectsDeleteAll(0, OBJ_VLINE); return(0); } int start() { int i, j, counted_bars = IndicatorCounted(); int AvailableWeek = 0; i = Bars - counted_bars - 1; double TotalHHtoLastFriClose = 0.0; double TotalLLtoLastFriClose = 0.0; if (LastWeekDateTime != iTime(NULL,PERIOD_W1,1) ) { for (j = HistoryWeek; j>0; j--) { if (iClose(NULL,PERIOD_W1,j+1) > 0) { TotalHHtoLastFriClose = TotalHHtoLastFriClose + ( iHigh(NULL,PERIOD_W1,j) - iClose(NULL,PERIOD_W1,j+1) ); TotalLLtoLastFriClose = TotalLLtoLastFriClose + ( iLow(NULL,PERIOD_W1,j) - iClose(NULL,PERIOD_W1,j+1) ); AvailableWeek++; } } TotalHHtoLastFriClose = TotalHHtoLastFriClose / AvailableWeek / MarketInfo(Symbol(),MODE_POINT); TotalLLtoLastFriClose = TotalLLtoLastFriClose / AvailableWeek / MarketInfo(Symbol(),MODE_POINT); LastWeekDateTime = iTime(NULL,PERIOD_D1,1); } while (i >= 0) { LastWeekBarShift = iBarShift(NULL, PERIOD_W1, Time[i]) + 1; pair1Close = iClose(NULL, PERIOD_W1, LastWeekBarShift); // closes of last week if (pair1Close > 0) { if (lastDay != TimeDayOfWeek(iTime(NULL, timeFrame, i))) { lastDay = TimeDayOfWeek(iTime(NULL, timeFrame, i)); totalWeek = 0; } BufBI[i] = (iClose(Symbol(), timeFrame, i) - pair1Close) / MarketInfo(Symbol(),MODE_POINT); BufBIHHLevel1[i] = TotalHHtoLastFriClose * Level1Factor; BufBIHHLevel2[i] = TotalHHtoLastFriClose * Level2Factor; BufBILLLevel2[i] = TotalLLtoLastFriClose * Level2Factor; BufBILLLevel1[i] = TotalLLtoLastFriClose * Level1Factor; } i--; } objectcnt=1; CreateLabelObject("HH1 = ",FontSize,3,Orange); CreateLabelObject(DoubleToStr(BufBIHHLevel1[0],0),FontSize,2,Orange); objectcnt++; CreateLabelObject("HH2 = ",FontSize,3,Orange); CreateLabelObject(DoubleToStr(BufBIHHLevel2[0],0),FontSize,2,Orange); objectcnt++; CreateLabelObject("Cur = ",FontSize,3,White); CreateLabelObject(DoubleToStr(BufBI[0],0),FontSize,2,White); objectcnt++; CreateLabelObject("LL2 = ",FontSize,3,Lime); CreateLabelObject(DoubleToStr(BufBILLLevel2[0],0),FontSize,2,Lime); CreateLabelObject(DoubleToStr(AvailableWeek,0),8,1,Gray); objectcnt++; CreateLabelObject("LL1 = ",FontSize,3,Lime); CreateLabelObject(DoubleToStr(BufBILLLevel1[0],0),FontSize,2,Lime); objectcnt++; return(0); } string formatInteger(int value) { if (value < 10) { return("0" + value); } else { return("" + value); } } void CreateLabelObject(string sString, int iFontSize, int iColumn, color cColor) { string objectname = sShortName+objectcnt+"_"+iColumn; int xx; if (iColumn == 1) xx = 10; else if (iColumn == 2) xx = 10 + 20; else if (iColumn == 3) xx = 10 + 60; ObjectDelete(objectname); ObjectCreate(objectname, OBJ_LABEL, WindowFind(sShortName), 0, 0); ObjectSet(objectname, OBJPROP_CORNER, 1); ObjectSet(objectname, OBJPROP_XDISTANCE, xx); ObjectSet(objectname, OBJPROP_YDISTANCE, 3+(objectcnt-1)*(iFontSize + 6)); ObjectSetText(objectname,sString, iFontSize,"Arial" ,cColor); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains open time of each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features: