//+------------------------------------------------------------------+ //| Candle Coefficient.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window enum PAIRS { watch = 0,//Select from market watch manual = 1//Enter pairs manually }; enum TFS { auto = 0,//Select all available inp = 1//Enter timeframes manually }; extern int cc = 12; //Minimum CC extern string PI = "";//-----------------------Pairs Input------------------------ extern PAIRS pairSelect = manual; //Select Pairs Option extern string inpPairs = "EURUSD,GBPUSD,AUDUSD,NZDUSD,USDCAD,USDCHF,USDJPY"; //User selected pairs extern string suffix = ""; //Pair suffix extern string TI = "";//-----------------------Timeframe Input-------------------------- extern TFS tfSelect = auto; //Select timeframes Option extern string inpTFs = "M1,M5,M15,M30,H1,H4,D1,W1,MN1";//User selected timeframes extern string ALRT = ""; //---------------------Alerts Settings-------------------- extern bool desktopAlerts = true; //Desktop Alerts extern bool emailAlerts = false; //Email Alerts extern bool mobileAlerts = true; //Mobile Alerts extern string TBL = ""; //-------------------TABLE SETTINGS------------------ extern color buyExtClr = clrRed; //Extream Up Trend Color extern color sellExtClr = clrGreen; //Extream Dpwn Trend Color extern color buyClr = clrLightSalmon; //Up Trend Color extern color sellClr = clrLightGreen; //Down Trend Color extern color neutralClr = clrWhite; //Neutral Color extern color cellColor = clrLavender; //Cell Color extern color fontClr = clrBlack; //Text Color extern int fontSize = 10;//Text Size extern bool setBackground = false; //Set as Background extern int cellWidth = 70; //Cell Width extern int cellHeight = 25; //Cell Height extern int xOffset = 0; //Move horizontal extern int yOffset = 30; //Move vertical string pairs[]; string timeframes[]; datetime candleTimes[]; int cnt; string objName = "RSIES_", tempName; string font = "Comic Sans MS"; int OnInit() { if(pairSelect==watch) { for(int i=0; i< SymbolsTotal(true);i++) { ArrayResize(pairs, ArraySize(pairs)+1); pairs[ArraySize(pairs)-1] = SymbolName(i,true); } } else { StringSplit(inpPairs, StringGetChar(",",0), pairs); for(int i=0; i=0; i--) { if(StringSubstr(ObjectName(i),0,StringLen(objName))==objName) { ObjectDelete(ObjectName(i)); } } EventKillTimer(); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { return(rates_total); } void OnTimer() { cnt = 0; for(int i=0; i open) //buy { while(close > open) { open = iCustom(pairs[i],str2tf(timeframes[j]),"Heiken Ashi",2,coef+1); close = iCustom(pairs[i],str2tf(timeframes[j]),"Heiken Ashi",3,coef+1); coef++; } coef--; if(coef >= cc) { doAlert(pairs[i], str2tf(timeframes[j]), coef); ObjectSetInteger(0, tempName, OBJPROP_BGCOLOR, buyExtClr); }else { ObjectSetInteger(0, tempName, OBJPROP_BGCOLOR, buyClr); } ObjectSetString(0, tempName, OBJPROP_TEXT, IntegerToString(coef)); }else if(open > close) //sell { while(open > close) { open = iCustom(pairs[i],str2tf(timeframes[j]),"Heiken Ashi",2,coef+1); close = iCustom(pairs[i],str2tf(timeframes[j]),"Heiken Ashi",3,coef+1); coef++; } coef--; if(coef >= cc) { doAlert(pairs[i], str2tf(timeframes[j]), coef); ObjectSetInteger(0, tempName, OBJPROP_BGCOLOR, sellExtClr); }else { ObjectSetInteger(0, tempName, OBJPROP_BGCOLOR, sellClr); } ObjectSetString(0, tempName, OBJPROP_TEXT, IntegerToString(coef)); } candleTimes[cnt] = iTime(pairs[i], str2tf(timeframes[j]), 0); } cnt++; } } } void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { if(id == CHARTEVENT_OBJECT_CLICK && StringFind(sparam, objName, 0) != -1) { ObjectSetInteger(0, sparam, OBJPROP_STATE, false); string result[]; int num = StringSplit(sparam, StringGetChar("_", 0), result); if(num == 3) { int row = (int) result[1]; int colomn = (int) result[2]; if(row > 0 && colomn > 0) { string currency = pairs[row-1]; int period = str2tf(timeframes[colomn-1]); long newId = ChartOpen(currency, period); } } } } void doAlert(string pair, int tf, int coef) { string message = "Candle coefficient of " + IntegerToString(coef) + " on " + pair + " " + tf2Str(tf); if (desktopAlerts) Alert(message); if (emailAlerts) SendMail("BTTFX Alert: ", message); if (mobileAlerts) SendNotification(message); } string tf2Str(int tf) { if (tf == 1) return("M1"); if (tf == 5) return("M5"); if (tf == 15) return("M15"); if (tf == 30) return("M30"); if (tf == 60) return("H1"); if (tf == 240) return("H4"); if (tf == 1440) return("D1"); if (tf == 10080) return("W1"); if (tf == 43200) return("MN1"); return NULL; } int str2tf(string _tf) { if (_tf == "M1") return(1); if (_tf == "M5") return(5); if (_tf == "M15") return(15); if (_tf == "M30") return(30); if (_tf == "H1") return(60); if (_tf == "H4") return(240); if (_tf == "D1") return(1440); if (_tf == "W1") return(10080); if (_tf == "MN1") return(43200); return NULL; } void drawButton(string name, int x, int y, int width, int height, string text, color clr, color back_clr, string Font, int FontSize) { ObjectDelete(0,name); ObjectCreate(0, name, OBJ_BUTTON, 0,0,0); ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x); ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y); ObjectSetInteger(0,name,OBJPROP_XSIZE,width); ObjectSetInteger(0,name,OBJPROP_YSIZE,height); ObjectSetInteger(0,name,OBJPROP_CORNER,0); ObjectSetString(0,name,OBJPROP_TEXT,text); ObjectSetString(0,name,OBJPROP_FONT, Font); ObjectSetInteger(0,name,OBJPROP_FONTSIZE, FontSize); ObjectSetInteger(0,name,OBJPROP_COLOR,clr); ObjectSetInteger(0,name,OBJPROP_BGCOLOR,back_clr); ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,CHART_COLOR_BACKGROUND); ObjectSetInteger(0, name, OBJPROP_STATE, false); ObjectSetInteger(0,name,OBJPROP_BACK, false); ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false); ObjectSetInteger(0,name,OBJPROP_SELECTED,false); ObjectSetInteger(0, name, OBJPROP_BORDER_TYPE, BORDER_SUNKEN); }