Create pending orders in Python MT5 via pymt5adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MetaTrader5 as mt5 | |
import pymt5adapter | |
from pymt5adapter.order import Order | |
from pymt5adapter.symbol import Symbol | |
class MySymbol(Symbol): | |
def pips(self, amount): | |
return amount * 10 * self.point | |
def buy_stop(): | |
symbol_str = 'EURUSD' | |
symbol = MySymbol(symbol_str) | |
lot = 0.01 | |
entry = symbol.ask + symbol.pips(50) | |
print(f"Entry {entry}") | |
sl = entry - symbol.pips(10) | |
tp = entry + symbol.pips(10) | |
deviation = 20 | |
o = Order.as_buy_stop(symbol=symbol, volume=lot, price=entry, stoplimit=entry, sl=sl, tp=tp, | |
deviation=deviation, type_filling=mt5.ORDER_FILLING_FOK) | |
r = o.send() | |
print(r) | |
def buy_limit(): | |
symbol_str = 'EURUSD' | |
symbol = MySymbol(symbol_str) | |
lot = 0.01 | |
entry = symbol.ask - symbol.pips(50) | |
print(f"Entry {entry}") | |
sl = entry - symbol.pips(10) | |
tp = entry + symbol.pips(10) | |
deviation = 20 | |
o = Order.as_buy_limit(symbol=symbol, volume=lot, price=entry, stoplimit=entry, sl=sl, tp=tp, | |
deviation=deviation, type_filling=mt5.ORDER_FILLING_FOK) | |
r = o.send() | |
print(r) | |
if __name__ == '__main__': | |
with pymt5adapter.connected(enable_real_trading=True): | |
buy_stop() | |
buy_limit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment