//+------------------------------------------------------------------+ //| eVOLution-dvoid.mq4 | //| 2012, someBody | //| http://trading-evolution.com/ | //+------------------------------------------------------------------+ #property copyright " 2012, someBody" #property link "http://trading-evolution.com/" #property indicator_separate_window #property indicator_color1 Silver #property indicator_color2 Blue #property indicator_color3 Red #property indicator_width2 2 #property indicator_width3 2 #property indicator_buffers 4 string FileNamePruductCode=""; int barsToProcess=100; color barColor=SteelBlue,oiColor=Yellow; bool showOI=true; bool showHeader=true; color HeaderColor=Black; int FontSize=8; int textXshift = 10; int textYshift = 13; double Buffer1[],Buffer2[],Buffer3[]; string folder="/evolution-dvoid/",objpref="evo-dvoid_"; int control,vol0,oi0,vol1,oi1,q; string currency,currency1,date0,date1,headertext1,headertext2; bool cur=true,cross=false; int a,b,objwidth=4,d,Val,Oi; double tempvol,tempoi,volmax,volmin,volrange,oimax,oimin,oirange; string ddate; double volarr[],oiarr[],OOO=0; bool initFinished=false; color back_ground; int windowIndex,Q; datetime curDay; datetime ldt_BeginDay; int li_Bar; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { initFinished=false; //---- SetIndexBuffer(1,Buffer1,INDICATOR_DATA); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); SetIndexBuffer(2,Buffer2,INDICATOR_DATA); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0); SetIndexBuffer(3,Buffer3,INDICATOR_DATA); PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0); //d=0; return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void drawRectangle(string name,datetime time1,double price1,datetime time2,int counter) { string oiname; windowIndex=WindowFind("trading-evolution.com : eVOLution-dvoid"); oiname=objpref+"_oi_"+name; name=objpref+"_vol_"+name; if(Period()<1440) ObjectCreate(name,OBJ_RECTANGLE,windowIndex,time1,price1,time2,volarr[counter]*100/volmax); else ObjectCreate(name,OBJ_TREND,windowIndex,time1,price1,time1,volarr[counter]*100/volmax); ObjectSet(name,OBJPROP_COLOR,barColor); ObjectSet(name,OBJPROP_BACK,true); ObjectSet(name,OBJPROP_RAY,false); ObjectSet(name,OBJPROP_WIDTH,objwidth); ObjectSetText(name,"Volume="+DoubleToStr(volarr[counter],0)); if(showOI) { if(oiarr[counter+1]>1 && oirange>0) //ObjectCreate(oiname,OBJ_TREND,windowIndex,time1-10,(oiarr[counter+1]-oimin)*100/oirange,time2,oiarr[counter]*100/oirange); ObjectCreate(oiname,OBJ_TREND,windowIndex,time1-10,(oiarr[counter+1]-oimin)*100/oirange,time2,(oiarr[counter]-oimin)*100/oirange); ObjectSet(oiname,OBJPROP_COLOR,oiColor); ObjectSet(oiname,OBJPROP_BACK,false); ObjectSet(oiname,OBJPROP_RAY,false); ObjectSet(oiname,OBJPROP_WIDTH,2); ObjectSetText(oiname,"OI="+DoubleToStr(oiarr[counter],0)); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Explode(string str,string levelrun,string &arr[]) { int i=0; int po=(StringFind(str,levelrun)); while(po!=-1) { if(po==0) arr[i]="0"; else arr[i]=StringSubstr(str,0,po); i++; str= StringSubstr(str,po+StringLen(levelrun)); po = StringFind(str,levelrun); if(po==-1 || str=="0") break; } arr[i]=str; return(i+1); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- deinition(); //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void deinition() { int total=ObjectsTotal(); int count=0; string prefixline=objpref; for(int i=total-1; i>=0; i--) { string prefix1=ObjectName(i); if(StringFind(prefix1,prefixline)==0) {ObjectDelete(prefix1);count++;} } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void drawonce() { //int counted_bars=IndicatorCounted(); string voldiff,oidiff; //---- if(!initFinished) { IndicatorShortName("trading-evolution.com : eVOLution-dvoid"); if(cur==FALSE){Alert("Currency is not supported");return(0);} color tempColor; int total = ObjectsTotal(); int count = 0; //product list from database: -EC -J1 -AD -BP -C1 -RY -NE -E1 -YM -NQ -ES -ZW -ZS -ZC -CL -SI -GC if(FileNamePruductCode=="") { currency=StringSubstr(Symbol(),0,2); currency1=StringSubstr(Symbol(),0,6); if(currency=="6E" || currency1=="EURUSD") {currency="ec";} else if(currency=="6B" || currency1=="GBPUSD") {currency="bp";} else if(currency=="ES" || currency1=="S&P_50") {currency="es";} else if(currency=="NQ" || currency1=="Nasdaq") {currency="nq";} else if(currency=="YM" || currency1=="DowJon") {currency="ym";} else if(currency=="J1" || currency1=="USDJPY") {currency="j1";} else if(currency=="AD" || currency1=="AUDUSD") {currency="ad";} else if(currency=="GC" || currency1=="XAGUSD") {currency="gc";} else if(currency=="SI" || currency1=="XAUUSD") {currency="si";} else if(currency=="CL" || currency1=="_CL") {currency="cl";} else if(currency=="6S" || currency1=="USDCHF") {currency="e1";} else if(currency=="6C" || currency1=="USDCAD") {currency="c1";} else if(currency=="6N" || currency1=="NZDUSD") {currency="ne";} else if(currency=="6R" || currency1=="EURJPY") {currency="ry";} else if(currency=="ZS" || currency1=="_ZS") {currency="zs";} else if(currency=="ZC" || currency1=="_ZC") {currency="zc";} else if(currency=="ZW" || currency1=="_ZW") {currency="zw";} else{cur=FALSE;return(0);} } else currency=FileNamePruductCode; string temp[1],asd[4]; //---- loading file string filename=folder+"dvoid-"+currency+".csv"; int handle=FileOpen(filename,FILE_CSV|FILE_READ,";"); if(handle<0) { if(GetLastError()==4103); Print("no file"); } if(handle>0) { int i=0; //Print ("1: "+handle+" "+filename); // return(0); while(!FileIsEnding(handle)) { ArrayResize(temp,i+1); temp[i]=FileReadString(handle); i++; Q=i; } } FileClose(handle); a=ArraySize(temp); Print(a); ArrayResize(volarr,a); ArrayResize(oiarr,a); if(GlobalVariableGet(Symbol()+"_"+currency)!=control){deinition();} for(b=0;bvol1) { voldiff="+"+(vol0-vol1); } else voldiff=vol0-vol1; if(oi0>oi1) { oidiff="+"+(oi0-oi1); } else oidiff=oi0-oi1; headertext1=date0+" V="+vol0+" OI="+oi0+" : Vol-D= "+voldiff+" OI-D= "+oidiff; headertext2=date1+" V="+vol1+" OI="+oi1; windowIndex=WindowFind("trading-evolution.com : eVOLution-dvoid"); string headername0=objpref+"header0"; string headername1=objpref+"header1"; ObjectCreate(headername0,OBJ_LABEL,windowIndex,0,0,0,0); ObjectSet(headername0,OBJPROP_XDISTANCE,textXshift); ObjectSet(headername0,OBJPROP_YDISTANCE,textYshift); ObjectSetText(headername0,headertext1,FontSize,"Arial",HeaderColor); ObjectCreate(headername1,OBJ_LABEL,windowIndex,0,0,0,0); ObjectSet(headername1,OBJPROP_XDISTANCE,textXshift); ObjectSet(headername1,OBJPROP_YDISTANCE,FontSize*1.6+textYshift); ObjectSetText(headername1,headertext2,FontSize,"Arial",HeaderColor); } //---- initFinished=true; WindowRedraw(); } } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(open,true); ArraySetAsSeries(close,true); ArraySetAsSeries(time,true); int i,limit; if(rates_total<=1) return(0); //--- last counted bar will be recounted if(prev_calculated>rates_total || prev_calculated<=0)// проверка на первый старт расчёта индикатора { limit=rates_total-5; // стартовый номер для расчёта всех баров }else{ limit=rates_total-prev_calculated; // стартовый номер для расчёта новых баров } drawonce(); if(b!=rates_total) { b=rates_total; ldt_BeginDay=iTime(NULL,PERIOD_D1,Q); li_Bar=iBarShift(NULL,0,ldt_BeginDay); d=0; for(int i=0; i<=li_Bar-10; i++) { if(curDay!=TimeDay(Time[i])) { curDay=TimeDay(Time[i]); OOO=iClose(NULL,PERIOD_D1,d+1)-iOpen(NULL,PERIOD_D1,d+1); if(volarr[d]!=0) Val=volarr[d]-volarr[d+1]; if(oiarr[d]!=0) Oi=oiarr[d]-oiarr[d+1]; d++; } Buffer1[i]=Val; Buffer2[i]=Oi; Buffer3[i]=OOO; } } WindowRedraw(); // Comment(Q," ",d," ",li_Bar); return(0); } //+------------------------------------------------------------------+ double iClose(string symbol,int tf,int index) { if(index < 0) return(-1); double Arr[]; ENUM_TIMEFRAMES timeframe=TFMigrate(tf); if(CopyClose(symbol,timeframe,index,1,Arr)>0) return(Arr[0]); else return(-1); } double iTime(string symbol,int tf,int index) { if(index < 0) return(-1); double Arr[]; ENUM_TIMEFRAMES timeframe=TFMigrate(tf); if(CopyClose(symbol,timeframe,index,1,Arr)>0) return(Arr[0]); else return(-1); } double iBarShift(string symbol,int tf,int index) { if(index < 0) return(-1); double Arr[]; ENUM_TIMEFRAMES timeframe=TFMigrate(tf); if(CopyClose(symbol,timeframe,index,1,Arr)>0) return(Arr[0]); else return(-1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double iHigh(string symbol,int tf,int index) { if(index < 0) return(-1); double Arr[]; ENUM_TIMEFRAMES timeframe=TFMigrate(tf); if(CopyHigh(symbol,timeframe,index,1,Arr)>0) return(Arr[0]); else return(-1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double iLow(string symbol,int tf,int index) { if(index < 0) return(-1); double Arr[]; ENUM_TIMEFRAMES timeframe=TFMigrate(tf); if(CopyLow(symbol,timeframe,index,1,Arr)>0) return(Arr[0]); else return(-1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ ENUM_TIMEFRAMES TFMigrate(int tf) { switch(tf) { case 0: return(PERIOD_CURRENT); case 1: return(PERIOD_M1); case 5: return(PERIOD_M5); case 15: return(PERIOD_M15); case 30: return(PERIOD_M30); case 60: return(PERIOD_H1); case 240: return(PERIOD_H4); case 1440: return(PERIOD_D1); case 10080: return(PERIOD_W1); case 43200: return(PERIOD_MN1); case 2: return(PERIOD_M2); case 3: return(PERIOD_M3); case 4: return(PERIOD_M4); case 6: return(PERIOD_M6); case 10: return(PERIOD_M10); case 12: return(PERIOD_M12); case 16385: return(PERIOD_H1); case 16386: return(PERIOD_H2); case 16387: return(PERIOD_H3); case 16388: return(PERIOD_H4); case 16390: return(PERIOD_H6); case 16392: return(PERIOD_H8); case 16396: return(PERIOD_H12); case 16408: return(PERIOD_D1); case 32769: return(PERIOD_W1); case 49153: return(PERIOD_MN1); default: return(PERIOD_CURRENT); } } //+------------------------------------------------------------------+