//+------------------------------------------------------------------+ //| +OPTIONS_VOLUME.mq4 | //| Copyright © 2009, Xrust Solution. | //| http://www.xrust.uco.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Xrust Solution." #property link "http://www.xrust.uco.net" #property indicator_chart_window extern string префикс = ""; extern string суффикс = ""; extern int Фильтр_по_обьему = 0; extern bool Показыватьисторию = true; extern bool Показыватьистобьем = true; extern int ГлубинаИсторииБаров = 300; extern int размер_шрифта = 15; extern int Толщина_линий = 3; extern int размер_шр_ист = 10; extern int Толщина_ист_линий = 2; extern color Цвет_Опциона_PUT = Blue; extern color Цвет_Опциона_CALL = Red; extern string имя_шрифта = "Times New Roman"; #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 "wininet.dll" int InternetAttemptConnect (int x); int InternetOpenA(string sAgent, int lAccessType, string sProxyName = "", string sProxyBypass = "", int lFlags = 0); int InternetOpenUrlA(int hInternetSession, string sUrl, string sHeaders = "", int lHeadersLength = 0,int lFlags = 0, int lContext = 0); int InternetReadFile(int hFile, int& sBuffer[], int lNumBytesToRead,int& lNumberOfBytesRead[]); int InternetCloseHandle(int hInet); #import double in[61][4]; double hist[1000][61]; double prom[61]; int Win_color;int bar_count; string inetpacth="http://xrust.land.ru//"; string name=""; string fn,histfn; //+------------------------------------------------------------------+ void init(){int len=0,strlen=0;name=Symbol(); if(префикс!=""){len=StringLen(префикс)-1;name=StringSubstr(Symbol(),len,0);} if(суффикс!=""){len=StringLen(суффикс);strlen=StringLen(Symbol());name=StringSubstr(Symbol(),0,(strlen-len+1));} fn=name+".csv"; histfn=name+"_opt_hist.csv"; return;} //+------------------------------------------------------------------+ void deinit(){ if(UninitializeReason()==REASON_REMOVE||UninitializeReason()==REASON_CHARTCLOSE){ FileDelete(fn); int h = FileOpen(histfn, FILE_CSV|FILE_WRITE); FileClose(h); delgr(); } return;} //+------------------------------------------------------------------+ int start() {static int prewtime,prewbar,maxbar; int indco=IndicatorCounted(); if(indco-Bars<-1){delgr();return;} //---- if(GetWndColor(Symbol())>0){color txcol=Black;}else{txcol=White;} if(prewtimeiTime(Symbol(),0,ГлубинаИсторииБаров)){ double z=0; double lp1,lp2; for(int y=1;y<59;y=y+2){z++; if(MathMod(z,2)>0){ if(hist[x][y+1]>Фильтр_по_обьему){ SetTLine(false,Цвет_Опциона_CALL,"Call", tm0,hist[x][y],tm1,hist[x][y],Толщина_ист_линий,hist[x][y+1]); if(lp1!=hist[x][y]){ if(Показыватьистобьем){SetText(false,Цвет_Опциона_CALL,tm1,hist[x][y],DoubleToStr(hist[x][y+1],0),размер_шр_ист);} lp1=hist[x][y]; } } }else{ if(hist[x][y+1]>Фильтр_по_обьему){ SetTLine(false,Цвет_Опциона_PUT,"Put", tm0,hist[x][y],tm1,hist[x][y],Толщина_ист_линий,hist[x][y+1]); if(lp1!=hist[x][y]){ if(Показыватьистобьем){SetText(false,Цвет_Опциона_PUT,tm1,hist[x][y]," "+DoubleToStr(hist[x][y+1],0),размер_шр_ист);} lp1=hist[x][y]; } } } } } } } int a=ArrayRange(in,0); for(int i=0;i<15;i++){ if(in[i][1]>Фильтр_по_обьему){ SetText(true,Цвет_Опциона_CALL,Time[0],in[i][0],DoubleToStr(in[i][1],0),размер_шрифта); SetTLine(true,Цвет_Опциона_CALL,"Call", Time[1],in[i][0],Time[0]+Period()*300,in[i][0],Толщина_линий,in[i][1]); } if(in[i][3]>Фильтр_по_обьему){ SetText(true,Цвет_Опциона_PUT,Time[0],in[i][2]," "+DoubleToStr(in[i][3],0),размер_шрифта); SetTLine(true,Цвет_Опциона_PUT,"Put", Time[1],in[i][2],Time[0]+Period()*300,in[i][2],Толщина_линий,in[i][3]); } } string copyrite="OptionsLevels&VolumesXR © "; SetLabel("cpo",copyrite,txcol,1,1,3,9); return(0); } 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));} ObjectDelete("cpo"); } return; } //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ void readinet(string nm,string inetnm){ //if(nm==""){nm=Symbol()+".csv";}else{nm=nm+".csv";} if(!IsDllsAllowed()){ Alert("Необходимо в настройках разрешить использование DLL"); return(0); } int rv = InternetAttemptConnect(0); if(rv != 0){ Print("Ошибка при вызове InternetAttemptConnect()"); return(0); } int hInternetSession = InternetOpenA("Microsoft Internet Explorer",0, "", "", 0); if(hInternetSession <= 0){ Print("Ошибка при вызове InternetOpenA()"); return(0); } int hURL = InternetOpenUrlA(hInternetSession,inetpacth+inetnm+"?z="+TimeCurrent(), "", 0, 0, 0); if(hURL <= 0){ Print("Ошибка при вызове InternetOpenUrlA()"); InternetCloseHandle(hInternetSession); return; } int cBuffer[256]; ArrayInitialize(cBuffer,0); int dwBytesRead[1]; ArrayInitialize(dwBytesRead,0); string TXT = ""; while(!IsStopped()){ bool bResult = InternetReadFile(hURL, cBuffer, 1024, dwBytesRead); if(dwBytesRead[0] == 0)break; string text = ""; for(int i = 0; i < 256; i++){ text = text + CharToStr(cBuffer[i] & 0x000000FF); if(StringLen(text) == dwBytesRead[0])break; text = text + CharToStr(cBuffer[i] >> 8 & 0x000000FF); if(StringLen(text) == dwBytesRead[0])break; text = text + CharToStr(cBuffer[i] >> 16 & 0x000000FF); if(StringLen(text) == dwBytesRead[0])break; text = text + CharToStr(cBuffer[i] >> 24 & 0x000000FF); if(StringLen(text) == dwBytesRead[0])break; } TXT = TXT + text; Sleep(1); } if(TXT != ""){ int h = FileOpen(nm, FILE_CSV|FILE_WRITE); if(h>0){ FileWrite(h,TXT); FileClose(h); }else{ int err=GetLastError(); Print(nm," Ошибка при вызове FileOpen() № ",err); } }else{Print("Нет считанных данных");} InternetCloseHandle(hInternetSession); return;} //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ 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); } //+------------------------------------------------------------------+ void SetLabel(string nm, string tx, color cl, int xd, int yd, int cr=0, int fs=9) { if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_LABEL, 0, 0,0); ObjectSetText(nm, tx,fs,имя_шрифта, 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="txt"+tx+DoubleToStr(p1,Digits); if(ObjectFind(nm)<0)ObjectCreate(nm, OBJ_TEXT, 0, 0,0, 0,0); ObjectSet(nm, OBJPROP_TIME1 , t1); ObjectSet(nm, OBJPROP_PRICE1, p1); ObjectSetText(nm,tx,razm,имя_шрифта,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) { nm="option "+nm+" Strike="+DoubleToStr(p1,4)+" Volume="+vol+" Time"+TimeToStr(t1,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(ObjectFind(nm)<0)ObjectCreate(nm, OBJ_TREND, 0, 0,0, 0,0); ObjectSet(nm, OBJPROP_TIME1 , t1); ObjectSet(nm, OBJPROP_PRICE1, p1); ObjectSet(nm, OBJPROP_TIME2 , t2); 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); ObjectSetText(nm,DoubleToStr(vol,0),3,"Arial",White); ObjectSet(nm, OBJPROP_BACK , false); } //+------------------------------------------------------------------+ bool WriteHistory(){bool write=false;int i,a=0;int hd; string last=TimeCurrent()+","; ArrayInitialize(hist,0); ArrayInitialize(prom,0); hd=FileOpen(histfn,FILE_CSV|FILE_READ); if(hd<0){ readinet(histfn,histfn); }else{ if(FileSize(hd)<500){readinet(histfn,histfn);} hd=FileOpen(histfn,FILE_CSV|FILE_READ|FILE_WRITE,","); int razm=FileSize(hd); int pos; int x=0,y=0; for(i=0;i