Labels have an anchor point... a specified number of pixels from top left, top right, bottom left, or bottom right, and expand from there. Change the anchor to top or bottom left.
I have a box with 6 rows and 6 columns and I want to put it at the bottom of that but that is anchored to the top right so just setting this label at present means it changes whether the screen is minimsed or full.
It is the alerttext label that keeps moving dependent on screen size. I locked it to the top left but the x setting is relative to the top left no matter whether the screen is maximised or not so I only see it in the correct place for 1 screen size.
int init() { // table of signals for(int x=0;x<6;x++) for(int y=0;y<5;y++) //y here is number of rows { if (y<3) { ObjectCreate("signal"+x+y,OBJ_LABEL,0,0,0,0,0); ObjectSet("signal"+x+y,OBJPROP_CORNER,corner); ObjectSet("signal"+x+y,OBJPROP_XDISTANCE,x*scaleX+offsetX); ObjectSet("signal"+x+y,OBJPROP_YDISTANCE,y*scaleY+offsetY); ObjectSetText("signal"+x+y,CharToStr(symbolCodeNoSignal),fontSize,"Wingdings",noSignalColor); } if (y>=3) {//we don't want six boxes for these 2, just a title and a text label to show the pips/alert ObjectCreate("signal"+x+y,OBJ_LABEL,0,0,0,0,0); ObjectSet("signal"+x+y,OBJPROP_CORNER,corner); ObjectSet("signal"+x+y,OBJPROP_XDISTANCE,x*scaleX+offsetX); ObjectSet("signal"+x+y,OBJPROP_YDISTANCE,y*scaleY+offsetY); ObjectSetText("signal"+x+y,"{Alert text here}",8,"Tahoma",Black); } } // names of timeframes for(x=0;x<6;x++) { ObjectCreate("textPeriod"+x,OBJ_LABEL,0,0,0,0,0); ObjectSet("textPeriod"+x,OBJPROP_CORNER,corner); ObjectSet("textPeriod"+x,OBJPROP_XDISTANCE,x*scaleX+offsetX); ObjectSet("textPeriod"+x,OBJPROP_YDISTANCE,offsetY-15); ObjectSetText("textPeriod"+x,periodString[x],8,"Tahoma",textColor); } // names of indicators for(y=0;y<5;y++) { ObjectCreate("textSignal"+y,OBJ_LABEL,0,0,0,0,0); ObjectSet("textSignal"+y,OBJPROP_CORNER,corner); ObjectSet("textSignal"+y,OBJPROP_XDISTANCE,offsetX+125); ObjectSet("textSignal"+y,OBJPROP_YDISTANCE,y*scaleY+offsetY+0); ObjectSetText("textSignal"+y,signalNameString[y],8,"Tahoma",textColor); } //alert text ObjectCreate("alerttext",OBJ_LABEL,0,0,0,0,0); ObjectSet("alerttext",OBJPROP_CORNER,0); ObjectSet("alerttext",OBJPROP_XDISTANCE,153); ObjectSet("alerttext",OBJPROP_YDISTANCE,100); ObjectSetText("alerttext","Helloooooooooooooooooooooooo",8,"Tahoma",Blue); }
Any ideas?
Every time I choose a right anchor (top right or bottom right), the text is right justified so it is impossible to list some text in the same place without it moving to the left.
Everytime I anchor it at the top left or bottom left, I cannot get it to appear on the right hand side of the screen unless the window is maximised.
I guess I'll have to anchor it to the right and then adjust the offset for each sentence.
What a crap way of doing it :(
int draw_new_row(string col1, string col2) { string n; color c=ClockColor; //column 1 n="timelabel-col1-row"+num_rows; ObjectCreate(n,OBJ_LABEL,0,0,0); ObjectSet(n,OBJPROP_CORNER,corner_position); ObjectSet(n,OBJPROP_XDISTANCE,col1_xdist+(fontsize*2.7)); ObjectSet(n,OBJPROP_YDISTANCE,num_rows*(fontsize+2)+y_offset+50); ObjectSetText(n,col1,fontsize,fontname,ClockColor); //column 2 if ((col1 == "BlncChng") || (col1 == "EqtyChng")) if (StrToDouble(col2)<0.0) c=Red; n="timelabel-col2-row"+num_rows; ObjectCreate(n,OBJ_LABEL,0,0,0); ObjectSet(n,OBJPROP_CORNER,corner_position); ObjectSet(n,OBJPROP_XDISTANCE,col2_xdist); ObjectSet(n,OBJPROP_YDISTANCE,num_rows*(fontsize+2)+y_offset+50); ObjectSetText(n,col2,fontsize,fontname,c); return(num_rows+1); }
The way I did it was to create two separate labels. num_rows is a global variable so i could keep track of the number of, well, rows. on init(), num_rows is zero'd.
num_rows=0;
int start() {
num_rows=draw_new_row("cows:",DoubleToStr(number_of_cows,0));
num_rows=draw_new_row("horses:",DoubleToStr(number_of_horses,0));
num_rows=draw_new_row(" "," "); // space, creates a nice visual separator
num_rows=draw_new_row("chickens:",DoubleToStr(number_of_chickens,0));
return (0);
}
This draws the probably useless information that you would expect it to...
I realize I could've done better with the num_rows thing, but it's used elsewhere and, again, that's just the way I did it.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am placing text in a label but as soon as the text length expands, instead of the text moving to the right, it moves off to the left like it is right justified or something.
Any ideas?