MetaTrader 5 Python User Group - the summary - page 27

 

Forum on trading, automated trading systems and testing trading strategies

And what, did you cut out Python from MT5?

MetaQuotes , 2023.02.20 17:36

MetaTrader 5.0.44 has been released with support for Python 3.11

You can update like this:

pip install --upgrade MetaTrader5

 

Hello traders,

I'm trying to get the SYMBOL_INDUSTRY_NAME and SYMBOL_SECTOR_NAME of a symbol from the python api.

But when using the symbol_info() function, thoses values are not returned, when it's stated in the doc that they should be returned:

symbol_info

Get data on the specified financial instrument.

symbol_info(

   symbol      // financial instrument name

)

symbol

[in]  Financial instrument name. Required unnamed parameter.

Return Value

Return info in the form of a named tuple structure (namedtuple). Return None in case of an error. The info on the error can be obtained using last_error().

Note

The function returns all data that can be obtained using SymbolInfoInteger, SymbolInfoDouble and SymbolInfoString in one call.

When using MLQ5 code it's working just fine:

Print(SymbolInfoString(_Symbol, SYMBOL_DESCRIPTION));   --> 2023.03.11 10:50:08.695 symbol_infoTST (AAPL.US,D1) APPLE INC

Print(SymbolInfoString(_Symbol, SYMBOL_SECTOR_NAME));   --> 2023.03.11 10:50:08.695 symbol_infoTST (AAPL.US,D1) Technology

Print(SymbolInfoString(_Symbol, SYMBOL_INDUSTRY_NAME)); --> 2023.03.11 10:50:08.695 symbol_infoTST (AAPL.US,D1) Consumer Electronics

Here is the python code I'm using:

# display AAPL.US symbol properties
symbol_info=mt5.symbol_info("AAPL.US")
if symbol_info!=None:
    # display the terminal data 'as is'    
    print(symbol_info)
    print("AAPL.US: spread =",symbol_info.spread,"  digits =",symbol_info.digits)
    # display symbol properties as a list
    print("Show symbol_info(\"AAPL.US\")._asdict():")
    symbol_info_dict = mt5.symbol_info("AAPL.US")._asdict()
    for prop in symbol_info_dict:
        print("  {}={}".format(prop, symbol_info_dict[prop]))

Returning:

SymbolInfo(custom=False, chart_mode=0, select=True, visible=True, session_deals=0, session_buy_orders=0, session_sell_orders=0, volume=0, volumehigh=0, volumelow=0, time=1678485585, digits=3, spread=20, spread_float=True, ticks_bookdepth=0, trade_calc_mode=2, trade_mode=4, start_time=0, expiration_time=0, trade_stops_level=10, trade_freeze_level=0, trade_exemode=2, swap_mode=5, swap_rollover3days=5, margin_hedged_use_leg=False, expiration_mode=15, filling_mode=3, order_mode=127, order_gtc_mode=0, option_mode=0, option_right=0, bid=148.58, bidhigh=150.94, bidlow=147.6, ask=148.6, askhigh=150.95, asklow=147.62, last=0.0, lasthigh=0.0, lastlow=0.0, volume_real=0.0, volumehigh_real=0.0, volumelow_real=0.0, option_strike=0.0, point=0.001, trade_tick_value=0.001, trade_tick_value_profit=0.001, trade_tick_value_loss=0.001, trade_tick_size=0.001, trade_contract_size=1.0, trade_accrued_interest=0.0, trade_face_value=0.0, trade_liquidity_rate=0.0, volume_min=0.01, volume_max=1600.0, volume_step=0.01, volume_limit=3800.0, swap_long=-6.326, swap_short=2.326, margin_initial=0.0, margin_maintenance=0.0, session_volume=0.0, session_turnover=0.0, session_interest=0.0, session_buy_orders_volume=0.0, session_sell_orders_volume=0.0, session_open=150.15, session_close=150.52, session_aw=0.0, session_price_settlement=0.0, session_price_limit_min=0.0, session_price_limit_max=0.0, margin_hedged=0.2, price_change=-1.2889, price_volatility=0.0, price_theoretical=0.0, price_greeks_delta=0.0, price_greeks_theta=0.0, price_greeks_gamma=0.0, price_greeks_vega=0.0, price_greeks_rho=0.0, price_greeks_omega=0.0, price_sensitivity=0.0, basis='', category='', currency_base='USD', currency_profit='USD', currency_margin='USD', bank='', description='APPLE INC', exchange='', formula='', isin='US0378331005', name='AAPL.US', page='', path='CFD USA Shares\\CFD USA Shares 5\\AAPL.US')

Is this a limitation of the metatrader python api, or I am missing something else ?

Documentation on MQL5: Market Info / SymbolInfoInteger
Documentation on MQL5: Market Info / SymbolInfoInteger
  • www.mql5.com
SymbolInfoInteger - Market Info - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
fxalpha1 #:

Hello traders,

