Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1338
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
I will ask the question more correctly.
There is a block of code that explains to the Expert Advisor how many trades it needs to open. It looks like this
int OPEN=1;
if(OrdersTotal())
OPEN=0; // no more orders can be opened
if(OPEN==1)
{
//open here
}
The problem is that it opens the required number of deals (1 in this example) for all symbols. And I need to explain to him
that it needs to open this number of deals on the CURRENT instrument. Something like _Symbol or Symbol (). How it can be done? I think the solution is simple.
I will ask the question more correctly.
There is a block of code which explains to the Expert Advisor how many trades it needs to open. It looks like this
int OPEN=1;
if(OrdersTotal())
OPEN=0; // no more orders can be opened
if(OPEN==1)
{
//open here
}
The problem is that it opens the required number of deals (1 in this example) for all symbols. And I need to explain to him
that it needs to open this number of deals on the CURRENT instrument. Something like _Symbol or Symbol (). How it can be done? I think the solution is simple.
Blows up a hell of a lot of deals, and in a sell
well there are two options:
1. show all code
2. join the telepath club
well there are two options:
1. show the whole code
2. join the telepath club:)
:)
I figured out how to open both buy and sell. But the number of deals does not open on every tick
int start()
{
double a=iOpen(NULL,PERIOD_D1,0);
double d=_ORDER*0.00001;
double c=d+1;
double s=c*a;
double limit= NormalizeDouble(s,_Digits);
// Print("limit level= ",limit);
double e=_STOP*0.00001;
double n=e+1;
double m=n*a;
double SL= NormalizeDouble(m,_Digits);
//Print("stop level= ",SL);
double p=_TP*0.00001;
double f=p+1;
double z=f*a;
double TP= NormalizeDouble(z,_Digits);
double w=iOpen(NULL,PERIOD_D1,0);
double q=_ORDER*0.00001;
double j=q+1;
double v=w/j;
double limit1= NormalizeDouble(v,_Digits);
// Print("limit level= ",limit);
double k=_STOP*0.00001;
double y=k+1;
double u=w/y;
double SL1= NormalizeDouble(u,_Digits);
//Print("stop level=",SL);
double g=_TP*0.00001;
double _f=g+1;
double _m=w/_f;
double TP1= NormalizeDouble(_m,_Digits);
if(Hour()==Nac)
{
if(iOpen(NULL,PERIOD_D1,0)<iOpen(NULL,PERIOD_D1,1))
{
if(!isTradeToDay(Symbol()))
{
int ticket1=OrderSend(Symbol(),OP_SELLSTOP,1.5,limit1,3,SL1,TP1,NULL,0,0,clrRed); //open here
}
}
if(iOpen(NULL,PERIOD_D1,0)>iOpen(NULL,PERIOD_D1,1))
{
if(isTradeToDay(Symbol()))
{
int ticket=OrderSend(Symbol(),OP_BUYSTOP,1.5,limit,3,SL,TP,NULL,0,0,0,clrBlueViolet); //open here
}
}
}
if(Hour()==Kon)
{
bool result;
int error;
//----
while(OrdersTotal()>0)
{
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY)
result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS),3,CLR_NONE);
if(OrderType()==OP_SELL)
result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),3,CLR_NONE);
if(OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
OrderDelete(OrderTicket());
if(result!=TRUE)
{
error=GetLastError();
Print("LastError = ",error, ",Symbol());
}
else
error=0;
}
else
Print("Error when order select ", GetLastError());
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
return(0);
}
Here's the code without any declared variables.
code needs to be inserted Alt+S
and where is the function ?
how did you compile it ? no errors ?
code needs to be inserted Alt+S
and where is the function ?
how did you compile it ? no errors ?
The function is at the bottom. The compilation is without errors. Sell side managed to adjust opens one trade on a specific instrument even if there are open on other
instruments. But the bay side fires trades on every tick and that's it
code needs to be inserted Alt+S
and where is the function ?
how did you compile it ? no errors ?
At the moment the code is like this. Sell side all ok, but buy side every tick is a trade
on the buy side the same thing should be done
the same thing should be done on the buy side
I cannot find out what should be changed in isTradeToDay function to make it the same on the buy side as on the sell side. Still the buy side does not work :(