Reply

Stop/limit order too close to actual price

6 replies

sansay

Subscriber, bbp_participant, community, 11 replies.

Visit profile

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.

0

sansay

Subscriber, bbp_participant, community, 11 replies.

Visit profile

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…

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #141585

Does it happen when you place an order or try to modify PT, SL or order price?

0

sansay

Subscriber, bbp_participant, community, 11 replies.

Visit profile

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) {

      // check if stop/limit price isn’t too close
      if(NormalizeDouble(MathAbs(openPrice – AskOrBid), Digits) <= NormalizeDouble(eaStopDifferenceNumber, Digits)) {
         //Log(“stop/limit order is too close to actual price”);
         return;
      }
so of course when this happens no trade is opened.
Yesterday I attempted to see what would happen if I remove the return statement. I wanted to see if the dealer would reject the order as well. 
The statement appeared in the Expert log, but no trade occurred and no other log appeared. I will give it another shot, this time I will add more logs so I know what path the process took.

0

sansay

Subscriber, bbp_participant, community, 11 replies.

Visit profile

7 years ago #141656

This morning I found it attempted and failed to place a sell stop order. See attached log.

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

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

0

sansay

Subscriber, bbp_participant, community, 11 replies.

Visit profile

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:

 

   if(stopLoss != 0 || profitTarget != 0) {
      if( tradeDirection == 1 )
      {
         stopLoss -= stopOffset;
         profitTarget += stopOffset;
      }
      else if( tradeDirection == -1 )
      {
         stopLoss += stopOffset;
         profitTarget -= stopOffset;
      }
      Log(“Setting SL/PT, SL: “, stopLoss, “, PT: “, profitTarget);
      if(OrderModify(ticket, OrderOpenPrice(), stopLoss, profitTarget, 0, 0)) {
         Log(“Order modified, StopLoss: “, OrderStopLoss(),”, Profit Target: “, OrderTakeProfit());
      } else {
         Log(“Error modifying order: “,error, ” : “, ErrorDescription(error));
      }
   }
 
This works. Trades modifications are accepted by the server.

0

Viewing 6 replies - 1 through 6 (of 6 total)