share utility code
//+------------------------------------------------------------------+ //| Get indicator value back | //+------------------------------------------------------------------+ double GetIndicator(int handle, int buffer_num, int index) { //--- array for the indicator values double arr[]; //--- obtain the indicator value in the last two bars if (CopyBuffer(handle, buffer_num, 0, index+1, arr) <= 0) { Sleep(5); for(int i=0; i<100; i++) { if (BarsCalculated(handle) > 0) break; Sleep(50); } int copied = CopyBuffer(handle, buffer_num, 0, index+1, arr); if (copied <= 0) { Print("CopyBuffer Failed. Error = ", GetLastError()); return -1; } else { IndicatorRelease(handle); return (arr[index]); } } else { IndicatorRelease(handle); return (arr[index]); } IndicatorRelease(handle); return 0; }
Thank you for Replay
Function code or utility code
example write text
void WriteText(string nm, string tx, color cl, int xd, int yd, int cr=0, int fs=14 ,string fnt="Arial") { if (ObjectFind(0,nm)<0) ObjectCreate(0,nm, OBJ_LABEL, 0, 0,0); ObjectSetString(0,nm,OBJPROP_TEXT,tx); ObjectSetInteger(0,nm,OBJPROP_COLOR,cl); ObjectSetString(0,nm,OBJPROP_FONT,fnt); ObjectSetInteger(0,nm, OBJPROP_XDISTANCE, xd); ObjectSetInteger(0,nm, OBJPROP_YDISTANCE, yd); ObjectSetInteger(0,nm, OBJPROP_CORNER , cr); ObjectSetInteger(0,nm, OBJPROP_FONTSIZE , fs); }
Below utility for create Button and edit box
void button(string name,string text,int x,int y,int xsize=50,int ysize=20,color cl=clrWhiteSmoke,color bkcl=clrGray,int fntsize=8) { ObjectCreate(0,name,OBJ_BUTTON,0,100,100); ObjectSetInteger(0,name,OBJPROP_COLOR,cl); ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bkcl); ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y); ObjectSetInteger(0,name,OBJPROP_XSIZE,xsize); ObjectSetInteger(0,name,OBJPROP_YSIZE,ysize); ObjectSetString(0,name,OBJPROP_FONT,"Arial"); ObjectSetString(0,name,OBJPROP_TEXT,text); ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fntsize); ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0); } void edit(string name,string text,int x,int y,int xsize=100,int ysize=20,color cl=clrWhiteSmoke,color bkcl=clrGray,int fntsize=10) { ObjectCreate(0,name,OBJ_EDIT,0,100,100); ObjectSetInteger(0,name,OBJPROP_COLOR,cl); ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bkcl); ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y); ObjectSetInteger(0,name,OBJPROP_XSIZE,xsize); ObjectSetInteger(0,name,OBJPROP_YSIZE,ysize); ObjectSetString(0,name,OBJPROP_FONT,"Arial"); ObjectSetString(0,name,OBJPROP_TEXT,text); ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fntsize); ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0); }
RaptorUK:
Why aren't you checking if the object already exists, you do in your WriteText() function ?
Why aren't you checking if the object already exists, you do in your WriteText() function ?
and what if x, y, xsize, ysize are negatives values ?
and if I want to create object in a subwindow ?
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
- www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Documentation on MQL5
Thanks, good idea.
FinGeR:
Thanks, good idea.
Thanks , I think you are a professional programmer and should send very utility .
Waiting for you :)
Hi
Please share useful code.