Requotes

 

Hello folks,

I started recently to study MQL5 , I am developing an Expert Advisor for Forex and I am having the following problem:

2019.11.18 21:04:52.205 2019.11.13 22:24:25   requote 1.10046 / 1.10049 / 1.10046 (instant buy 0.01 EURUSD at 1.10046 sl: 1.09996 tp: 1.10096)

2019.11.18 21:04:52.205 2019.11.13 22:24:25   requote 1.10046 / 1.10049 (instant buy 0.01 EURUSD at 1.10046 sl: 1.09996 tp: 1.10096)

2019.11.18 21:04:52.205 2019.11.13 22:24:25   CTrade::OrderSend: instant buy 0.01 EURUSD at 1.10046 sl: 1.09996 tp: 1.10096 [requote (1.10046/1.10049)]


The first order is sent without problem but the following ones are not.


The code is below, remembering that I just practing yet:
 

void OnTick()
  {                     
        double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID),_Digits);
        double stoplosspips = 50; //AccountPercentStopPips(_Symbol, 3, 00.1);
        double point = _Point;
        double stoploss = Bid - (stoplosspips * point);
        double takeprofit = Bid + (stoplosspips * point);
        trade.Buy(0.01, _Symbol, Bid, stoploss, takeprofit, NULL);           
  }
  
  double PercentStopLostPips(string symbol, double percent, double lots)
{
    double balance      = AccountInfoDouble(ACCOUNT_BALANCE);
    double moneyrisk    = balance * percent / 100;
    int    spread       = SymbolInfoInteger(symbol, SYMBOL_SPREAD);
    double point        = SymbolInfoDouble(symbol, SYMBOL_POINT);
    double ticksize     = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
    double tickvalue    = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
    double tickvaluefix = tickvalue * point / ticksize; // A fix for an extremely rare occasion when a change in ticksize leads to a change in tickvalue
    
    double stoploss = moneyrisk / (lots * tickvaluefix ) - spread;
    
    if (stoploss < SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL)){
        stoploss = SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL); // This may rise the risk over the requested
     }
        
    stoploss = NormalizeDouble(stoploss, 0);
    
    return (stoploss);
}


Thanks guys.

 

Forum on trading, automated trading systems and testing trading strategies

EA Buy when bid

William Roeder, 2017.11.09 17:55

You buy at the Ask and sell at the Bid.
  • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
  • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3
  • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

Reason: