TheSnowGuru / PyTrader-python-mt4-mt5-trading-api-connector-drag-n-drop

Open Source Trading Strategies & End-to-End solution connecting Metatrader4 & Metatrader5 💹 with Python with a simple drag and drop EA. Fully tested bug free & efficient solution for live & paper trading⭐ Full Documentation ready. Lightweight, efficient and stable implementation 🔥
https://discord.gg/wRMUNP8ERa
702 stars 20 forks source link

issues with get specific bar function and last Ticks #42

Closed Sedik7 closed 1 year ago

Sedik7 commented 1 year ago

Dear Developer hope you are doing well

the below issues after test connection in real account not licensed EA yet just test if ok, so 3 issues as bellow your help is highly appreciated

number 1: number 1using the PyTrader_API_V3_01a.py

in line 2088 break

syntax Error:'break' outside loop

i switch to PyTrader_API_V3_1.py

number 2:

get specific_bar

                            Pytrader_API_V3_1.py", line 967, in Get_specific_bar
self.command = self.command + _instr + '$'
               ~~~~~~~~~~~~~^~~~~~~~

TypeError: can only concatenate str (not "NoneType") to str

NB: i changed the instrument_list to only EURUSD same type Error

instrument_list = 'EURUSD'

number 3: last Ticks test function event for one tick

F998^2^NOK^02103^!

18 Empty DataFrame Columns: []
Index: []


for last Bars function is working no issue

Branly76 commented 1 year ago

Hi,

Some remarks. The break is a bug. So please download again version V3_01a from github. Use same MT4 EA version. instrument_list = 'EURUSD', this is a string definition and not a list definition. instrument_list = ['EURUSD'] is list definition, then you will see it works

For MT4 the tick function you use does not work. Is written in the documentation. use: last_tick = MT.Get_last_tick_info('EURUSD') You will see it works.

watch code below.

from utils.api.Pytrader_API_V3_01a import Pytrader_API

instantiation

documentation reference 1

MT = Pytrader_API()

brokerInstrumentsLookup = { 'EURUSD': 'EURUSD', 'GBPNZD': 'GBPNZD', 'GOLD': 'XAUUSD', 'DAX': 'GER30'}

Connected = MT.Connect( server='127.0.0.1', port=1122, instrument_lookup=brokerInstrumentsLookup)

if not Connected: print('Failed to connect to MT4/5. Please check your configuration.') exit(1)

get the latest tick data

last_tick = MT.Get_last_tick_info('EURUSD') print(last_tick)

get specific bar data

instrument_list = ['EURUSD'] specific_bar = MT.Get_specific_bar(instrument_list) print(specific_bar)

MT.Disconnect()

Best regards

Sedik7 commented 1 year ago

Dear Sir thank you very much for the quick answer last tick function is working for me but last ticks is not working will be mentions bellow im sorry im just beginner in coding

i download again the PyTrader_API_V3_01a.py same ''break '' issue i will open it in pycharm and see for the ticks function as below LastTicks = MT.Get_last_x_ticks_from_now(instrument= ['EURUSD'], nbrofticks=10) ticks = pd.DataFrame(LastTicks) print(ticks.head()) print('')

retrun File "c:\Users\cs\BOT project\BOT\Pytrader_API_V3_1.py", line 754, in Get_last_x_ticks_from_now self.instrument_name_universal = instrument.upper() ^^^^^^^^^^^^^^^^ AttributeError: 'list' object has no attribute 'upper' (venv) PS C:\Users\cs\BOT project\BOT>

for the specific bar the return not clear Specific_bars = MT.Get_specific_bar(instrument_list = ['EURUSD'] , specific_bar_index=1, timeframe = MT.get_timeframe_value('H1'))

retrun (in the first line there is data about the bar but followed with long msg)

F045^1^EURUSD$1692205200$1.09081$1.09229$1.08957$1.09061$8261^! Traceback (most recent call last): File "c:\Users\cs\BOT project\BOT\connection_test.py", line 141, in Specific_bars = MT.Get_specific_bar(instrument_list = 'EURUSD', specific_bar_index=1, timeframe = MT.get_timeframe_value('H1')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\cs\BOT project\BOT\Pytrader_API_V3_1.py", line 967, in Get_specific_bar self.command = self.command + _instr + '$'


TypeError: can only concatenate str (not "NoneType") to str
(venv) PS C:\Users\cs\BOT project\BOT> 
Sedik7 commented 1 year ago

sorry i didn't mention about your response the function didn't specify the bar index and time frame

instrument_list = ['EURUSD'] specific_bar = MT.Get_specific_bar(instrument_list) print(specific_bar)

Best Regards

Branly76 commented 1 year ago

This function has also default values. Check the call, if not mentioned it will de default bar[1] BR

Sedik7 commented 1 year ago

Dear Sir thank you for response , yes i checked the LastTicks doesn't exist in Pytrader_API any more so i will use last_tick function so the issues are closed Best Regards

Sedik7 commented 1 year ago

issues fixed and closed