Buy Operation not Ok

 

Hello to everybody,

I try to run this chunk of code

double price = 0;
double sl, tp;

price = SymbolInfoDouble(Symbol(),SYMBOL_ASK)+offs*point;
sl    = price-stopLoss*point;
tp    = price+takeProfit*point;

if (m_trade.BuyStop(0.01,m_symbol.Name(),price,sl,tp,ORDER_TIME_GTC,TimeCurrent()+86400)) {
   Print("+---------------------------------------------------------------------------------");
   Print(StringToTime(TimeCurrent())+" Pendign Buy order openede at: price "+price+" Stop Loss: "+sl+" TakeProfit: "+tp+" Ticket no."+m_trade.ResultOrder()+" Code"+getResultCode(m_trade.ResultRetcode()));
   Print("+---------------------------------------------------------------------------------");
   } else Print("Buy Operation not Ok");

But, instead of place a buy stop order, I always get the message "Buy Operation not OK".

What's wrong ?

Davide

 
price = SymbolInfoDouble(Symbol(),SYMBOL_ASK)+offs*point;
sl    = price-stopLoss*point;
tp    = price+takeProfit*point;
  1. We have no idea what offs, stopLoss, or takeProfit is. You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point / SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).)
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

  2. 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.)

 

#whroeder1

Hello and thanks for your reply, even though in the meantime I have found the issue and fix it.

Only a question about when you wrote: "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.

I perfectly know it... but I have to fix my SL when BID  reaches the price order (i.e. ASK price) less the TP pips I have established; so sl = bid_price-deltaPip is OK.

The same for TP.

Regards

 
actually, what code is that?