Hi there!
I have run into a strange EA behaviour, I will first post the code, then the output
so, the second alert states that LotRemains 0, so the cycle while ((LotRemains>0) && (!IsStopped()) ) should stop, but the next alert indicates that it didn't and tried to open another order with 0 volume
how is that possible?
Does this Lot have Local or Global scope ?
Lot = GetLot(MaxRisk); OpenPartOrders(OP_SELL,Lot);
probably not connected, but this is wrong . . .
LastTic = NewOrder(Cmd, LotRemains); NumOrders++;
. . even if the OrderSend() fails you still increment the number of orders . . .
I suspect that the issue is one of comparing doubles, yet again. In this code . . .
LotRemains = LotRemains - OrderLots();
. . . if LotRemains > OrderLots() even by 0.00000000001 your while loop will not exit. Instead try this . . .
while ((LotRemains > Point ) && (!IsStopped()) )
Thanks for your reply!
>Does this Lot have Local or Global scope ?
here is the main frame where Lot is declared
int start() { //---- double Lot; if (TrailingStop > 0) DoTrailing(); static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0]; { CheckCross(); } //---- return(0); }
and it is used in CheckCross() then:
Lot = GetLot(MaxRisk);
OpenPartOrders(OP_SELL,Lot);
where should I declare it?
maybe inside CheckCross function?
edit:
oh, it was declared both in start() and CheckCross(), shame on me...
I deleted all the declaration and made it like this:
OpenPartOrders(OP_BUY,GetLot(MaxRisk));
>I suspect that the issue is one of comparing doubles
thanks for the solution, but I wonder how can this happen? I mean, this is computer, not a human who can be mistaken even for 0.00000000001
edit:
found this https://www.mql5.com/en/forum/138355
and this https://www.mql5.com/en/forum/136997
wow never thought this could take place
Thanks for your reply!
>Does this Lot have Local or Global scope ?
here is the main frame where Lot is declared
and it is used in CheckCross() then:
where should I declare it?
It's OK as it is, if it had been Globally declared it could have caused you issues . . . it's just local, so you need it declared in each function that uses it . . . but it is a different variable in each function.
wow never thought this could take place
well, ok, are there any other tricks in mql4 like this one?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi there!
I have run into a strange EA behaviour, I will first post the code, then the output
this is the part of the code that behaves strange:
Lot = GetLot(MaxRisk); OpenPartOrders(OP_SELL,Lot);
the GetLot function:
OpenPartOrders function: (I need to open orders like that because my broker sometimes opens orders partially)
and the NewOrder function:
And here is the output:
1) 2014.01.12 08:59:53 myEMA-nomagic-24-12-2110 BTCUSD,H1: open #1404883915 sell 0.83 BTCUSD at 856.234 ok
2) 2014.01.12 08:59:53 myEMA-nomagic-24-12-2110 BTCUSD,H1: Alert: NumberOfOrders 1 Ticket 1404883915 LotRemains 0 initial Lot 0.83
3) 2014.01.12 08:59:53 myEMA-nomagic-24-12-2110 BTCUSD,H1: Alert: Error opening order: 131
4) 2014.01.12 08:59:53 myEMA-nomagic-24-12-2110 BTCUSD,H1: Alert: cmd 1 Lot 0 PR 857.001 Slip 1000 SL 0 TP 0 Ask 857.001 Bid 857.001
5) 2014.01.12 08:59:53 myEMA-nomagic-24-12-2110 BTCUSD,H1: Alert: OrderSelect returned the error of 0 order ticket -1
the output messages should be read from top to bottom, so the earlier ones are at the top and the latter ones are in the bottom, I numbered them in chronological order
so, the second alert states that LotRemains 0, so the cycle while ((LotRemains>0) && (!IsStopped()) ) should stop, but the next alert indicates that it didn't and tried to open another order with 0 volume
how is that possible?