ユーザーページ

GPDUSD HMA EA (による bl4ckp3n9u1n)

The user has made his system private.

GPDUSD HMA EA 討論

Oct 23, 2021 at 03:36
482 視聴
13 Replies
Sep 16, 2020からメンバー   59 投稿
Oct 23, 2021 at 03:58
Trying some new variables, as stated, HMA GBPUSD and H1 for the timeframe.

Halfway through some backtesting results to whet one's appetite.

付属品:

"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 23, 2021 at 14:26 (編集済みのOct 23, 2021 at 14:28)
Last week was just testing the Go Markets Server and I am happy with an average ping of ~20ms.

The first 17 trades for anyone interested was just testing and recalibrating the system which I did lose about $400 but managed to close the deficit to about $50, which means starting from the original balance come mid-Monday trading period.

The final results for the backtest today wasn't the best as I am unable to download / get more tick data which means the quality is just under 50%, the close off of course skewed the results slightly as I had 1 'loss', but this is one of the many grey areas with showing people back testing results as I could also show other results with zero losses and ~1.5% draw down.


付属品:

"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 23, 2021 at 14:33
Just did a second pass, again 1 loss but with slightly better tick quality and ~3% draw down, will try to tweak the settings a bit but will most likely apply the preset to the EA for the week.

付属品:

"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 24, 2021 at 03:10
MetaTrader5 and Python simple login code.

For those who are interested, I have written this to help connect your account, get ticker data, save to csv or xlsx which then can be used to backtest in Python.

This is a .py file, the double ## denotes my own comments, whilst the single # is part of the code (commented out) which can be turned on or off depending on your circumstance,.

This code was developed with Python 3.9.7 using VS Code IDE, however, each section could be cut and pasted into a Jupyter Notebook etc.

****

import MetaTrader5 as mt5
import pandas as pd
import plotly.express as px
from datetime import datetime
import openpyxl

##connect to MetaTrader5 Servers
mt5.initialize()

if not mt5.initialize():
    print('initialize() failed, error code =',mt5.last_error())
    quit()

##specify account details to login
login = '12345' ##does need to include the two ' ' characters
password = 'ABCD1234'
server = 'Broker-Server-Name'

##connect to the trade account specifying all the login details supplied above
authorised = mt5.login(login, password, server)

##convert trading account data into a dictionary
account_info_dict = mt5.account_info()._asdict()


##convert dictionary into dataframe
for prop in account_info_dict:
    df=pd.DataFrame(list(account_info_dict.items()),columns=['Detail','Value'])

# print(df)

symbol_info = mt5.symbol_info('GDPUSD') ##choose your own ticker symbol

symbol_price = mt5.symbol_info_tick('GBPUSD')._asdict() ##gets your ticker and converts to a dictionary
# print(symbol_price)

##get Open, High, Low, Close data and covert to a dataframe
ohlc_data = pd.DataFrame(mt5.copy_rates_range('GBPUSD',
                                            mt5.TIMEFRAME_H1, ##change your timeframe (my strategy requires a little time to process the data, test and forecast hence H1)
                                            datetime(2015, 10, 1), ##change starting date
                                            datetime.now())) ##change end date, useful for backtesting timeseries prediction / forecasting

ohlc_data['time']=pd.to_datetime(ohlc_data['time'], unit='s') ##need to convert time unit to seconds ('s') or the dataframe will show errors

# fig = px.line(ohlc_data, x=ohlc_data['time'], y=ohlc_data['close']) ##fig will plot the chart data
# fig.show() ##this will just open up a window with your chart data

# print(ohlc_data) ##just if you want to print out the ohlc dataframe

##Export dataframe to XSLX ##functions to save the dataframes if needed into XLSX or CSV
# ohlc_data.to_excel(r'd:\Projects\MT5\Test\ohlc.xlsx', index = False)

##Export dataframe to CSV
# ohlc_data.to_csv(r'd:\Projects\MT5\Test\ohlc.csv', index = False) ##CSV will most likely be more useful for using in backtesting or training
"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 26, 2021 at 14:23
I have had to adjust some parameters early as the EA is 'working' but I am not getting the returns that I want based on the daily / weekly goals I have set.

Ideally, each trade returns a minimum of 5% but although not a perfect system it is performing as expected so fat and with the new parameters hopefully the other statistics don't go too crazy.
"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 27, 2021 at 01:22
bl4ckp3n9u1n posted:
MetaTrader5 and Python simple login code.

