[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 502

 
edit | delete Help to find a function for placing orders that takes slippage into account and without 130-134 errors.
 
nuan:
edit | delete Help to find a function for placing orders that takes slippage into account and without 130-134 errors.

Show me your variant.
 
NumderOrder=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-SL*Point,Ask+TP*Point, "BUY",0,0,Red);

Print(GetLastError());

With any values of SL and TP it gives out 134, it often doesn't place an order at all.

opens on condition if(NumberOfOrders(NULL)==0)


In the tester, instead of one order it always places a bunch, i.e. i can not understand why it should place an order if there are no other open orders on this pair

 
sorry, why there is more than one order
 
nuan:
NumderOrder=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-SL*Point,Ask+TP*Point, "BUY",0,0,Red);

Print(GetLastError());

With any values of SL and TP it gives out 134, it often doesn't place an order at all.

opens on condition if(NumberOfOrders(NULL)==0)


In the tester, instead of one order it always places a bunch, i.e. i can not understand why it should place an order if there are no other open orders on this pair


ERR_NOT_ENOUGH_MONEY 134 Not enough money to complete the transaction
 

Good day. I am making an EA, it opens 2 orders in a certain condition (figuratively speaking: when the price goes up and down). When the price goes up, it opens 2, when the price goes down, it closes those 2 and opens a new 2. One order goes without a take profit, the second order with a take profit. There is a problem with the second one. At the time when its time of death comes, it is not selected, here is the code to remove orders:

for (int a = 0; a < OrdersTotal()-1; a++)
    if (OrderSelect(a, SELECT_BY_POS, MODE_TRADES))
        if (OrderComment() == "MyOrd" && OrderType() == OP_SELL)
            OrderClose(OrderTicket(), NormalizeDouble(OrderLots(), Digits), NormalizeDouble(Ask, Digits), 0);

Same for OP_BUY. I'm comparing comments to know for sure it's an order opened by my EA and not manually or by another EA. Here's the problem with OrderSelect, it just doesn't want to select an order with a take profit. When it gets a to its number, OrderSelect returns false. There is no error in the tester log, GetLastError also says everything is fine (returns 0). Why is it not being selected? Why no error if it couldn't select it? Thank you all.

 
Follow-up question. Why in the tester, when I set the period to month+, then five digits appear in the results? Wherever prices are set, I put NormalizeDouble(SomeValue, Digits). And only in the results, the log does not swear, although when I didn't know about rounding function, then it swore.
 

the condition

a < OrdersTotal()-1

is checked at each iteration.

Think about what a equals and what OrdersTotal() -1 equals after the first iteration

 
Solree:

OrderClose(OrderTicket(), NormalizeDouble(OrderLots(), Digits), NormalizeDouble(Ask, Digits), 0);

The lot and price have different Digits.
 

Solree:

NormalizeDouble(OrderLots(), Digits)


Also - it's not so easy to normalize the lot.
You need to take into account the allowable step of lot change.
For example, if the step is 0.01, then normalize by 2
and if the step is 0.1, then the normalization should be 1