Ejemplo n.º 1
0
    def margin(self):
        """Returns the required margin in $ to take that position."""

        rMargin = mt5.order_calc_margin(self._type(), self.symbol, self.volume,
                                        self.entry)

        return rMargin
Ejemplo n.º 2
0
import MetaTrader5 as mt5

#____________Initializing Metatrader5____________#
mt5.initialize()
print(mt5.version(), '\n')
print(mt5.terminal_info(), '\n')
print(mt5.account_info(), '\n')

order = mt5.orders_get()  #getting all pending orders

#____________Calculating required Margin_________________#
margin = mt5.order_calc_margin(
    mt5.ORDER_TYPE_BUY, order[0].symbol, order[0].volume_initial,
    order[0].price_open)  #returns required margin in account currency
print('\nMargin requirement for buying {0} @ {1} is ${2}'.format(
    order[0].symbol, order[0].price_open, margin))

#____________Calculating Profit/loss_____________#
volatility = float(input('Enter the desired volatility in percentage: '))
percentage = volatility * (order[0].price_open / 100)
profit = mt5.order_calc_profit(
    mt5.ORDER_TYPE_BUY, order[0].symbol, order[0].volume_initial,
    order[0].price_open,
    (order[0].price_open +
     percentage))  #returns potential P/L in account currency
print('\n Profit on {0} at {1} with {2}% volatility is ${3}'.format(
    order[0].symbol, order[0].price_open, volatility, profit))
Ejemplo n.º 3
0
    print("initialize() failed, error code =", mt5.last_error())
    quit()

# get account currency
account_currency = mt5.account_info().currency
print("Account сurrency:", account_currency)

# arrange the symbol list
symbols = ("EURUSD", "GBPUSD", "USDJPY", "USDCHF", "EURJPY", "GBPJPY")
print("Symbols to check margin:", symbols)
action = mt5.ORDER_TYPE_BUY
lot = 0.1
for symbol in symbols:
    symbol_info = mt5.symbol_info(symbol)
    if symbol_info is None:
        print(symbol, "not found, skipped")
        continue
    if not symbol_info.visible:
        print(symbol, "is not visible, trying to switch on")
        if not mt5.symbol_select(symbol, True):
            print("symbol_select({}}) failed, skipped", symbol)
            continue
    ask = mt5.symbol_info_tick(symbol).ask
    margin = mt5.order_calc_margin(action, symbol, lot, ask)
    if margin != None:
        print("   {} buy {} lot margin: {} {}".format(symbol, lot, margin, account_currency));
    else:
        print("order_calc_margin failed: , error code =", mt5.last_error())

# 断开与MetaTrader 5程序端的连接
mt5.shutdown()