MQL4 missing trades with error #129

 

Here's the problem, my EA is meant to buy and sell at a specified price point. Today when i left the EA on the chart it passed the point at least 10 times, but each time the Order Send returned error #129 (invalid price). I have the slippage on 3 and i've made sure to normalise the price.

The strange part is that i put the EA onto the strategy tester from today, with the same data and precise tick method and it went into the trades exactly as it was meant to. I don't understand how this is possible. My theory is that the EA might be too slow in to take the trades in the moment?

Any thoughts as to what might be happening would be much appreciated. By the way pending orders won't do because the broker doesn't like placing them too close to the opening price :(


Update! here is the code i used, however i'm not sure if it will help. 

bool buyActivation  = (currentClose <= openHighPrice + point) &&
                      (currentClose >= openHighPrice - point) &&
                      (tradesOpen < 2); 

//if buy hold true and buy activation true, buy
if (holdbuy && buyActivation)
{
    //get parameters for the order
    StopLoss = openLowPrice;
    TakeProfit = openHigh100;

    //first buy, check for success
    if (!OrderOpenV2(OP_BUY, StopLoss, TakeProfit, openHighPrice))
    {
        Alert("Buy Order failed with error #", GetLastError());
    }else {
        Alert("Buy Order placed successfully");
                      
    }
}

bool OrderOpen(int orderType, double stopLoss, double takeProfit, double choiceOpenPrice)
{
    //declaring variables
    int ticket;
    
    //normalize values
    stopLoss = NormalizeDouble(stopLoss,Digits);
    takeProfit = NormalizeDouble(takeProfit,Digits);
    choiceOpenPrice = NormalizeDouble(choiceOpenPrice,Digits);


    ticket = OrderSend( Symbol(),        // current symbol
                        orderType,       // buy or sell
                        orderSize,       // number of lots
                        choiceOpenPrice, // the price level
                        5,               // the slippage
                        stopLoss,        // stop loss price, to close the trade
                        takeProfit,      // take profit price, to close the trade
                        InpTradeComment, // inputed trade comment
                        InpMagicNumber,  // magic 'identifier' number
                        expirationTime,  // expiration time, todays date + input time (should be 'expirationTime')
                        clrTurquoise);   // colour for the arrow, to visualise trade

    //true for success
    return(ticket > 0);
}

Further more, i also tried a new version today, and it took the trades with no error but it was up a whole pip off the price i wanted. Again when i tested it in the strategy tester it was bang on the price i wanted.

Here is the updated code:

bool buyActivationV2  = (currentClose == openHighPrice) &&
                        (tradesOpen < 2);

//if buy hold true and buy activation true, buy
if (holdbuy && buyActivationV2)
{
    //get parameters for the order
    StopLoss = openLowPrice;
    TakeProfit = openHigh100;

    //first buy (stratergy 1), check for sucess 
    if (!OrderOpenV2(OP_BUY, StopLoss, TakeProfit))
    {
        Alert("Buy Order failed with error #", GetLastError());
    }else {
        Alert("Buy Order placed successfully");          
    }

bool OrderOpenV2(int orderType, double stopLoss, double takeProfit)
{
    //declaring variables
    int ticket;
    double openPrice;
    
    //find the open price for bus or sells
    if (orderType == OP_BUY)
    {
        openPrice = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
    }else
    if (orderType == OP_SELL)
    {
        openPrice = SymbolInfoDouble(Symbol(), SYMBOL_BID);
    }
    //incorect ordertype
    else return(false);
    
    //normalize values
    stopLoss = NormalizeDouble(stopLoss,Digits);
    takeProfit = NormalizeDouble(takeProfit,Digits);
    openPrice = NormalizeDouble(openPrice,Digits);

    ticket = OrderSend( Symbol(),        // current symbol
                        orderType,       // buy or sell
                        orderSize,       // number of lots
                        openPrice,       // the price level
                        0,               // the slippage
                        stopLoss,        // stop loss price, to close the trade
                        takeProfit,      // take profit price, to close the trade
                        InpTradeComment, // inputed trade comment
                        InpMagicNumber,  // magic 'identifier' number
                        expirationTime,  // expiration time, todays date + input time (should be 'expirationTime')
                        clrTurquoise);   // colour for the arrow, to visualize trade

    //true for success
    return(ticket > 0);
}
 

When you post a question please don't just write error #129. Tell us what the code means so that we don't have to look it up.

Show the relevant code ( using the code button - Alt+S ).

I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.


 

If you are sending the correct prices and still getting an error try using RefreshRates() before requesting the prices .

 

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.

Always post all relevant code.
     How To Ask Questions The Smart Way. 2004
          Be precise and informative about your problem

We can't see your broken code.

Fix your broken code.

 
Keith Watford:

When you post a question please don't just write error #129. Tell us what the code means so that we don't have to look it up.

Show the relevant code ( using the code button - Alt+S ).

I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.


Sorry i am new here, thanks for the advice i will make sure to do that in the future.
 
William Roeder:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.

Always post all relevant code.
     How To Ask Questions The Smart Way. 2004
          Be precise and informative about your problem

We can't see your broken code.

Fix your broken code.

sorry, updated my post