I'm trying to get the SYMBOL_INDUSTRY_NAME and SYMBOL_SECTOR_NAME of a symbol from the python api.

But when using the symbol_info() function, thoses values are not returned, when it's stated in the doc that they should be returned:

When using MLQ5 code it's working just fine:

Print(SymbolInfoString(_Symbol, SYMBOL_DESCRIPTION));   --> 2023.03.11 10:50:08.695 symbol_infoTST (AAPL.US,D1) APPLE INC

Print(SymbolInfoString(_Symbol, SYMBOL_SECTOR_NAME));   --> 2023.03.11 10:50:08.695 symbol_infoTST (AAPL.US,D1) Technology

Print(SymbolInfoString(_Symbol, SYMBOL_INDUSTRY_NAME)); --> 2023.03.11 10:50:08.695 symbol_infoTST (AAPL.US,D1) Consumer Electronics

Here is the python code I'm using:

# display AAPL.US symbol properties
symbol_info=mt5.symbol_info("AAPL.US")
if symbol_info!=None:
    # display the terminal data 'as is'    
    print(symbol_info)
    print("AAPL.US: spread =",symbol_info.spread,"  digits =",symbol_info.digits)
    # display symbol properties as a list
    print("Show symbol_info(\"AAPL.US\")._asdict():")
    symbol_info_dict = mt5.symbol_info("AAPL.US")._asdict()
    for prop in symbol_info_dict:
        print("  {}={}".format(prop, symbol_info_dict[prop]))

Returning:

Is this a limitation of the metatrader python api, or I am missing something else ?

It's a small bug, these symbol's properties were added after python API was created. I advised a MQ developer about it.
 
Alain Verleyen #:
It's a small bug, these symbol's properties were added after python API was created. I advised a MQ developer about it.
Thank you for you answer and action 👍
 

Test version of MQL5 Copilot in beta 3647

Test version of MQL5 Copilot in beta 3647 -
https://www.mql5.com/ru/forum/444170

 
Python in trading - the key forum thread with video lessons
Python in trading - Trading with MetroTrader 5 in Machine Learning (MQ5)
Python in trading - Trading with MetroTrader 5 in Machine Learning (MQ5)
  • 2023.04.13
  • www.mql5.com
Python's metatrader5 package enables traders to perform trade operations in metatrader 5 client terminal and exchange data for statistical calculations and machine learning. The trading action function must specify the position and the type of order and the volume must be specified in case of a partial close
 
I want to accurately diagnose a problem so that my intention is understood
 I have a bot based on Python language whose job is to transcribe signals from telegram to mt5 platform
  And since it is done in the Python language, it is placed on a desktop, and I run it from a desktop only
 It has nothing to do with the Expert advisor folder
 In fact, he does not execute any transaction through my real or demo account
 May I know where is the problem
 And what do you recommend
 

MetaTrader 5 Platform update build 3800: Book or Cancel orders, AI coding assistant, and enhanced ONNX support

MetaEditor: Added integration with the advanced automatic coding assistant Copilot. Its operation is based on OpenAI models. Enter a comment or part of a function and send a prompt. The neural network will analyze the prompt and will offer coding options to implement the idea.

Copilot coding assistant


Depending on the file type, the string "MQL5 language", "Python language" or "C++ language" is automatically inserted at each prompt beginning. Thus, the neural network will provide the result in the required language.

Copilot is currently free and is already enabled in the editor. There are several options available under Tools \ Options \ Copilot:

Copilot settings

Payment settings:
  • Use your MQL5 account: this option is currently available for free. Later, you will be able to pay for the subscription directly from your MQL5 account balance.
  • Use an OpenAI key, if you have purchased a subscription and have the relevant key.
Prompt settings:
  • Model — a neural network which will process your requests. text-davinci-003 and gpt-3.5-turbo are currently available. Support for gpt-4 will be added soon.
  • Maximum tokens — the number of text units which the model can return in response to a prompt.
  • Variability — affects how strictly the neural network will follow the prompt. The bigger the value, the greater the result randomness. This option corresponds to the temperature parameter in OpenAI models.
GitHub Copilot · Your AI pair programmer
GitHub Copilot · Your AI pair programmer
  • github.com
GitHub Copilot works alongside you directly in your editor, suggesting whole lines or entire functions for you.
 

Python Fundamentals - video lessons on the fundamentals of the Python programming language

  • Part 01 -post
  • Part 02 - post
  • Part 03 - post
Machine Learning and Neural Networks - In The Second Part of a three-part series on the python programming language - Part 02
Machine Learning and Neural Networks - In The Second Part of a three-part series on the python programming language - Part 02
  • 2023.06.07
  • www.mql5.com
Soper, and today i have the pleasure of presenting the second installment of our three-part series on the fundamentals of the python programming language. Throughout the lesson, we will explore each of these topics in detail, complete with illustrative examples and demonstrations showcasing their features within the python programming language
Reason: