Closed kaleming closed 4 years ago
The Trade
class is somewhat experimental at this point so I'd recommend using the Order
class. That being said, I added a couple of methods to the Trade
class to make it easier to modify the sl and tp.
pip install -U pymt5adapter
from pprint import pp
import pymt5adapter as mta
from pymt5adapter.trade import Trade
def main():
trade = Trade('EPM20')
if trade.position:
res = trade.modify_sltp_by_ticks(tp=10, sl=5, price_basis='current')
pp(res._asdict())
else:
s = trade.symbol
ask = s.tick.ask
sl = s.normalize_price(ask - 10 * s.trade_tick_size)
tp = s.normalize_price(ask + 10 * s.trade_tick_size)
trade.buy(1.0, sl=sl, tp=tp)
main()
if __name__ == '__main__':
with mta.connected(raise_on_errors=True, ensure_trade_enabled=True):
main()
Thank you very much @nicholishen.
Hello @nicholishen ,
First of all, thank you for make available this very nice "pythonic" Metatrader repository. I really like it.
I was having a look on your Trade class, and it's very easy to use.
I can place an order just doing this:
Trade('EURUSD').buy(1.0)
Is there some straightforward way to include a stop-loss value ? And also modify this stop-loss value ?
Should I use
create_order_request
function for this purpose ?