[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 909
![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 need help. I have an Expert Advisor in the tutorial, but it only works with one market order, and I want to make it work with several, just trade on different financial instruments and open and close orders on them at the same time. Below I threw off an example, but slowed down on the one where the value of the first order is assigned to variables for accounting orders. How can I do the same for the second order (from another currency pair)? And if I want not only one order to work for these currency pairs but for example, for a day the indicator has shown several openings but closing has not yet taken place and 3 or 5 orders are opened in pairs on these two currency pairs. Please advise how to implement this.
// Order count
Symb1=SymbolN1(external variable); // Name of financial instrument.
Symb2=SymbolN2(external variable); // Name of the financial instrument.
Total=0; // Number of orders
for(int i=1; i<=OrdersTotal(); i++) // Order loop
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the following
{ // Order analysis:
if (OrderSymbol()!=Symb1 $$ OrderSymbol()!=Symb2)continue; // Not our financial instrument
if (OrderType()>1) // Pending order caught
{
Alert("Pending order detected. Expert Advisor not working.");
return; // Exit start()
}
Total++; // Market counter. orders
if (Total>2) // No more than two orders
{
Alert("more than 2 market orders. Expert Advisor does not work.");
return; // Exit start()
}
Below this value is set to the variable, to do something with it at the second iteration, since there will be 2 orders (the second on another currency pair) they will change values for the second order but I need to commit information for the first and the second order.
Ticket=OrderTicket(); // Number of the selected order.
Tip =OrderType(); // Type of the selected order.
Price =OrderOpenPrice(); // Price of the selected order.
SL =OrderStopLoss(); // SL of the selected order.
TP =OrderTakeProfit(); // TP of the selected order.
Lot =OrderLots(); // Number of lots
Can we just use the same variables for the second order, only with the prefix 1?
Ticket1=OrderTicket(); // Number of the selected order.
Tip1 =OrderType(); // Type of the selected order.
Price1 =OrderOpenPrice(); // Price of the selected order.
SL1 =OrderStopLoss(); // SL of the selected order.
TP1 =OrderTakeProfit(); // TP of the selected order.
Lot1 =OrderLots(); // Number of lots
}
}
ERR_LONGS_NOT_ALLOWED 4110 Long positions are not allowed. Expert properties must be checked.
ERR_SHORTS_NOT_ALLOWED 4111 Short positions are not allowed. Expert properties must be checked.
what do you mean by long and short positions, what do they look like?
Roughly correct thinking.
These are overwhelmingly bool type variables.
And it can only have two values:
true (true) and false (false).
So, if the flag is set (value true), that means there is an order, and if it is cleared (value false), that means there is no order.
The values true and false do not necessarily mean presence/absence.
Sometimes false means that a condition is present , and true means that there is no condition.
It all depends on the logic of the program and the criteria the programmer checks.
In any case, if you set these flags yourself, you can specify which flag value (true or false)
will correspond to one data state or another.
At the same time, there are standard functions that return true or false depending on the result of the function.
These values can be found in the function reference.
what do long and short mean? what do they look like?
Long = Long = Buy
short =Short = Sell
Thank you
I'm looking for a script which closes an order only when the bar is above or below a specified level.
Of course there should be a tf setting.
. If there is such a script, give me a link. Many thanks in advance
I have buy and sell orders that open at the same price for almost 50-100 positions,
how should i make only one order open, if i'm not mistaken - OrdersTotal()
If so, how should I use it and where should I place it? I feel that without this function I need to input the entire algebra
I have buy and sell orders that open at the same price for almost 50-100 positions,
how should i make only one order open, if i'm not mistaken - OrdersTotal()
If so, how should I use it and where should I place it? I feel that without this function I need to input the entire algebra
You should have attached your own code.
I have buy and sell orders that open at the same price for almost 50-100 positions,
how should i make only one order open, if i'm not mistaken - OrdersTotal()
if so, how should i use it and where should i place it? i feel that without this function i need to input the entire algebra
The OrderSend() function works with every tick (I think so). To solve this problem, you need to create a variable before the start function, for example int H=0.
Further the code:
..........
if ( H==0)
{
OrderSend(blah blah blah);
}
H=1;
And there's no need for algebra. And OrdersTotal() is better not to use for constraint.