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
As a result, a custom position counting was added to the close block, which resulted in a "correct" close, buterror 131 still pops up a couple of times in the log:
Is such an insertion of an order count into a loop normal considering that there is already one order check and
Could you correct the code to avoid error 131?
Thank you very much.
Could you please correct the code to avoid error 131?
Thank you very much.
And who will normalise the lot size for you after division? Hence the error.
Alex, before passing the lot to the close function, normalise its size with NormalizeLot().
Thanks Igor, Alexander,
Indeed, I've checked lots by replacing Lot/3 (Lot/2, Lot) by 0.01 in function SELLCLOSED_1=OrderClose( OrderTicket(), Lot/3, Ask, 0, Red ); and avoided error 131. We could leave it like that (0.01), but, first, closing in the Lot form is more correct. Second, I've never encountered user functions and their call in the program before, which turned out to be rather interesting. I seem to have attached everything correctly in the code and everything works, but the error 131 still remains. Take a look at the code, please. Maybe I messed up something in the NormalizeLot call function.
Apologies. In the original code, the line
RefreshRates();
BUYCLOSED_1=OrderClose( OrderTicket(), CloseLot, Bid, 0, Red );
is the correct LotClose, as per the condition.
Lot =OrderLots(); // NUMBER OF LOTS
LotClose =NormalizeLot(Lot); // the value of the NORMALIZED LOT is assigned to the CLOSED LOT
wrong when posting........
Take a look at the code, please. Maybe you messed up something in the NormalizeLot call function.
Try replacing
to
Good morning Alexander,
Unfortunately, your tip didn't help. I parsed the log and found that the error occurs in two cases, when the closing of one part of one lot, almost coincides with the closing of another part of the lot.
In the case where there is no coincidence in time, then part of the lot is closed without an error.
I tried to normalize lots for closing buy and lots for closing sell separately but no success:
double
Lot, // Number of lots in selected order
LotCloseBuy,
LotCloseSell,
............................
Lot =OrderLots();
LotCloseBuy =NormalizeLot(Lot);
LotCloseSell =NormalizeLot(Lot);
............................
BUYCLOSED_3=OrderClose( OrderTicket(), LotCloseBuy, Bid, 0, Red )
...........................
SELLCLOSED_3=OrderClose( OrderTicket(), LotCloseSell, Ask, 0, Red );
...................
Igor's function
NormalizeLot.........
Do you have any ideas?
What a sheep I am! Ugh - it's disgusting....
Normalised the lots in the order loop
//--------------------------------------------------------------- 4 --
// Counting orders
Symb=Symbol(); // Name of financial instrument.
BuyTotal=0; // Number of Buy orders
SellTotal=0; // Number of Sell 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()!=Symb)continue; // Not our financial instrument
if (OrderType()>1) // Pending
{
Alert(" Pending order detected. Expert Advisor not working.");
return; // Exit start()
}
if (OrderType()==OP_BUY)
{
BuyTotal++; // Buy order counter
BuyOrdOpPrice=OrderOpenPrice(); // Open Buy price
}
if (OrderType()==OP_SELL)
{
SellTotal++; // Sell order counter
SellOrdOpPrice=OrderOpenPrice(); // Open Sell price
}
Ticket=OrderTicket(); // Order number selected.
Tip =OrderType(); // Type of the selected order.
Lot =OrderLots();
LotCloseBuy =NormalizeLot(Lot);
LotCloseSell =NormalizeLot(Lot);
}
}
.... and I created a separate loop to account for open orders, where I had to normalize lots to close them!!!
//--------------------------------------------------------------- 6 --
// Checking open orders
int _GetLastError = 0, _OrdersTotal = OrdersTotal();
int z;
//---- go through all open positions
for ( z = _OrdersTotal-1 ; z >=0; z -- )
{
//The loop for - going through all open orders
//---- if an error occurs during position selection, proceed to the next
if ( !OrderSelect( z, SELECT_BY_POS ) )
{
_GetLastError = GetLastError();
Print("OrderSelect( ", z, ", SELECT_BY_POS ) - Error #", _GetLastError );
continue;
}
//Finished
//Binding to Currency and Majik
//---- if position is not opened by current instrument, skip it
if ( OrderSymbol() != Symbol() ) continue; // ERROR
//Finished
//---- if MagicNumber is not equal to Expert_ID, skip this position
if ( OrderMagicNumber() != Expert_ID ) continue; // ERROR
//Finished
if (OrderType()==OP_BUY)
{
BuyClot=OrderLots();
}
if (OrderType()==OP_SELL)
{
SellClLot=OrderLots();
}
OpenedLots=OrderLots();
LotCloseBuy =NormalizeLot(OpenedLots); // Number of lots
LotCloseSell =NormalizeLot(OpenedLots); // Number of lots
//Check if a Buy position is opened,
........................................
Thank you Igor, Alexander. Without lot normalization function, would still be in a deadlock....
Good evening,
And the very first error that occurs:
2009.07.08 21:05:45 TestGenerator: unmatched data error (volume limit 651 at 2009.07.08 19:00 exceeded)
is critical or is it just a tester error?
Thank you.