Questions from Beginners MQL5 MT5 MetaTrader 5 - page 727
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Can you tell me how to select an object when it is created, so that it doesn't lose its selection and doesn't select itself when the user deselects it. It was easy in the fourth, but it doesn't work in the fifth.
It used to be, and it worked just fine:
if(ObjectFind(chart_ID,nm)!=0) {
ObjectCreate(chart_ID,nm,OBJ_HLINE,0,0,0);
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTED,sel);
...
}
ObjectSetDouble(chart_ID,nm,OBJPROP_PRICE,p);
}
As you can see, when creating, we can select or not select the object being created at once and it will not change anymore and there will be no reference to it, but it doesn't work in the fifth one, it creates it without selection.
How to make mql5 so that the object can be selected at creation and then managed manually when needed - to select/not to select
Well, it is, but the icon doesn't stand out
if(ObjectFind(0,nm)!=0) {
ObjectCreate(0,nm,type==0?OBJ_ARROW_BUY:OBJ_ARROW_SELL,0,0,0);
ObjectSetInteger(0,nm,OBJPROP_COLOR,col);
ObjectSetInteger(0,nm,OBJPROP_SELECTED,true);
ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,true);
ObjectSetInteger(0,nm,OBJPROP_HIDDEN,false);
ObjectSetString(0,nm,OBJPROP_TOOLTIP,tooltxt);
}
ObjectSetDouble(0,nm,OBJPROP_PRICE,p);
ObjectSetInteger(0,nm,OBJPROP_TIME,t);
}
Well it is, but the icon is not highlighted
if(ObjectFind(0,nm)!=0) {
ObjectCreate(0,nm,type==0?OBJ_ARROW_BUY:OBJ_ARROW_SELL,0,0,0);
ObjectSetInteger(0,nm,OBJPROP_COLOR,col);
ObjectSetInteger(0,nm,OBJPROP_SELECTED,true);
ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,true);
ObjectSetInteger(0,nm,OBJPROP_HIDDEN,false);
ObjectSetString(0,nm,OBJPROP_TOOLTIP,tooltxt);
}
ObjectSetDouble(0,nm,OBJPROP_PRICE,p);
ObjectSetInteger(0,nm,OBJPROP_TIME,t);
}
Everything is highlighted:
Everything stands out:
I've noticed a strange feature, if you set it this way, the lines are not highlighted when you create
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTABLE,true);
But if you do the opposite, then there is no problem with selection:
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTED,sel);
For some reason, replacing summands changes the sum?
I've noticed a strange feature, if you set it this way, the lines are not highlighted when you create
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTABLE,true);
But if it's the other way round, there's no problem with selection:
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTED,sel);
For some reason, replacing summands changes the sum?
Apparently, when
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTED,sel);
last command, the chart is updated
I've noticed a strange feature, if you set it this way, it doesn't select lines when you create
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTABLE,true);
But if it's the other way round, it doesn't have any problems:
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTED,sel);
For some reason, replacing summands changes the sum?
Then you select it (but the object is not selectable), consequently nothing is selected
Then you set it as selectable. But it's "too late to drink the borjomi" ...
So here's the full code:
string tooltxt="",bool sel=false,bool back=false) {
if(ObjectFind(chart_ID,nm)<0) {
ObjectCreate(chart_ID,nm,OBJ_VLINE,0,tm,0);
ObjectSetInteger(chart_ID,nm,OBJPROP_TIME,tm);
ObjectSetInteger(chart_ID,nm,OBJPROP_BACK,back);
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTABLE,true);
ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTED,sel);
// ObjectSetInteger(chart_ID,nm,OBJPROP_SELECTABLE,true);
ObjectSetString(chart_ID,nm,OBJPROP_TOOLTIP,tooltxt);
ObjectSetInteger(chart_ID,nm,OBJPROP_COLOR,cl);
ObjectSetInteger(chart_ID,nm,OBJPROP_WIDTH,wd);
ObjectSetInteger(chart_ID,nm,OBJPROP_STYLE,st);
}
}
Yes, double-checked on all object types, and you have to put"SELECTABLE" first and then"SELECTED"
Thanks for your participation and help in solving it!
Can I suggest 1. Can I add custom indicators in 1 block? If yes, how should I do it?
2. is it possible to correct the code so that trades are opened in both directions (now, for example, if a buy trade is opened, the sell trade is not opened until the buy trade is closed)