
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thanks for sharing this code ! I am able to close orders, for example a buy, by doing a sell and then doing a close_by...but when I look at the history of the deals these operations are missing
do you also have this problem?
from_date=dt.datetime(2000,1,1)
to_date=dt.datetime.now()
history_deals=mt5.history_deals_get(from_date, to_date)
history_deals_df=pd.DataFrame(list(history_deals),columns=history_deals[0]._asdict().keys())
Problem is here
You need to convert the namedtuples being returned to dict. I added a helper function to the pymt5adapter package to help with that.
...and if you only want to work exclusively with dict return types for all functions you can modify the API via the context manager kwarg "return_as_dict".
That's how you close either with MT5. In fact, there is even a Close function included in the MetaTrader5 module so your code could be greatly reduced and refactored to something like this.
Hi All
I'm new and am trying to create a python bot. I found codes on MT5 forum that execute trades, however it always returns None.
Would you guys know what is the problem, as I cant seem to know why its always returning None when i have all the required paramenters.
I was also having the problem of result = None.
I got an answer when I changed the type of the value that I was putting at request.volume from int to float, for example:
After casting to float, it worked. (you might as well already use a variable that is a float)
Hope it helps anybody.
had the same problem when working with a Pandas Dataframe. fix it by changing the data type of position_ticket. initially it was sent as <class 'numpy.int64'>, it was changed to type <class 'int'>.
import MetaTrader5 as mt5
import MetaTrader5 as mt5
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.
I was also having the problem of result = None.
I got an answer when I changed the type of the value that I was putting at request.volume from int to float, for example:
After casting to float, it worked. (you might as well already use a variable that is a float)
Hope it helps anybody.
this works for me
Thanks!
Just want to add that I had the same problem of getting None returned after calling order_send.
My problem was the comment was too long. I am not sure what the limit is, but it cannot be too long.
Guys, I did it this way and it worked