I am trying to send a buy request using the metatrader python libary:
import time
import MetaTrader5 as mt
LOGIN = ...
PASSWORD = ...
SERVER = "ICMarketsSC-Demo"
symbol = 'BTCUSD'
lot_size = 0.1if not mt.initialize(login=LOGIN, password=PASSWORD, server=SERVER):
print("initialize() failed, error code =", mt5.last_error())
quit()
symbol_info = mt.symbol_info(symbol)
if symbol_info is None:
print(symbol, "not found, can not call order_check()")
mt.shutdown()
quit()
point = mt.symbol_info(symbol).point
price = mt.symbol_info(symbol).ask
deviation = 20
request = {
"action": mt.TRADE_ACTION_DEAL,
"symbol": symbol,
"volume": lot_size,
"type": mt.ORDER_TYPE_BUY,
"price": price,
"sl": price - 5000 * point,
"tp": price + 5000 * point,
"deviation": deviation,
"magic": 234000,
"comment": "python script open",
"type_time": mt.ORDER_TIME_GTC,
"type_filling": mt.ORDER_FILLING_IOC
}
result = mt.order_send(request)
print("1. order_send(): by {} {} lots at {} with deviation={} points".format(symbol,lot_size,price,deviation));
if result.retcode != mt.TRADE_RETCODE_DONE:
print("2. order_send failed, retcode={}".format(result.retcode))
# request the result as a dictionary and display it element by element
result_dict=result._asdict()
for field in result_dict.keys():
print(" {}={}".format(field,result_dict[field]))
# ifthis is a trading request structure, display it element by element as well
if field=="request":
traderequest_dict=result_dict[field]._asdict()
for tradereq_filed in traderequest_dict:
print(" traderequest: {}={}".format(tradereq_filed,traderequest_dict[tradereq_filed]))
print("shutdown() and quit")
mt.shutdown()
quit()
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello,
I am trying to send a buy request using the metatrader python libary:
Output:
Now as you can see, I get the error 'invalid stops' but if I take a look at the outputs I get
(sl = 56152.67) < (open = 56202.67) < (tp = 56252.67)
which shouldn't be a problem, anyways it does not work