//+------------------------------------------------------------------+ //| AOchartbars.mq4 | //| masemus | //| Gresik_JawaTimur_Indonesia | //+------------------------------------------------------------------+ #property copyright "masemus" #property link "Gresik_JawaTimur_Indonesia" #property indicator_chart_window #property indicator_buffers 8 #property indicator_color1 Blue//wick #property indicator_color2 Red//wick #property indicator_color3 Blue//candle #property indicator_color4 Red//candle #property indicator_color5 LightSkyBlue//wick #property indicator_color6 LightPink//wick #property indicator_color7 LightSkyBlue//candle #property indicator_color8 LightPink//candle #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 2 #property indicator_width4 2 #property indicator_width5 1 #property indicator_width6 1 #property indicator_width7 2 #property indicator_width8 2 //**************************************** //---- input parameters extern int FastMA = 5; extern int SlowMA = 34; extern int MA_Mode = MODE_SMA; extern int MA_PriceType = PRICE_MEDIAN; extern int BarWidth = 1; extern int CandleWidth = 2; extern bool indicatorName = true; extern int Mywindow = 0; string ObjectID = "AOcb_"; //---- buffers double Bar1[], Bar2[], Bar3[], Bar4[], Candle1[], Candle2[], Candle3[], Candle4[]; //**************************************** //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(8); //---- AO SetIndexBuffer(0,Bar1); SetIndexBuffer(1,Bar2); SetIndexBuffer(2,Candle1); SetIndexBuffer(3,Candle2); SetIndexBuffer(4,Bar3); SetIndexBuffer(5,Bar4); SetIndexBuffer(6,Candle3); SetIndexBuffer(7,Candle4); SetIndexStyle(0,DRAW_HISTOGRAM,0,BarWidth); SetIndexStyle(1,DRAW_HISTOGRAM,0,BarWidth); SetIndexStyle(2,DRAW_HISTOGRAM,0,CandleWidth); SetIndexStyle(3,DRAW_HISTOGRAM,0,CandleWidth); SetIndexStyle(4,DRAW_HISTOGRAM,0,BarWidth); SetIndexStyle(5,DRAW_HISTOGRAM,0,BarWidth); SetIndexStyle(6,DRAW_HISTOGRAM,0,CandleWidth); SetIndexStyle(7,DRAW_HISTOGRAM,0,CandleWidth); return(0); } //+------------------------------------------------------------------+ double MACD (int tf, int i = 0) {return(iMA(NULL,tf,FastMA,0,MA_Mode,MA_PriceType,i) -iMA(NULL,0,SlowMA,0,MA_Mode,MA_PriceType,i));} //+------------------------------------------------------------------+ void SetCandleColor(int col, int i) { double high,low,bodyHigh,bodyLow; { bodyHigh = MathMax(Open[i],Close[i]); bodyLow = MathMin(Open[i],Close[i]); high = High[i]; low = Low[i]; } Bar1[i] = low; Candle1[i] = bodyLow; Bar2[i] = low; Candle2[i] = bodyLow; Bar3[i] = low; Candle3[i] = bodyLow; Bar4[i] = low; Candle4[i] = bodyLow; switch(col) { case 1: Bar1[i] = high; Candle1[i] = bodyHigh; break; case 2: Bar2[i] = high; Candle2[i] = bodyHigh; break; case 3: Bar3[i] = high; Candle3[i] = bodyHigh; break; case 4: Bar4[i] = high; Candle4[i] = bodyHigh; break; } } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- // ObjectsDeleteAll(0,OBJ_LABEL); // ObjectsDeleteAll(Mywindow,OBJ_LABEL); delete_objects(); // Only delete objects created by this indicator //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i; int limit; limit = MathMax(Bars-1-IndicatorCounted(),1); //---- if(indicatorName){ DisplayObject("AOcbars_00", 2, "AO_ChartBars", 8, "Trebuchet MS", Gray, 9, 9); } //***************************************************************************************************** for( i = limit; i>=0; i--) { double c_macd = MACD(i); double p_macd = MACD(i+1); if((c_macd > p_macd)&&(c_macd > 0)) {SetCandleColor(1,i);} if((c_macd < p_macd)&&(c_macd < 0)) {SetCandleColor(2,i);} if((c_macd > p_macd)&&(c_macd < 0)) {SetCandleColor(3,i);} if((c_macd < p_macd)&&(c_macd > 0)) {SetCandleColor(4,i);} } //---- done return(0); } void DisplayObject(string mObject, int corner, string msg, int FontSize, string FontName, color mColor, int x_position, int y_position) { string myObject = ObjectID + mObject; if (ObjectFind( myObject) == -1 ){ ObjectCreate( myObject, OBJ_LABEL, Mywindow, 0, 0); } ObjectSet(myObject, OBJPROP_CORNER, corner); ObjectSet( myObject, OBJPROP_XDISTANCE, x_position); ObjectSet( myObject, OBJPROP_YDISTANCE, y_position); ObjectSetText( myObject,msg, FontSize,FontName,mColor); } void delete_objects() { int i, tot; string object_name; tot = ObjectsTotal(); for (i = tot; i>=0;i--) { object_name = ObjectName(i); if (StringFind(object_name, ObjectID) > -1 ) ObjectDelete(object_name); } } //+------------------------------------------------------------------+