Strange OrderSend() problem...

 
I'm using the following line of code in an EA that I want to run backtests with...

int Ticket = OrderSend(Symbol(), Command, Lots, Price, Slippage, StopLoss, TakeProfit, NULL, Reference, 0, Colour);

Price, StopLoss & TakeProfit are all being correctly normalized but I'm getting the following, very strange, problem....

Command == 0 (OP_BUY): Works fine
Command == 1 (OP_SELL): Works fine
Command == 2 (OP_BUYLIMIT): Works fine
Command == 3 (OP_SELLLIMIT): Gives error 130 (ERR_INVALID_STOPS)

It doesn't matter if I am passing a valid stop value or zero, I get the same result every time.

I've also tried switching the sequence in which orders are submitted i.e. send sell limits first but it makes no difference.

Any ideas?

Adam
 
Your open price may be too close to market
 
Can you post the error message as seen in the journal?
 
  1. Forex Trader: int Ticket = OrderSend(Symbol(), Command, Lots, Price, Slippage, StopLoss, TakeProfit, NULL, Reference, 0, Colour);

    Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Forex Trader: Command == 3 (OP_SELLLIMIT): Gives error 130 (ERR_INVALID_STOPS)

    Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    We have no idea what Command, Price, StopLoss, TakeProfit, and the market is.

    You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers, the value might be zero (the broker doesn't know). Use a minimum of two (2) PIPs.

    The checks a trading robot must pass before publication in the Market - MQL5 Articles (2016)

  3. Forex Trader: Any ideas?
    There is no need to create pending orders in code.
    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
    2. Don't worry about it unless you're scalping M1 or trading news.
    3. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
Reason: