//+------------------------------------------------------------------+ //| Options Levels & Volumes XR © V40 + Lite.mq4 | //| Copyright © 2010, Xrust Soluton. | //| http://www.opmarketvol.com | //| xrustx@gmail.com xrust@mksat.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Xrust Soluton." #property link "http://www.opmarketvol.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Coral #property indicator_color2 Red #property indicator_color3 Blue #property indicator_color4 DodgerBlue #import "user32.dll" int GetWindowDC(int dc); int ReleaseDC(int h, int dc); bool GetWindowRect(int h, int& pos[4]); #import #import "gdi32.dll" int GetPixel(int dc, int x, int y); #import #import "kernel32.dll" int WinExec(string cmd, int showConsole); int GetTimeZoneInformation(int& TZInfoArray[]); #import #import "inet.ex4" void request(string nm); #include //+------------------------------------------------------------------+ extern string SymbolSet = "";// extern bool Lite = true;// extern bool Pro = false;// extern bool ShowHistory = true;// extern bool ShowHistoryVolumes = true;// extern bool ShowHistActLevels = true;// extern bool ShowActiveLevels = false;// extern bool ShowActiveColor = true;// extern int DepthHistoryInDays = 3;// extern int VolumeFilter = 0;// extern bool nearest = false;// extern int near_to_the_price = 2;// extern int OnlineFwdInBars = 10;// extern int WidthHistoryLines = 2;// extern int WidthOlineLines = 3;// extern int HistoryFontSize = 7;// extern int OnlineFontSize = 14;// extern string FontName = "Times new roman";// //+------------------------------------------------------------------+ bool Langvage_Ru_Engl = true; color Option_Call_Color = FireBrick;// color Call_In_Money_Clr = DodgerBlue;// color Option_Put_Color = MidnightBlue;// color Put_In_Money_Clr = OrangeRed;// //+------------------------------------------------------------------+ string requestfn = "request.opd"; string symbols = "symbols.ini"; string name = ""; string ext = "_opt_hist.csv"; string copyrite = "OptionsLevels&VolumesXR © "; string exp = "Expiration date = "; string cnm = "Contract name = "; //+------------------------------------------------------------------+ string nolistru = "Этот инструмент не поддерживается, или его нет в списке."; string nolisten = "This currency is not supported, or it is not in the list."; string entnamru = "Ведите имя инструмента в переменную SymbolSet"; string entnamen = "Enter the name of the currency in the variable SymbolSet"; string erronlru = "Нет доступа к файлу онлайн данных.\nПовтор запроса будет произведен при следующем обращении к серверу.\nИли пезапустите индикатор вручную."; string erronlen = "No file access online data.\n Perhaps you have not activated your account.\n Please contact technical support."; string indvisru = "В режиме визуализации, индикация будет \n отражаться корректно только на тайм фрейме М5"; string indvisen = "In the visual mode, the indication will \n display correctly only in the time frame M5"; string faterrru = "Перезагрузите систему или\nобратитесь http://realvolumes.ucoz.ru/forum/2-4-1"; string faterren = "Fatal error\nreboot the system or contact http://realvolumes.ucoz.ru/forum/2-4-1"; string errsinru = "Нет доступа к файлу синонимов\nСистема будет остановлена\nЧерез "; string errsinen = "No access to the symbols.ini file\nsystem will be stopped \nthrough"; string errdayru = "Ожидайте, идет докачка истории по ТФ D1, или закачайте самостоятельно"; string errdayen = "Wait, is History download for D1 TimeFrame, or upload your own"; //+------------------------------------------------------------------+ int date[365]; int tz[43]; string in[1000],copy[1000]; int near1,near2; int prewtime =0; bool wait = false; bool noonline = false; bool geraze = true; int Win_color; int days; //+------------------------------------------------------------------+ double price[]; double resist[]; double resstop[]; double supstop[]; double support[]; double midup[]; double middn[]; double online[15][4]; //+------------------------------------------------------------------+ void init(){ //+------------------------------------------------------------------+ SetIndexStyle(0,DRAW_SECTION,STYLE_DOT); SetIndexBuffer(0,resist); SetIndexLabel(0,"StopResistanse"); SetIndexStyle(1,DRAW_SECTION,STYLE_SOLID,2); SetIndexBuffer(1,resstop); SetIndexLabel(1,"Resistanse"); SetIndexStyle(2,DRAW_SECTION,STYLE_SOLID,2); SetIndexBuffer(2,supstop); SetIndexLabel(2,"Support"); SetIndexStyle(3,DRAW_SECTION,STYLE_DOT); SetIndexBuffer(3,support); SetIndexLabel(3,"StopSupport"); //+------------------------------------------------------------------+ near1=7-near_to_the_price; near2=8+near_to_the_price; //+------------------------------------------------------------------+ if(isfile(symbols)!=0){request(symbols);wait=true;}else{wait=false;} //+------------------------------------------------------------------+ recalcdate(); //+------------------------------------------------------------------+ int hd=FileOpen("opml.tmp",FILE_CSV|FILE_READ); if(hd>0){FileReadString(hd); if(FileReadString(hd)==".en"){Langvage_Ru_Engl=false;}else{Langvage_Ru_Engl=true;} FileClose(hd); } //+------------------------------------------------------------------+ for(int i=0;i<100;i++){ if(iTime(Symbol(),1440,i)<1){ i--; if(Langvage_Ru_Engl){ Comment(errdayru); }else{ Comment(errdayen); } } } //+------------------------------------------------------------------+ return;} //+------------------------------------------------------------------+ bool busy(){if(GlobalVariableCheck("busy")){return(true);}else{return(false);}} //+------------------------------------------------------------------+ void deinit(){ if(UninitializeReason()==REASON_REMOVE|| UninitializeReason()==REASON_CHARTCLOSE|| UninitializeReason()==REASON_PARAMETERS|| UninitializeReason()==REASON_RECOMPILE|| UninitializeReason()==REASON_ACCOUNT){ ObjectDelete("cpo"); ObjectDelete("exp"); ObjectDelete("cnm"); ObjectDelete("oicpo"); ObjectDelete("oiexp"); ObjectDelete("oicnm"); delgr(); int prewtime =0; } Comment(" "); return;} //+------------------------------------------------------------------+ void start(){//return; static int pc =0;int col; int x,i,tm0,tm1;string mode = ""; static int asd=0,sinerr = 30; static string tmexp,contrnm; //-------------------------------------------------------------------+ col = GetWndColor(Symbol()); if(col>0){ Option_Call_Color = Pink;// Call_In_Money_Clr = Blue;// Option_Put_Color = LightBlue;// Put_In_Money_Clr = Red;// }else{ Option_Call_Color = FireBrick;// Call_In_Money_Clr = DodgerBlue;// Option_Put_Color = MidnightBlue;// Put_In_Money_Clr = Coral;// } if(col!=pc){pc=col;prewtime=0;} //-------------------------------------------------------------------+ if(sinerr<=0){ if(Langvage_Ru_Engl){ Comment(faterrru); }else{ Comment(faterren); } return; } if(iTime(Symbol(),1440,i)<1){ if(Langvage_Ru_Engl){ Comment(faterrru,"\nНедостаточно истории по ТФ D1"); }else{ Comment(faterren,"\nEnough history on D1 TimeFrame"); } return; } if(newday()){recalcdate();asd=0;} //----блок проверки символа на сооответствие списку------------------+ static int wc=0,errcount=0; //---- if(SymbolSet==""){SymbolSet=SymbolControl();} if(SymbolControl()=="404"){ request(symbols); sinerr--; if(Langvage_Ru_Engl){ Comment(errsinru,sinerr," сек"); }else{ Comment(errsinen,sinerr," sec"); } return; } //---- if(SymbolSet==""){ if(Langvage_Ru_Engl){ Comment(nolistru,"\n",entnamru); }else{ Comment(nolisten,"\n",entnamen); } return; } //----Запрашиваем и выводим данные-----------------------------------+ static int filecount=0; bool c; bool first=true; int maxday; string filenm; //---- maxday = ArraySize(date)-1; if(prewtime>TimeCurrent()){return;} if(!ShowHistory){ prewtime=TimeCurrent()+300; filecount=0; filenm = SymbolSet+date[filecount]+ext; if(!busy()){request(filenm);}else{prewtime=TimeCurrent()+10;Print("wait 10 sek");return;} }else{ if(filecount>=maxday){ prewtime=TimeCurrent()+300; recalcdate(); filecount=0; filenm = SymbolSet+date[filecount]+ext; if(!busy()){request(filenm);}else{prewtime=TimeCurrent()+10;Print("wait 10 sek");return;} } } filenm = SymbolSet+date[filecount]+ext; if(date[filecount]==0){recalcdate();return;} if(filecount!=0){if(isfile(filenm)!=0){if(!busy()){request(filenm);}else{prewtime=TimeCurrent()+10;Print("wait 10 sek");return;}}} if(errcount>2){ date[filecount]=0; filecount++; errcount=0; } if(!ReadFile(filenm,date[filecount])){errcount++;return;} if(date[0]==0){ if(Langvage_Ru_Engl){ Comment(erronlru); }else{ Comment(erronlen); } }else{Comment(" ");} int razm = ArraySize(in)-1; if(TimeHour(TimeCurrent())+(timesdvig()/3600)<0){i=1;}else{i=0;} if(date[filecount]>=StrToTime(TimeToStr(TimeCurrent()-(86400*i),TIME_DATE))){//только свежие данные if(IsTesting()||IsVisualMode()||IsOptimization()){ ShowHistory=false; OnlineFontSize=HistoryFontSize; if(Period()>5){ if(Langvage_Ru_Engl){ Comment(indvisru); }else{ Comment(indvisen); } } if(StrToInteger(StringSubstr(in[asd],0,10))Close[0]){ SetTLine(true,Put_In_Money_Clr,"Put", tm0,putprs,tm1,putprs,WidthOlineLines,putvol); SetText(true,Put_In_Money_Clr,tm0+Period()*180,putprs," "+DoubleToStr(putvol,0),OnlineFontSize); } }else{ if(ShowActiveColor){ if(putprs>Close[0]){ SetTLine(true,Put_In_Money_Clr,"Put", tm0,putprs,tm1,putprs,WidthOlineLines,putvol); SetText(true,Put_In_Money_Clr,tm0+Period()*180,putprs," "+DoubleToStr(putvol,0),OnlineFontSize); }else{ SetTLine(true,Option_Put_Color,"Put", tm0,putprs,tm1,putprs,WidthOlineLines,putvol); SetText(true,Option_Put_Color,tm0+Period()*180,putprs," "+DoubleToStr(putvol,0),OnlineFontSize); } }else{ SetTLine(true,Call_In_Money_Clr,"Put", tm0,putprs,tm1,putprs,WidthOlineLines,putvol); SetText(true,Call_In_Money_Clr,tm0+Period()*180,putprs," "+DoubleToStr(putvol,0),OnlineFontSize); } } } } pos=StringFind(in[i],",",1); tmexp = TimeToStr(((StrToInteger(StringSubstr(in[i],1,pos-1))-25569)*86400),TIME_DATE); in[i]=StringSubstr(in[i],pos); pos=StringFind(in[i],",",1); contrnm = StringSubstr(in[i],1,pos-1); in[i]=StringSubstr(in[i],pos); pos=StringFind(in[i],",",1); mode = StringSubstr(in[i],1,pos-1); first=false; if(Lite){ double br0 = iBarShift(Symbol(),0,tm1); double br1 = iBarShift(Symbol(),0,tm0); int nco = MathMax(br0,br1); for(x=0;x=High[x]&&online[xy][3]>0){break;}} if(online[xy][2]!=0){resist[x]=online[xy][2];} for(xy=0;xy<15;xy++){if(online[xy][0]>=High[x]&&online[xy][0]=0;xy--){if(online[xy][0]<=Low[x]&&online[xy][1]>0){break;}} if(online[xy][1]!=0){support[x]=online[xy][0];} for(xy=14;xy>=0;xy--){if(online[xy][2]<=Low[x]&&online[xy][2]>support[x]){break;}} if(online[xy][2]!=0){supstop[x]=online[xy][2];}else{supstop[x]=support[x];} } } if(!ShowHistory){if(filecount>0){filecount=0;return;}} ArrayCopy(in,copy,0,0,WHOLE_ARRAY); }else{razm++;}//онлайн данные if(ShowHistory){// плюс история for(i=razm;i>0;i--){ tm0=StrToInteger(StringSubstr(in[i],0,10)); tm1=StrToInteger(StringSubstr(in[i-1],0,10)); if (tm1==0){tm1=date[filecount];} in[i]=StringSubstr(in[i],10); for(x=0;x<15;x++){ pos=StringFind(in[i],",",1); callprs =nd(StrToDouble(StringSubstr(in[i],1,pos))); online[x][0]=callprs; in[i]=StringSubstr(in[i],pos); pos=StringFind(in[i],",",1); callvol =nd(StrToDouble(StringSubstr(in[i],1,pos))); online[x][1]=callvol; in[i]=StringSubstr(in[i],pos); pos=StringFind(in[i],",",1); putprs =nd(StrToDouble(StringSubstr(in[i],1,pos))); online[x][2]=putprs; in[i]=StringSubstr(in[i],pos); pos=StringFind(in[i],",",1); putvol =nd(StrToDouble(StringSubstr(in[i],1,pos))); online[x][3]=putvol; in[i]=StringSubstr(in[i],pos); if(Pro){ if(nearest){ if(x>near1&&xiHigh(Symbol(),0,iBarShift(Symbol(),0,tm1))||putprs>iHigh(Symbol(),0,iBarShift(Symbol(),0,tm0))){ SetTLine(geraze,Put_In_Money_Clr,"Put", tm0,putprs,tm1,putprs,WidthHistoryLines,putvol); if(ShowHistoryVolumes){SetText(geraze,Put_In_Money_Clr,tm1,putprs," "+DoubleToStr(putvol,0),HistoryFontSize);} } }else{ if(ShowActiveColor){ if(putprs>iHigh(Symbol(),0,iBarShift(Symbol(),0,tm1))||putprs>iHigh(Symbol(),0,iBarShift(Symbol(),0,tm0))){ SetTLine(geraze,Put_In_Money_Clr,"Put", tm0,putprs,tm1,putprs,WidthHistoryLines,putvol); if(ShowHistoryVolumes){SetText(geraze,Put_In_Money_Clr,tm1,putprs," "+DoubleToStr(putvol,0),HistoryFontSize);} }else{ SetTLine(geraze,Option_Put_Color,"Put", tm0,putprs,tm1,putprs,WidthHistoryLines,putvol); if(ShowHistoryVolumes){SetText(geraze,Option_Put_Color,tm1,putprs," "+DoubleToStr(putvol,0),HistoryFontSize);} } }else{ SetTLine(geraze,Call_In_Money_Clr,"Put", tm0,putprs,tm1,putprs,WidthHistoryLines,putvol); if(ShowHistoryVolumes){SetText(geraze,Call_In_Money_Clr,tm1,putprs," "+DoubleToStr(putvol,0),HistoryFontSize);} } } } } }//if(nearest){else }//if(Pro) } if(Lite){ nco = iBarShift(Symbol(),0,tm1-timesdvig()); int nca = iBarShift(Symbol(),0,tm0-timesdvig()); for(x=nca;x=High[x]&&online[xy][3]>0){break;}} if(online[xy][2]!=0){resist[x]=online[xy][2];} for(xy=0;xy<15;xy++){if(online[xy][0]>=High[x]&&online[xy][0]=0;xy--){if(online[xy][0]<=Low[x]&&online[xy][1]>0){break;}} if(online[xy][1]!=0){support[x]=online[xy][0];} for(xy=14;xy>=0;xy--){if(online[xy][2]<=Low[x]&&online[xy][2]>support[x]){break;}} if(online[xy][2]!=0){supstop[x]=online[xy][2];}else{supstop[x]=support[x];} } } } } if(filecount=0){return(true);}else{return(false);}} //+------------------------------------------------------------------+ void recalcdate(){days = DepthHistoryInDays; ArrayResize(date,100); ArrayInitialize(date,0); int x=0; int time_0=TimeHour(TimeCurrent())+(timesdvig()/3600); if(time_0<0){days++;} for(int i=0;i<=days;i++){ if(i==0){if(time_0<0){i=1;}} if(TimeDayOfWeek(StrToTime(TimeToStr(TimeCurrent()-(86400*i),TIME_DATE)))!=0&& TimeDayOfWeek(StrToTime(TimeToStr(TimeCurrent()-(86400*i),TIME_DATE)))!=6){ date[x]=StrToTime(TimeToStr(TimeCurrent()-(86400*i),TIME_DATE)); x++; }else{days++;} } ArrayResize(date,x); return; } //+------------------------------------------------------------------+ void delgr(){ for(int i=ObjectsTotal();i>=0;i--){ if("txt"==StringSubstr(ObjectName(i),0,3)){ObjectDelete(ObjectName(i));} if("option"==StringSubstr(ObjectName(i),0,6)){ObjectDelete(ObjectName(i));} if("onl"==StringSubstr(ObjectName(i),0,3)){ObjectDelete(ObjectName(i));} if("online"==StringSubstr(ObjectName(i),0,6)){ObjectDelete(ObjectName(i));} ObjectDelete("cpo"); } geraze = true; return; } //+------------------------------------------------------------------+ void delonl(){ for(int i=ObjectsTotal();i>=0;i--){ if("onl"==StringSubstr(ObjectName(i),0,3)){ObjectDelete(ObjectName(i));} if("online"==StringSubstr(ObjectName(i),0,6)){ObjectDelete(ObjectName(i));} } return; } //+------------------------------------------------------------------+ string SymbolControl(){string in[100];string sy="404";int hd; hd=FileOpen(symbols,FILE_CSV|FILE_READ,";"); if(hd<0){return(sy);} sy=""; for(int i=0;i<100;i++){ in[i]=FileReadString(hd); if(FileIsEnding(hd)){break;} } ArrayResize(in,i); FileClose(hd); for(int x=0;x<=i;x++){ if(StringFind(in[x],Symbol(),0)>=0){ int count=StringFind(in[x],",",0); sy=StringSubstr(in[x],0,count); } } return(sy); } //+------------------------------------------------------------------+ double nd(double in){return(NormalizeDouble(in,Digits));} //+------------------------------------------------------------------+ void SetLabel(string nm, string tx, color cl, int xd, int yd, int cr=0, int fs=9) {//if(Lite){return;} if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_LABEL, 0, 0,0); ObjectSetText(nm, tx,fs,"Times new roman", cl); ObjectSet(nm, OBJPROP_COLOR , cl); ObjectSet(nm, OBJPROP_XDISTANCE, xd); ObjectSet(nm, OBJPROP_YDISTANCE, yd); ObjectSet(nm, OBJPROP_CORNER , cr); ObjectSet(nm, OBJPROP_FONTSIZE , fs); ObjectSet(nm, OBJPROP_BACK , false); } //+------------------------------------------------------------------+ void SetText(bool eraze,color cl,int t1,double p1,string tx="",int razm=8){string nm;//if(Lite){return;} if(!eraze){ nm="txt"+tx+DoubleToStr(p1,Digits); if(ObjectFind(nm)<0){ ObjectCreate(nm, OBJ_TEXT, 0, 0,0, 0,0); ObjectSet(nm, OBJPROP_TIME1 , t1-timesdvig()); ObjectSet(nm, OBJPROP_PRICE1, p1); ObjectSetText(nm,tx,razm,FontName,cl); ObjectSet(nm, OBJPROP_BACK , false); } }else{ nm="onl"+tx+DoubleToStr(p1,Digits); ObjectCreate(nm, OBJ_TEXT, 0, 0,0, 0,0); ObjectSet(nm, OBJPROP_TIME1 , t1-timesdvig()); ObjectSet(nm, OBJPROP_PRICE1, p1); ObjectSetText(nm,tx,razm,FontName,cl); ObjectSet(nm, OBJPROP_BACK , false); } return; } //+------------------------------------------------------------------+ void SetTLine(bool eraze, color cl, string nm="", datetime t1=0, double p1=0, datetime t2=0, double p2=0, int wd=1, int vol=0) {string nmm;//if(Lite){return;} if(!eraze){nmm="option";}else{nmm="online";} nm = nmm + nm + " Prise="+DoubleToStr(p1,4)+ " Volume="+vol+ " Time"+TimeToStr(t2-timesdvig(),TIME_DATE|TIME_MINUTES); if (t1<=0) t1=Time[10]; if (p1<=0) p1=Low[10]; if (t2<=0) t2=Time[0]; if (p2<=0) p2=Bid; if(!eraze){ if(ObjectFind(nm)<0){ObjectCreate(nm, OBJ_TREND, 0, 0,0, 0,0);} }else{ ObjectCreate(nm, OBJ_TREND, 0, 0,0, 0,0); } ObjectSet(nm, OBJPROP_TIME1 , t1-timesdvig()); ObjectSet(nm, OBJPROP_PRICE1, p1); ObjectSet(nm, OBJPROP_TIME2 , t2-timesdvig()); ObjectSet(nm, OBJPROP_PRICE2, p2); ObjectSet(nm, OBJPROP_COLOR , cl); ObjectSet(nm, OBJPROP_RAY , false); ObjectSet(nm, OBJPROP_STYLE , 0); ObjectSet(nm, OBJPROP_WIDTH , wd); ObjectSet(nm, OBJPROP_BACK , false); } //+------------------------------------------------------------------+ bool ReadFile(string fn,int tm){int i, hd; ArrayResize(in,1000); hd=FileOpen(fn,FILE_CSV|FILE_READ,";"); if(hd<0){return(false);} string res=FileReadString(hd); if(res=="404"){ FileClose(hd); return(false); } FileSeek(hd,SEEK_SET,0); for(i=0;i<1000;i++){ res=FileReadString(hd); if(StringSubstr(res,0,2)=="12"){in[i]=res;}else{break;} if(FileIsEnding(hd)){break;} } ArrayResize(in,i); FileClose(hd); return(true); } //+------------------------------------------------------------------+ int isfile(string fn){ int hd = FileOpen(fn,FILE_CSV|FILE_READ,";"); if( hd>0){ string res=FileReadString(hd); if(res=="404"){ FileClose(hd); return(404); } FileClose(hd); return(0); }else{return(GetLastError());} } int GetWndColor(string sy) { int hWnd = WindowHandle(sy, Period()); int hDC = GetWindowDC(hWnd); int rect[4]; GetWindowRect(hWnd, rect); int wW = rect[2] - rect[0]; // ширина окна int wH = rect[3] - rect[1]; // высота окна int col = GetPixel(hDC, 2, 2); if(col==-1) // левый верхний угол не виден { col = GetPixel(hDC, wW-3, wH-3); if(col==-1) // правый нижний угол не виден col = GetPixel(hDC, 2, wH-3); if(col==-1) // левый нижний угол не виден col = GetPixel(hDC, wW-3, 2); if(col==-1) // правый верхний угол не виден { ReleaseDC(hWnd, hDC); return(Win_color); } } ReleaseDC(hWnd, hDC); return(col); } //+------------------------------------------------------------------+