MetaTrader 5 Python User Group - как использовать Python в Метатрейдере - страница 62

 
nicholi shen:

Спасибо за подсказку. Я прочел материалы по Вашей ссылке. Сложновато.

 
9805244:

Добрый день! Как работать с TRADE_ACTION_CLOSE_BY ??? или кто и как закрывает все открытые позиции?

https://www.mql5.com/en/forum/306742/page10#comment_15577952

MetaTrader 5 Python User Group - the summary
MetaTrader 5 Python User Group - the summary
  • 2020.03.11
  • www.mql5.com
The Main Study MetaTrader Python online documentation Python Releases for Windows - website MetaTrader5 : Python Package - website...
 
nicholi shen:

https://www.mql5.com/en/forum/306742/page10#comment_15577952

Спасибо за пример.

У меня в МКЛ аналогичный скрипт сначала закрывает все прибыльные позиции.

Может и в Вашем скрипте так же сделать?

Удачи

PS: У Вас так и сделано. Увидел.

И этот скрипт для неттинговых счетов?
 
Vladimir Perervenko:

Thanks for the example.

In my MKL, a similar script first closes all the profitable positions.

Can you do the same in your script?

Good luck

PS: You have done so. Had seen.

And this script for netting accounts?

I usually prioritize position closing based on risk (position size), but if you want close based on overall profit then then you just have to modify how you sort the symbols.

def open_position_symbols():
    positions = {}
    for p in mt5.positions_get():
        positions.setdefault(p.symbol, []).append(p.profit)
    symbols = sorted(
        positions,
        key=lambda s: sum(positions[s]),
        reverse=True
    )
    return symbols
 
nicholi shen:

I usually prioritize position closing based on risk (position size), but if you want close based on overall profit then then you just have to modify how you sort the symbols.

Спасибо

 
Python скрипты можно использовать для бэктестинга в терминале?
 
Dmitri Custurov:
Python скрипты можно использовать для бэктестинга в терминале?
Нет, они работают только как скрипты на чарте в отдельном потоке.
 
MetaQuotes:
Нет, они работают только как скрипты на чарте в отдельном потоке.

Can you add a feature so that the terminal passes the chart symbol and time-frame as command-line arguments when evoking a python script by dropping it on the chart? For example, you drop the python script on the EURUSD M15 chart and the command to evoke the script would be

python mt5_script.py EURUSD 15

So that we we can know the symbol and timeframe from within the python script

import sys
if len(sys.argv) == 3:
    chart_symbol, chart_tf = sys.argv[1:3]
 
nicholi shen:

Can you add a feature so that the terminal passes the chart symbol and time-frame as command-line arguments when evoking a python script by dropping it on the chart? For example, you drop the python script on the EURUSD M15 chart and the command to evoke the script would be

So that we we can know the symbol and timeframe from within the python script

Will be available next beta version tonight:

import sys

chart_symbol='unknown'
chart_tf=1

if len(sys.argv) == 3:
    chart_symbol, chart_tf = sys.argv[1:3];

print("Hello world from", chart_symbol, chart_tf)



>> Hello world from T.NYSE 15
Причина обращения: