OrderLots() is half what it should be - page 2

 
MetaNt:

No I'm closing sell positions also, why do you ask?


Not here. Only the buys:

if(OrderType()==OP_BUY)

Also

OrderClose(buyticket2,OrderLots(), bid,7,Yellow);

is easily wrong if you use 5 digits broker (0.7 pips?). Also use predefined var Ask instead of bid to avoid requotes.

Why are you not checking if OrderClose() was success?

if (OrderClose(....) == true)
 ...
 

I've fixed it now, I think it's because I used Orderselect way too many times, even more than raptor thought, because I had it as both a primary and secondary condition, (it was carried over from the previous coding arrangement that I had built but I didn't realise the implications of doing it in this way)

Could you please check if this is just duck tape are an actual structural improvement.

       if(direction==25)
      {
       for(int i=OrdersTotal()-1;i>=0;i--)
          {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            if(OrderMagicNumber()==MagicNumber)
               if(OrderSymbol()==Symbol())                                                                 
                  if(OrderType()==OP_BUY)
                   if(OrderTicket()==buyticket2){OrderClose(buyticket2,OrderLots(), OrderClosePrice(),7,Yellow);Print("OrderLots ", OrderLots(), " OrderTicket ", OrderTicket()," buyticket2 ", buyticket2);}
          }
      }
 
graziani:


Not here. Only the buys:

Also

is easily wrong if you use 5 digits broker (0.7 pips?). Also use predefined var Ask instead of bid to avoid requotes.

Why are you not checking if OrderClose() was success?


Tbh, I'm a bit new at mql4, I mean I've been writing in mql4 pretty much non stop day and night since mid december, and I've built a few EAs, currently I'm working on an indicator, never the less I have not yet developed habits like checking if the close was successful, nor am I familiar with *var Ask", is that the same as "Ask", were you just saying "the predefined variable, Ask"? In any case, I wanted to clear up a few of the errors I'm my current EA before I work on the indicator while learning more about mql4.
 

This will not work for sure.

OrderClosePrice() is for closed orders out of history pool.

Read the manual, you are doing everything wrong.

 
MetaNt:

Tbh, I'm a bit new at mql4, I mean I've been writing in mql4 pretty much non stop day and night since mid december, and I've built a few EAs, currently I'm working on an indicator, never the less I have not yet developed habits like checking if the close was successful, nor am I familiar with *var Ask", is that the same as "Ask", were you just saying "the predefined variable, Ask"? In any case, I wanted to clear up a few of the errors I'm my current EA before I work on the indicator while learning more about mql4.
You MUST get into the habit of checking the return values from your trading functions, they tell you if they worked or not, if they didn't work you can then print all the variables involved and with that information be in the best position to understand what went wrong. It's critical in live or demo where you can't turn the clock back . . . read this: What are Function return values ? How do I use them ?
 

OK, you are new, so take time. You must check every step as you made mistakes almost everywhere.

Just select keywords, press F1 and read. Examples are everywhere.

Ask is predefined just like Bid, Point, Digits etc.

 
graziani:

This will not work for sure.

OrderClosePrice() is for closed orders out of history pool.

Read the manual, you are doing everything wrong.

Not just for closed Orders . . . it will work.

Read all of this thread for more info: https://www.mql5.com/en/forum/143495

 
graziani:

This will not work for sure.

OrderClosePrice() is for closed orders out of history pool.

Read the manual, you are doing everything wrong.


Woops I put that in there because of an earlier suggestion, it was initially bid, (bid = MarketInfo(ect)), it seems to be working atm but I can change back.
RaptorUK:
You MUST get into the habit of checking the return values from your trading functions, they tell you if they worked or not, if they didn't work you can then print all the variables involved and with that information be in the best position to understand what went wrong. It's critical in live or demo where you can't turn the clock back . . . read this: What are Function return values ? How do I use them ?

Oh thanks for the useful link.
 

That's pure luck. Haven't checked it in code, but you cannot conclude it out of manual and it is not logical.

Also what value will you get from ECN broker? How will the slippage be calculated then, i.e. what is the use of slippage in this case?

 
graziani:

That's pure luck. Haven't checked it in code, but you cannot conclude it out of manual and it is not logical.

Also what value will you get from ECN broker? How will the slippage be calculated then?


you are right, the documentation doesn't tell you it works . . . but it does. There is no such thing as "luck" . . . its just another word for something that we don't understand. The slippage is specified as part of the OrderClose() call . . .
Reason: