[Python] comment=invalid stops

 

Hello,


I'm trying to automate trade Eurusd but every time I send a request it doesn't execute. The error comment is invalid stops.

Here is the code:

symbol="EURUSD"
volume=0.01
price=mt.symbol_info_tick("EURUSD").ask
sl=price-0.0001
x=mt.symbol_info_tick("EURUSD").ask
y=1.07234,1.07230,1.0700,1.0721)
if x in y:
request = { 
    "action": mt.TRADE_ACTION_DEAL, 
    "symbol":"EURUSD", 
    "volume":volume,
    "type":mt.ORDER_TYPE_BUY,            
    "price":price,
    "sl":sl,
    "tp":0.00, 
    "deviation":0,
    "type_time": mt.ORDER_TIME_GTC,
    "Type_filling":mt.ORDER_FILLING_IOC,
}
result=mt.order_send(request)
print(result)

The Error:

OrderSendResult(retcode=10016, deal=0, order=0, volume=0.0, price=0.0, bid=0.0, ask=0.0, comment='Invalid stops', request_id=0, retcode_external=0, request=TradeRequest(action=1, magic=0, order=0, symbol='EURUSD', volume=0.01, price=1.0745, stoplimit=0.0, sl=1.0744, tp=0.0, deviation=0, type=0, type_filling=0, type_time=0, expiration=0, comment='', position=0, position_by=0))


Ty

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trade Operation Types - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
josip2247 :


Read and study the help: order_send

Documentation on MQL5: Integration / MetaTrader for Python / order_send
Documentation on MQL5: Integration / MetaTrader for Python / order_send
  • www.mql5.com
order_send - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
josip2247 # :
Did it, even tried the code, didn't help.

I see you didn't read the help. Read help. Learn an example from the help. Get the FULL code from the help. Show the result.

 

True, read it, problem resolved. Thank you very much!
Do you maybe know how to control the buying requests? Lets say I want to buy just one time at certain price. 

 
price=mt.symbol_info_tick("EURUSD").ask
sl=price-0.0001

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  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.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

 
William Roeder #:

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  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.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

Thank you.
For me it is sl=price-0.0002 (my brokers min.is 0.0002).

Do you maybe know how to control the buying requests? Lets say I want to buy just one time at certain price. 
Custom Graphical Controls. Part 1: Creating a Simple Control
Custom Graphical Controls. Part 1: Creating a Simple Control
  • www.mql5.com
This article covers general principles of development of graphical controls. We are going to prepare tools for a quick and convenient work with graphical objects, analyze an example of creation of a simple control for entering text or numeric data as well as the ways of using it.
 
Vladimir Karputov #:

I see you didn't read the help. Read help. Learn an example from the help. Get the FULL code from the help. Show the result.

Do you maybe know how to control the buying requests? Lets say I want to buy just one time at certain price. 
Custom Graphical Controls. Part 1: Creating a Simple Control
Custom Graphical Controls. Part 1: Creating a Simple Control
  • www.mql5.com
This article covers general principles of development of graphical controls. We are going to prepare tools for a quick and convenient work with graphical objects, analyze an example of creation of a simple control for entering text or numeric data as well as the ways of using it.
Reason: