order_calc_profit

指定された取引操作の利益を口座通貨で返します。

order_calc_profit(
  action,          // 注文の種類(ORDER_TYPE_BUYまたはORDER_TYPE_SELL)
  symbol,          // 銘柄名
  volume,          // ボリューム
  price_open,      // 始値
  price_close      // 終値
  );

パラメータ

action

[in] ORDER_TYPE列挙のいずれか(ORDER_TYPE_BUYまたはORDER_TYPE_SELL)の値を持つ注文の種類名前なし必須パラメータ。

symbol

[in] 金融商品名。名前なし必須パラメータ。

volume

[in] 取引操作量。名前なし必須パラメータ。

price_open

[in] 始値。名前なし必須パラメータ。

price_close

[in] 終値。名前なし必須パラメータ。

戻り値

成功した場合は実際の値、それ以外の場合はなし。エラーコードは、last_error()を使用して取得できます。

注意事項

この関数を使用すると、現在の口座および現在の取引環境での取引操作結果を推定できます。この関数はOrderCalcProfitに似ています。

例:

import MetaTrader5 as mt5
# MetaTrader 5パッケージにデータを表示する
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
 
# MetaTrader 5ターミナルへの接続を確立する
if not mt5.initialize():
   print("initialize() failed, error code =",mt5.last_error())
  quit()
 
# 口座通貨を取得する
account_currency=mt5.account_info().currency
print("Account сurrency:",account_currency)
 
# 銘柄リストを整理する
symbols = ("EURUSD","GBPUSD","USDJPY")
print("Symbols to check margin:", symbols)
# 売買による利益を見積もる(
lot=1.0
distance=300
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
   point=mt5.symbol_info(symbol).point
   symbol_tick=mt5.symbol_info_tick(symbol)
   ask=symbol_tick.ask
   bid=symbol_tick.bid
   buy_profit=mt5.order_calc_profit(mt5.ORDER_TYPE_BUY,symbol,lot,ask,ask+distance*point)
  if buy_profit!=None:
      print("   buy {} {} lot: profit on {} points => {} {}".format(symbol,lot,distance,buy_profit,account_currency));
  else:
       print("order_calc_profit(ORDER_TYPE_BUY) failed, error code =",mt5.last_error())
   sell_profit=mt5.order_calc_profit(mt5.ORDER_TYPE_SELL,symbol,lot,bid,bid-distance*point)
  if sell_profit!=None:
      print("   sell {} {} lots: profit on {} points => {} {}".format(symbol,lot,distance,sell_profit,account_currency));
  else:
       print("order_calc_profit(ORDER_TYPE_SELL) failed, error code =",mt5.last_error())
  print()
 
# MetaTrader 5ターミナルへの接続をシャットダウンする
mt5.shutdown()
 
 
Result:
MetaTrader5 package author:  MetaQuotes Software Corp.
MetaTrader5 package version:  5.0.29
 
Account сurrency: USD
Symbols to check margin: ('EURUSD', 'GBPUSD', 'USDJPY')
  buy EURUSD 1.0 lot: profit on 300 points => 300.0 USD
  sell EURUSD 1.0 lot: profit on 300 points => 300.0 USD
 
  buy GBPUSD 1.0 lot: profit on 300 points => 300.0 USD
  sell GBPUSD 1.0 lot: profit on 300 points => 300.0 USD
 
  buy USDJPY 1.0 lot: profit on 300 points => 276.54 USD
  sell USDJPY 1.0 lot: profit on 300 points => 278.09 USD

参照

order_calc_marginorder_check