Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 149
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
Good afternoon.
Can you tell me how to find the right bar by date and time without going through all the bars one by one?
Good afternoon.
Can you tell me how to find the right bar by date and time without going through all the bars one by one?
Read about iBarShift
int TotalPos=-1;
void start()
{
//the rest of the code
//--
if(OrdersTotal()!=TotalPos) { // do not torture every tick
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if(OrderSymbol()==Symbol() && OrderType()<=1) {
History();
}
}}} TotalPos=OrdersTotal(); // remember quantity
//--
}
void History() {
string Ticket=(string)OrderTicket();
color col=Red;
if(OrderType()==0)col=Blue;
datetime a=OrderOpenTime();
double b=OrderOpenPrice();
datetime c=OrderCloseTime();
double d=OrderClosePrice();
double prSep=OrderProfit()+OrderCommission()+OrderSwap();
double prAll=0;
int cn=0;
string hTicket;
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if(OrderSymbol()==Symbol() && OrderType()<=1) {
datetime ct=OrderCloseTime();
// 60 seconds difference between the close of the first and last order in the grid
if(c<=ct+60 && c>=ct-60) {
prAll+=OrderProfit()+OrderCommission()+OrderSwap();
hTicket=(string)OrderTicket();
cn++;
}
}}}
ObjectCreate(Ticket+"Open",OBJ_ARROW,0,a,b);
ObjectSet(Ticket+"Open",OBJPROP_COLOR,col);
ObjectSet(Ticket+"Open",OBJPROP_ARROWCODE,1);
ObjectCreate(Ticket+"Line",OBJ_TREND,0,a,b,c,d);
ObjectSet(Ticket+"Line",OBJPROP_COLOR,col);
ObjectSet(Ticket+"Line",OBJPROP_WIDTH,1);
ObjectSet(Ticket+"Line",OBJPROP_STYLE,STYLE_DOT);
ObjectSet(Ticket+"Line",OBJPROP_RAY,0);
ObjectCreate(Ticket+"Close",OBJ_ARROW,0,c,d);
ObjectSet(Ticket+"Close",OBJPROP_COLOR,Green);
ObjectSet(Ticket+"Close",OBJPROP_ARROWCODE,3);
Ticket=cn>1?hTicket:Ticket;
ObjectCreate(Ticket+"Profit",OBJ_TEXT,0,c,d);
ObjectSet(Ticket+"Profit",OBJPROP_ANCHOR,0);
ObjectSetText(Ticket+"Profit",DoubleToString(prAll,2),10, "Arial",White);
ObjectSet(Ticket+"Profit",OBJPROP_PRICE1,d);
ObjectSet(Ticket+"Profit",OBJPROP_TIME1,c+Period()*60*2);
}
what to add to the code of this function to draw a level line in these places of the trades
coordinate from the trades to the border of the chart offset
Please help with reading from a .crv file
file has the following entry :
2010.03.18 01:35:00;1.37409;1.37119
how to write code to get each value separately in a variable
Please help with reading from a .crv file
file has the following entry :
2010.03.18 01:35:00;1.37409;1.37119
how to write code to get each value separately in a variable
int TotalPos=-1;
void start()
{
//the rest of the code
//--
if(OrdersTotal()!=TotalPos) { // do not torture every tick
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if(OrderSymbol()==Symbol() && OrderType()<=1) {
History();
}
}}} TotalPos=OrdersTotal(); // remember quantity
//--
}
void History() {
string Ticket=(string)OrderTicket();
color col=Red;
if(OrderType()==0)col=Blue;
datetime a=OrderOpenTime();
double b=OrderOpenPrice();
datetime c=OrderCloseTime();
double d=OrderClosePrice();
double prSep=OrderProfit()+OrderCommission()+OrderSwap();
double prAll=0;
int cn=0;
string hTicket;
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if(OrderSymbol()==Symbol() && OrderType()<=1) {
datetime ct=OrderCloseTime();
// 60 seconds difference between the close of the first and last order in the grid
if(c<=ct+60 && c>=ct-60) {
prAll+=OrderProfit()+OrderCommission()+OrderSwap();
hTicket=(string)OrderTicket();
cn++;
}
}}}
ObjectCreate(Ticket+"Open",OBJ_ARROW,0,a,b);
ObjectSet(Ticket+"Open",OBJPROP_COLOR,col);
ObjectSet(Ticket+"Open",OBJPROP_ARROWCODE,1);
ObjectCreate(Ticket+"Line",OBJ_TREND,0,a,b,c,d);
ObjectSet(Ticket+"Line",OBJPROP_COLOR,col);
ObjectSet(Ticket+"Line",OBJPROP_WIDTH,1);
ObjectSet(Ticket+"Line",OBJPROP_STYLE,STYLE_DOT);
ObjectSet(Ticket+"Line",OBJPROP_RAY,0);
ObjectCreate(Ticket+"Close",OBJ_ARROW,0,c,d);
ObjectSet(Ticket+"Close",OBJPROP_COLOR,Green);
ObjectSet(Ticket+"Close",OBJPROP_ARROWCODE,3);
Ticket=cn>1?hTicket:Ticket;
ObjectCreate(Ticket+"Profit",OBJ_TEXT,0,c,d);
ObjectSet(Ticket+"Profit",OBJPROP_ANCHOR,0);
ObjectSetText(Ticket+"Profit",DoubleToString(prAll,2),10, "Arial",White);
ObjectSet(Ticket+"Profit",OBJPROP_PRICE1,d);
ObjectSet(Ticket+"Profit",OBJPROP_TIME1,c+Period()*60*2);
}
what to add to the code of this function to draw a level line in these places of the trades
coordinate from the trades to the border of the chart offset
something like this :
string level="Level"+IntegerToString(iTime(_Symbol,iBarShift(OrderCloseTime())); // ид.уровня - по времени бара (!! не по тикету)
if (ObjectFind(level)==-1) {
// гор.вектора нет - видимо первый ордер из закрытых на баре
// сделать горизонтальную линию
ObjectCreate(0,level,OBJ_TREND,0,OrderCloseTime(),OrderClosePrice(),OrderCloseTime()+PeriodSeconds(_Period)*3,OrderClosePrice);
// указывающую только вправо
ObjectSetInteger(level,OBJPROP_RAY,1);
ObjectSetInteger(level,OBJPROP_RAYLEFT,0);
// украсить её как-то :-)
ObjectSetInteger(level,OBJPROP_COLOR,....)
....
} else {
// гор.уровень есть - значит были ордера закрытые на этом баре
// по фантазии - обновить метки/корректировать уровень/etc
}
Good afternoon!
What are the reasons for the terminal not seeing a robot? it was written by a local programmer. The other robots are partly visible and partly not.
Good afternoon!
What are the reasons for the terminal not seeing a robot? it was written by a local programmer. The other robots are partly visible and partly not.
Good evening!
Please help me to write this code, I feel I can't do it myself:
When i run an EA on EURUSD i should place two pending orders if i don't have any open/pending orders on this pair,
If one of them triggered, another one is not shown, i.e. the total sum of all pending orders on the pair should not exceed 2 and it should not take into account pending/open orders already shown on other pairs.
I've already racked my brains, it doesn't place anything at all, then every tick it places.
I am very thankful for it.
I will be very thankful for it.
Good afternoon!
What are the reasons for the terminal not seeing a robot? it was written by a local programmer. The other robots are partly visible and partly not.
The robot should be located in the "experts" folder and be in the form of *.ex4 (*.ex5 for 5).
In the terminal - menu "File/Open Data Folder" then "MQL4/Experts".
And the *.mq4 *.mq5 source code will not start - it needs to be compiled.
And in the meantime, tear the head off the programmer who did not tell you how to use his product