Buy at Ask, Sell at bid . . .
Not this . . .
if(order==1) { while(true) { Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Bid ,30,Bid-1500*Point,Bid+1500*Point);
while(OrdersTotal()>0) { OrderSelect(0, SELECT_BY_POS, MODE_TRADES); switch (OrderType()) { case OP_SELL: OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), 4, Purple); break; case OP_SELLSTOP:OrderDelete(OrderTicket()); case OP_SELLLIMIT: OrderDelete(OrderTicket()); } }
- OrdersTotal()>0 and OrderSelect(0...) Makes the EA incompatible with every other including manual trading.
- If the OrderSelect fails so does everything else. Always test return codes
- If the OrderClose/OrderDelete fails you have an infinite loop. Always test return codes and print errors.
- Why use the MarketInfo function call instead of just Ask or the simpler OrderClosePrice()
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ switch (OrderType()){ case OP_SELL: if (!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Purple)) Print("OrderClose failed: ", GetLastError()); break; case OP_SELLSTOP: case OP_SELLLIMIT: if (!OrderDelete(OrderTicket()) Print("OrderDelete failed: ", GetLastError()); break; } }
Sleep(10000); RefreshRates(); return(OrderType()==0);Once the last order is deleted, what is OrderType()
Ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,30,Ask-1500*Point,Ask+1500*Point); if(Ticket<0)... else{ Sleep(20000); return(Ticket==OrderTicket());What is OrderTicket, you haven't selected anything.
If total = 0 this can make your code lock up . . .
for(cnt=0;cnt<total;cnt++) {
although this reply is too late, but think can help other too if searching. using strategy tester, set manual spread, do not use current spread on market
weekend. i also got this error, tested other previous code suddenly the same problem. i forgot that i am using current spread on market closed
@ weekend. so i set manual spread value, then no more error 138.
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
Hi everyone, im new at coding and still have not managed to get many things right. I keep receiving the error code 138 and ive heard a refreshrates() would fix it but im assuming there is something wrong with my brackets or maybe something else. Here is my code can anyone find why the strategy tester is giving me this error?