Pesky Error 138

 

I am busy back testing an EA and keep on getting an "error 138 - Requote" although I have never before had this problem in back testing or in live usage since I always build in a healthy slippage in all my OrderSend() commands.

I have changed the Price from the one in the OrderSend command line as shown below in the code to be simply just "Ask' or "Bid", but it makes no difference.

I hope that somebody can help me discover the problem.

        UseSlippage = GetSlippage(Symbol(),Slippage);


        int GetSlippage(string Currency, int SlippagePips)
        {
                int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
                if(CalcDigits == 2 || CalcDigits == 4) double CalcSlippage = SlippagePips;
                else if(CalcDigits == 3 || CalcDigits == 5) CalcSlippage = SlippagePips * 10;
                return(CalcSlippage);
        }           

     for (Count = OrdersTotal()-1; Count >= 0; Count--)
                    if (OrderSelect(Count, SELECT_BY_POS)
                    && OrderType() == OP_BUY
                    && OrderMagicNumber() == MagicNumber
                    && OrderSymbol() == Symbol()  
                    && OrderProfit() < Loss)
               
               {
               while(IsTradeContextBusy()) Sleep(10);
               RefreshRates();
               int BuyHedge = OrderSend(Symbol(),OP_SELL,OrderLots(),OrderOpenPrice() + StopLoss * UsePoint,UseSlippage,OrderOpenPrice(),0,"ForexRebel",MagicNumber,0,Green);
               }
 

A few points . . . not all relevant to your issue but you need to be aware of them none the less . . .

Slippage isn't implemented in the Strategy Tester

You only need to use RefreshRates to refresh the Predefined variables

In your code above it seems you are using the OrderOpenPrice from a Buy (Ask) + (StopLoss * UsePoint) as the price you want to open at, when was it placed ? what has price done since then ?. . . to open a Sell . . . a Sell is placed at current Bid price. You also seem to be using the OrderOpenPrice for the StopLoss . . .

As a reminder . . . OrderSend(string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit)

Try this . . .

int BuyHedge = OrderSend(Symbol(), OP_SELL, OrderLots(), Bid, UseSlippage, OrderOpenPrice() + StopLoss * UsePoint, 0, "ForexRebel", MagicNumber, 0, Green);
 
RaptorUK:

A few points . . . not all relevant to your issue but you need to be aware of them none the less . . .

Slippage isn't implemented in the Strategy Tester

You only need to use RefreshRates to refresh the Predefined variables

In your code above it seems you are using the OrderOpenPrice from a Buy (Ask) + (StopLoss * UsePoint) as the price you want to open at, when was it placed ? what has price done since then ?. . . to open a Sell . . . a Sell is placed at current Bid price. You also seem to be using the OrderOpenPrice for the StopLoss . . .

As a reminder . . . OrderSend(string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit)

Try this . . .


Thanks RaptorUK for your efforts and time taken to help me solve my problem.

I realise that I used RefreshRates() unnecessary - but I was desperate to solve the problem and willing to try anything.

I think I understand now that I am using the OrderOpenPrice() operator which was applied to a previous Buy (Ask) transaction to place a Sell (Bid) transaction and that is where the problem could lie.

I don't understand why something like OrderOpenPrice() + StopLoss * UsePoint is acceptable as the stoploss but not as the Sell price. Could you please explain?

 
ernest02:
I don't understand why something like OrderOpenPrice() + StopLoss * UsePoint is acceptable as the stoploss but not as the Sell price. Could you please explain?
The Sell price must be current market for a buy or sell. If you use a SELL LIMIT or SELL STOP (depending on direction) then you can specify any price.
 
WHRoeder:
The Sell price must be current market for a buy or sell. If you use a SELL LIMIT or SELL STOP (depending on direction) then you can specify any price.

Bloody hell! Of Course! What was I thinking!!!

Thanks a lot WHRoeder!!!

Reason: