Stop/limit order too close to actual price
6 replies
sansay
7 years ago #116332
Please see attached screenshot.
When I first saw this EA log, “stop/limit order too close to actual price” I immediately thought “OK the stop level is incorrect”. So I edited the code and changed the value of MinDistanceOfStopFromPrice to 70, as that was the spec of the USDMXN pair. However as you can see in the screenshot that didn’t solve the problem. In fact I even tried 100, 200, 700, it didn’t change a thing.
Any help would be greatly appreciated.
sansay
7 years ago #141561
Which screenshot?
I have the opposite problem, I need some Stop_limit orders to be closer to the price.
That’s weird, I am pretty sure I attached the png file. Let’s give it another try…
tomas262
7 years ago #141585
Does it happen when you place an order or try to modify PT, SL or order price?
sansay
7 years ago #141594
I don’t do anything, it’s an EA created with SQ. It does this, and I think the code is added to every single EA it creates. The difference in this case is that this particular forex dealer has a 70 stops level, where as other have 0.
Of course those with 0 don’t trigger anything.
The code is in function:
void openPosition(int tradeDirection) {
…
sansay
7 years ago #141656
This morning I found it attempted and failed to place a sell stop order. See attached log.
tomas262
7 years ago #141681
I ask because you placed the question into “EA Wizard” thread
You can post the strategy here or send me to [email protected] so I can try to test it on USDMXN too
sansay
7 years ago #141685
Actually, my tests allowed me to find the problem and I fixed the code.
The problem is that the broker’s server check for:
short: orderPrice < currentPrice – stopLevel
long: orderPrice > currentPrice + stopLevel
If the condition is not matched the modification request fails. Currently the code adjust the stopLoss and targetProfit to be just at least withing orderPrice + or – dealer stop level. And this results in the test failing whenever the orderPrice is exactly CurrentPrice -+ stopLevel. So the solution was to simply add or subtract 1 pip. Here is the code change:
In the hidden parameters, declare:
double stopOffset = 0.0001;
Add and pass parameter tradeDirection to the signature and call of method openOrderWithErrorHandling:
int openOrderWithErrorHandling(int tradeDirection, int orderType, double orderLots, double openPrice, double stopLoss, double profitTarget, string comment, int magicNumber) {
In same method add the code in green:
Viewing 6 replies - 1 through 6 (of 6 total)