For those who are interested, I have written this to help connect your account, get ticker data, save to csv or xlsx which then can be used to backtest in Python.

This is a .py file, the double ## denotes my own comments, whilst the single # is part of the code (commented out) which can be turned on or off depending on your circumstance,.

This code was developed with Python 3.9.7 using VS Code IDE, however, each section could be cut and pasted into a Jupyter Notebook etc.

****

import MetaTrader5 as mt5
import pandas as pd
import plotly.express as px
from datetime import datetime
import openpyxl

##connect to MetaTrader5 Servers
mt5.initialize()

if not mt5.initialize():
    print('initialize() failed, error code =',mt5.last_error())
    quit()

##specify account details to login
login = '12345' ##does need to include the two ' ' characters
password = 'ABCD1234'
server = 'Broker-Server-Name'

##connect to the trade account specifying all the login details supplied above
authorised = mt5.login(login, password, server)

##convert trading account data into a dictionary
account_info_dict = mt5.account_info()._asdict()


##convert dictionary into dataframe
for prop in account_info_dict:
    df=pd.DataFrame(list(account_info_dict.items()),columns=['Detail','Value'])

# print(df)

symbol_info = mt5.symbol_info('GDPUSD') ##choose your own ticker symbol

symbol_price = mt5.symbol_info_tick('GBPUSD')._asdict() ##gets your ticker and converts to a dictionary
# print(symbol_price)

##get Open, High, Low, Close data and covert to a dataframe
ohlc_data = pd.DataFrame(mt5.copy_rates_range('GBPUSD',
                                            mt5.TIMEFRAME_H1, ##change your timeframe (my strategy requires a little time to process the data, test and forecast hence H1)
                                            datetime(2015, 10, 1), ##change starting date
                                            datetime.now())) ##change end date, useful for backtesting timeseries prediction / forecasting

ohlc_data['time']=pd.to_datetime(ohlc_data['time'], unit='s') ##need to convert time unit to seconds ('s') or the dataframe will show errors

# fig = px.line(ohlc_data, x=ohlc_data['time'], y=ohlc_data['close']) ##fig will plot the chart data
# fig.show() ##this will just open up a window with your chart data

# print(ohlc_data) ##just if you want to print out the ohlc dataframe

##Export dataframe to XSLX ##functions to save the dataframes if needed into XLSX or CSV
# ohlc_data.to_excel(r'd:\Projects\MT5\Test\ohlc.xlsx', index = False)

##Export dataframe to CSV
# ohlc_data.to_csv(r'd:\Projects\MT5\Test\ohlc.csv', index = False) ##CSV will most likely be more useful for using in backtesting or training

I am still in two minds about 'tolist' or 'todict' as I understand it is better not to enumerate enumerable multiple times as this code really needs only to refer to account details for trading whilst the real time data will append to an exisitng dataframe continuously.

The updated code will only use CSV.
"Or die trying...." Sonny Crockett, Miami Vice 1980's
Oct 27, 2021からメンバー   1 投稿
Oct 27, 2021 at 04:27
Thanks bl4 for the code. I am trying to use socket connection with EA from python for live data.
Sep 16, 2020からメンバー   59 投稿
Oct 27, 2021 at 05:13
fxtradervik posted:
Thanks bl4 for the code. I am trying to use socket connection with EA from python for live data.

I found a forum https://www.forexfactory.com/thread/991133-metatrader5-and-python?page=2 which has the socket script - but also on MQL5 website I believe the same author has posted in more detail and has zip files to download.

For some reason I cannot upload the python file but it is below **save as socketserver.py**, don't forget to load the EA file.

import argparse
import asyncio
import json
import pymt5adapter as mta
import logging
API_FUNCS = mta.get_function_dispatch()

async def handle_api(reader, writer):
    data = await reader.read(1000)
    message = data.decode()
    try:
        req = json.loads(message)
        func = API_FUNCS[req['function']]
        args = req.get('args', [])
        kwargs = req.get('kwargs', {})
        response = func(*args, **kwargs)
        res = dict(error=mta.mt5_last_error(), response=response)
    except Exception as e:
        res = dict(error=[-1, f'{type(e).__name__} {e.args[0]}'], response=None)
    res = json.dumps(res)
    writer.write(res.encode())
    await writer.drain()
    writer.close()

async def main():
    server = await asyncio.start_server(handle_api, '127.0.0.1', 8888)
    addr = server.sockets[0].getsockname()
    print('Serving on {}:{}'.format(*addr))
    async with server:
        await server.serve_forever()

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Socket server for MT5 API')
    parser.add_argument('--path', type=str, help='Absolute path to the terminal64.exe')
    parser.add_argument('--login', type=int, help='Account number')
    parser.add_argument('--password', type=str, help='Account password')
    parser.add_argument('--server', type=str, help='Name of the trade server eg. 'MetaQuotes-Demo'')
    parser.add_argument('--portable', action='store_true', default=None,
                        help='Will launch the terminal in portable mode if this flag is set')
    ns = parser.parse_args()
    kw = vars(ns)
    val_states = [v is not None for v in kw.values()]
    if any(val_states) and not all(val_states):
        print(ns)
        raise Exception('Missing commandline arguments.')
    mt5_connected = mta.connected(
        ensure_trade_enabled=True,
        native_python_objects=True,
        raise_on_errors=True,
        **kw
    )
    with mt5_connected:
        asyncio.run(main())

logger = mta.get_logger(path_to_logfile='example_mt5_log.log', loglevel=logging.DEBUG)
    
with mta.connected(raise_on_errors=True, logger=logger) as conn:
    # custom log
    logger.info(mta.LogJson('My custom message', dict(type='custom', ping=conn.ping())))
raise Exception('Error!')

付属品:

"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 27, 2021 at 08:20
bl4ckp3n9u1n posted:
I have had to adjust some parameters early as the EA is 'working' but I am not getting the returns that I want based on the daily / weekly goals I have set.

Ideally, each trade returns a minimum of 5% but although not a perfect system it is performing as expected so fat and with the new parameters hopefully the other statistics don't go too crazy.

Waiting a whole day for the TP to kick in, I closed off the trade manually (which I didn't want to do) and have set the trade return minimum to 2% now since there seemed to be too much risk waiting for a result. Hopefully, the lower percentage will work better within the swings over a 24-hour period.
"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 27, 2021 at 22:20
bl4ckp3n9u1n posted:
fxtradervik posted:
Thanks bl4 for the code. I am trying to use socket connection with EA from python for live data.

I found a forum https://www.forexfactory.com/thread/991133-metatrader5-and-python?page=2 which has the socket script - but also on MQL5 website I believe the same author has posted in more detail and has zip files to download.

For some reason I cannot upload the python file but it is below **save as socketserver.py**, don't forget to load the EA file.

import argparse
import asyncio
import json
import pymt5adapter as mta
import logging
API_FUNCS = mta.get_function_dispatch()

async def handle_api(reader, writer):
    data = await reader.read(1000)
    message = data.decode()
    try:
        req = json.loads(message)
        func = API_FUNCS[req['function']]
        args = req.get('args', [])
        kwargs = req.get('kwargs', {})
        response = func(*args, **kwargs)
        res = dict(error=mta.mt5_last_error(), response=response)
    except Exception as e:
        res = dict(error=[-1, f'{type(e).__name__} {e.args[0]}'], response=None)
    res = json.dumps(res)
    writer.write(res.encode())
    await writer.drain()
    writer.close()

async def main():
    server = await asyncio.start_server(handle_api, '127.0.0.1', 8888)
    addr = server.sockets[0].getsockname()
    print('Serving on {}:{}'.format(*addr))
    async with server:
        await server.serve_forever()

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Socket server for MT5 API')
    parser.add_argument('--path', type=str, help='Absolute path to the terminal64.exe')
    parser.add_argument('--login', type=int, help='Account number')
    parser.add_argument('--password', type=str, help='Account password')
    parser.add_argument('--server', type=str, help='Name of the trade server eg. 'MetaQuotes-Demo'')
    parser.add_argument('--portable', action='store_true', default=None,
                        help='Will launch the terminal in portable mode if this flag is set')
    ns = parser.parse_args()
    kw = vars(ns)
    val_states = [v is not None for v in kw.values()]
    if any(val_states) and not all(val_states):
        print(ns)
        raise Exception('Missing commandline arguments.')
    mt5_connected = mta.connected(
        ensure_trade_enabled=True,
        native_python_objects=True,
        raise_on_errors=True,
        **kw
    )
    with mt5_connected:
        asyncio.run(main())

logger = mta.get_logger(path_to_logfile='example_mt5_log.log', loglevel=logging.DEBUG)
    
with mta.connected(raise_on_errors=True, logger=logger) as conn:
    # custom log
    logger.info(mta.LogJson('My custom message', dict(type='custom', ping=conn.ping())))
raise Exception('Error!')

@fxtradervik hopefully the socket scripts work.
"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 27, 2021 at 23:16
Deep Evolution Strategy / Machine Learning Script for anyone else who is interested, this is an extension to the original connector to help predict the price of a stock, fxpair etc.

**This was written as a Jupyter Notebook and converted to Python code in VS Code (I should expect to be backwards compatible)**
**This is built within a sandbox environment where the code can be used for Live Accounts but use with caution**
**There is no broker account integration but this is possible given the definitions are changed and the correct functions to execute are included**

Very simple to use:

Check the imports for required modules.

Add in your own MT Broker Account Details (as described in the previous code).

Choose your stock, fxpair etc that you want to use as the 'operational data' and you need training data which would be other stock in the same industry, index etc.

Pay attention to the timeframe to get your data (I use H1) and how far back you want your data to train on.

Double-check your CSV save directory is correct.

Essentially this will use the 'other data' to train on and will exclude your 'operational data' as a 'first pass' to train on.
Check for Window Size - this is how far back you want to look. E.g. I use H1 so 24 = 24 hours = 1 day.

There are other numbers you can 'play around with' but I wouldn't worry too much.

The more data you want to train on the longer this takes to execute. Simples.

Saves results as a pickle file for those who want to use this later for more 'things'.

***Save the attached txt as .py file***

付属品:

"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 27, 2021 at 23:17
bl4ckp3n9u1n posted:
Deep Evolution Strategy / Machine Learning Script for anyone else who is interested, this is an extension to the original connector to help predict the price of a stock, fxpair etc.

**This was written as a Jupyter Notebook and converted to Python code in VS Code (I should expect to be backwards compatible)**
**This is built within a sandbox environment where the code can be used for Live Accounts but use with caution**
**There is no broker account integration but this is possible given the definitions are changed and the correct functions to execute are included**

Very simple to use:

Check the imports for required modules.

Add in your own MT Broker Account Details (as described in the previous code).

Choose your stock, fxpair etc that you want to use as the 'operational data' and you need training data which would be other stock in the same industry, index etc.

Pay attention to the timeframe to get your data (I use H1) and how far back you want your data to train on.

Double-check your CSV save directory is correct.

Essentially this will use the 'other data' to train on and will exclude your 'operational data' as a 'first pass' to train on.
Check for Window Size - this is how far back you want to look. E.g. I use H1 so 24 = 24 hours = 1 day.

There are other numbers you can 'play around with' but I wouldn't worry too much.

The more data you want to train on the longer this takes to execute. Simples.

Saves results as a pickle file for those who want to use this later for more 'things'.

***Save the attached txt as .py file***

Sorry, For some reason I could not save the code as txt in the message??
"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 29, 2021 at 18:17
In keeping within the KISS rule, I will continue for one more week with my minimum profit of 2% per trade just to see what statistics will change.

The next change I will look at will be whether or not I use slippage to capture missed opportunity as this week has shown a few price movements far beyond the minimum return set.

My goal is really to try and achieve 15% return per week based on my equity.

(N.B. this is possible already as I would just need to adjust the minimum return value but I want to minimise the risk if margin levels get too high whilst I wait for a return / TP)
"Or die trying...." Sonny Crockett, Miami Vice 1980's
Sep 16, 2020からメンバー   59 投稿
Oct 29, 2021 at 18:51
MT5 Python Trading Bot - SMA Crossover Example (NOT MY CODE)

I just found this on YouTube from the Channel TraderPy

His code in a Zip file https://traderpy.com/wp-content/uploads/2021/10/sma_crossover1.zip

Very useful for people looking at using Web Sockets or a VPS running Python.
"Or die trying...." Sonny Crockett, Miami Vice 1980's
サインイン / 登録 to comment
You must be connected to Myfxbook in order to leave a comment
*商用利用やスパムは容認されていないので、アカウントが停止される可能性があります。
ヒント:画像/YouTubeのURLを投稿すると自動的に埋め込まれます!
ヒント:この討論に参加しているユーザー名をオートコンプリートするには、@記号を入力します。