//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2018, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property strict #property indicator_chart_window #property indicator_buffers 4 extern double CandleSize = 20.0; extern color BearBarUp = clrLime; // Bear Bar Up extern color BullBarDown = clrRed; //Bull Bar Down extern int FastAtrPeriode = 5; extern int SlowAtrPeriode = 10; extern int history = 200; // Hystori Bars double Bull[]; double Bear[]; datetime mytime[]; double hi[]; double low[]; double open[]; double close[]; double differenz; double barUp[]; double EMAYelow[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { ArrayResize(barUp,history+1,0); ArrayResize(EMAYelow,history+1,0); ArrayResize(hi,history+1,0); ArrayResize(low,history+1,0); ArrayResize(open,history+1,0); ArrayResize(close,history+1,0); ArrayResize(mytime,history+1,0); //---- Buy Bar SetIndexStyle(0, DRAW_ARROW, EMPTY, 2, BearBarUp); SetIndexArrow(0, 233); SetIndexBuffer(0, Bull); //--- Sell Bar SetIndexStyle(1, DRAW_ARROW, EMPTY, 2, BullBarDown); SetIndexArrow(1, 234); SetIndexBuffer(1, Bear); //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { RectangleDelete(0, "Rectangle"); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //--- for(int i = 0; i <= history - 1 ; i++) { ResetLastError(); barUp[i] = iCustom(NULL, PERIOD_CURRENT, "PZ Volatmeter", "", FastAtrPeriode, SlowAtrPeriode, 0, i); EMAYelow[i] = iCustom(NULL, PERIOD_CURRENT, "PZ Volatmeter", "", FastAtrPeriode, SlowAtrPeriode, 2, i); //--- if(barUp[i] >= EMAYelow[i]) { hi[i] = iHigh(NULL, 0, i); low[i] = iLow(NULL, 0, i); open[i] = iOpen(NULL, 0, i); close[i] = iClose(NULL, 0, i); mytime[i] = iTime(NULL, 0, i); if(open[i] > close[i]) { //Bear[i] = High[i] + (100 * Point) ; RectangleCreate(0, "Rectangle"+ i, 0, mytime[i] + 60 * 60, hi[i], mytime[i] - 60 * 60, low[i], clrRed); } else if(open[i] < close[i]) { //Bull[i] = Low[i] - (100 * Point) ; RectangleCreate(0, "Rectangle"+ i, 0, mytime[i] + 60 * 60, hi[i], mytime[i] - 60 * 60, low[i], clrGreen); } } } return(0); } //+------------------------------------------------------------------+ //| Create rectangle by the given coordinates | //+------------------------------------------------------------------+ bool RectangleCreate(const long chart_ID = 0, // chart's ID const string name = "Rectangle", // rectangle name const int sub_window = 0, // subwindow index datetime time1 = 0, // first point time double price1 = 0, // first point price datetime time2 = 0, // second point time double price2 = 0, // second point price const color clr = clrRed, // rectangle color const ENUM_LINE_STYLE style = STYLE_SOLID, // style of rectangle lines const int width = 1, // width of rectangle lines const bool fill = true, // filling rectangle with color const bool back = false, // in the background const bool selection = false, // highlight to move const bool hidden = true, // hidden in the object list const long z_order = 0) // priority for mouse click { //--- set anchor points' coordinates if they are not set ChangeRectangleEmptyPoints(time1, price1, time2, price2); //--- reset the error value ResetLastError(); //--- create a rectangle by the given coordinates if(!ObjectCreate(chart_ID, name, OBJ_RECTANGLE, sub_window, time1, price1, time2, price2)) { Print(__FUNCTION__, ": failed to create a rectangle! Error code = ", GetLastError()); return(false); } //--- set rectangle color ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr); //--- set the style of rectangle lines ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style); //--- set width of the rectangle lines ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, width); //--- enable (true) or disable (false) the mode of filling the rectangle ObjectSetInteger(chart_ID, name, OBJPROP_FILL, fill); //--- display in the foreground (false) or background (true) ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back); //--- enable (true) or disable (false) the mode of highlighting the rectangle for moving //--- when creating a graphical object using ObjectCreate function, the object cannot be //--- highlighted and moved by default. Inside this method, selection parameter //--- is true by default making it possible to highlight and move the object ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection); ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection); //--- hide (true) or display (false) graphical object name in the object list ObjectSetInteger(chart_ID, name, OBJPROP_HIDDEN, hidden); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order); //--- successful execution return(true); } //+------------------------------------------------------------------+ //| Move the rectangle anchor point | //+------------------------------------------------------------------+ bool RectanglePointChange(const long chart_ID = 0, // chart's ID const string name = "Rectangle", // rectangle name const int point_index = 0, // anchor point index datetime time = 0, // anchor point time coordinate double price = 0) // anchor point price coordinate { //--- if point position is not set, move it to the current bar having Bid price if(!time) time = TimeCurrent(); if(!price) price = SymbolInfoDouble(Symbol(), SYMBOL_BID); //--- reset the error value ResetLastError(); //--- move the anchor point if(!ObjectMove(chart_ID, name, point_index, time, price)) { Print(__FUNCTION__, ": failed to move the anchor point! Error code = ", GetLastError()); return(false); } //--- successful execution return(true); } //+------------------------------------------------------------------+ //| Check the values of rectangle's anchor points and set default | //| values for empty ones | //+------------------------------------------------------------------+ void ChangeRectangleEmptyPoints(datetime & time1, double & price1, datetime & time2, double & price2) { //--- if the first point's time is not set, it will be on the current bar if(!time1) time1 = TimeCurrent(); //--- if the first point's price is not set, it will have Bid value if(!price1) price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); //--- if the second point's time is not set, it is located 9 bars left from the second one if(!time2) { //--- array for receiving the open time of the last 10 bars datetime temp[10]; CopyTime(Symbol(), Period(), time1, 10, temp); //--- set the second point 9 bars left from the first one time2 = temp[0]; } //--- if the second point's price is not set, move it 300 points lower than the first one if(!price2) price2 = price1 - 300 * SymbolInfoDouble(Symbol(), SYMBOL_POINT); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool RectangleDelete(const long chart_ID = 0, // chart's ID const string name = "Rectangle") // rectangle name { //--- reset the error value ResetLastError(); //--- delete rectangle if(!ObjectDelete(chart_ID, name)) { Print(__FUNCTION__, ": failed to delete rectangle! Error code = ", GetLastError()); return(false); } //--- successful execution return(true); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+