EA testing OrderSend problem

 

Hello,

I am pretty new to mql4 programming. I've made some simple EA, and while testing it (with strategy tester), some positions are opened above the current price, and some stop losses are triggered even that price never reached into that zone.

Here are some pictures:


Buy position opened above the price

Picture 1: Buy position opened above the price


stop loss

Picture 2: Stop loss is triggered even that the price did not reached SL price.



I would say that those things happen randomly, but always at the same spot (while running the test again). What could be the problem?

I am using this to execute the trades:

OrderSend(Symbol(),OP_BUY,myLOTS,Ask,3,Ask-0.0010,0,NULL,16384,0,clrGreen); // BUY

OrderSend(Symbol(),OP_SELL,myLOTS,Bid,3,Bid+0.0010,0,NULL,16384,0,clrGreen); // SELL

 

Charts are Bid price

Buys are opened at Ask, which is Bid price + spread.

Sells are closed at Ask. 

 
Turn on the Ask line, so you see the spread.
 

Thanks.

So, how can I handle my situation? My strategy is based on the chart that is displayed (Bid price, as you've said).

Before, I was using some other platform, and I've done a few hundred of trades, and never saw something like that. I thought that spread is fixed and defined by broker.


Basically I could wait for Ask price to come closer to the Bid price?

 
doctorslo:

Thanks.

So, how can I handle my situation? 

Find a Broker that offers Zero spreads . . .
 

I see now what is the problem.

The simulation somehow by default uses 4 pips as spread, my broker spread is 2 pips.

I just changed that default value to 2.


Sorry for such an idiotic topic .. :D

Thanks

 
doctorslo: The simulation somehow by default uses 4 pips as spread, my broker spread is 2 pips.
Mt4 doesn't have pips, only points. On a 5 digit broker a point is 1/10 pip. So the tester used 4 points (0.4 pips) not your broker's 2 pips (20 points.)
Reason: