tensortrade-org / tensortrade

An open source reinforcement learning framework for training, evaluating, and deploying robust trading agents.
https://discord.gg/ZZ7BGWh
Apache License 2.0
4.5k stars 1.02k forks source link

Feature Request: Forex exchange implementation using Meta Trader 4 #97

Closed notadamking closed 4 years ago

notadamking commented 4 years ago

Funding: 1.75 ETH (~$450 USD)

Description: Create an implementation of Exchange capable of trading any forex pair on the MetaTrader 4 (MT4) platform.

Requirements:

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 1.0 ETH (184.42 USD @ $184.42/ETH) attached to it as part of the tensortrade-org fund.

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 1 month, 1 week ago. Please review their action plans below:

1) adivyas99 has been approved to start work.

I have good experience in machine learning, Python and Reinforcement Learning. Pls, allow me to work on this project. Thanks.

Learn more on the Gitcoin Issue Details page.

gitcoinbot commented 4 years ago

⚡️ A tip worth 0.05000 ETH (9.47 USD @ $189.39/ETH) has been granted to @coejoder for this issue from @notadamking. ⚡️

Nice work @coejoder! Your tip has automatically been deposited in the ETH address we have on file.

sleekmike commented 4 years ago

Hello any progress here?

CoeJoder commented 4 years ago

I've gone through the docs and the tutorial to familiarize myself with the application and requisite concepts, and am beginning my implementation of this Exchange class now.

CoeJoder commented 4 years ago

@notadamking The requirement is for MT4 compatibility, however the company no longer provides an installer for MT4. Support threads on this topic suggest that you can only obtain MT4 through a broker, eg: https://www.mql5.com/en/forum/216552

Do you have an official installer for MT4 you could provide, or can this requirement be changed for MT5 compatibility? EDIT: I was able to get a copy of MT4 by signing up for a demo account through forex.com.

CoeJoder commented 4 years ago

Update: I have the basic features working. It took longer than expected because I had to write additional MQL4 code than what was provided by the 3rd party connector library. Still working on it and will provide updates on progress this week as I have time.

sleekmike commented 4 years ago

ok this is great!!! keep the good work mate, I am really looking forward to the update on the progress.

CoeJoder commented 4 years ago

@notadamking Almost done. I've created a nice API for all the data pulled from MT4, and have methods implemented which pull the data and makes trades as required. However there's a conceptual gap between crypto and forex trading, so I need clarification on what to return for a few Exchange properties:

Exchange::portfolio() A forex account is always denominated in the account's currency. You get exposure to a symbol during the lifetime of a trade, but the balance is always finalized in the account currency when the trade is closed. My understanding is that a forex portfolio should include the asset exposure of all open trades, but the usage of portfolio() by ActionScheme components suggests that only the free margin (the amount available for making new trades) of the account balance should be included. Awaiting your input on this one.

Exchange::trades() Given the forex trade lifecycle, which kinds of trades should be included?

Exchange::balance() I'm currently returning the account's free margin, based on how this property is being used throughout the application.

Exchange::net_worth() I'm currently returning the account equity (the account balance plus or minus the floating profit/loss from any open trades).

notadamking commented 4 years ago

Hi @CoeJoder,

Thanks for your contribution! I have been asked to pass some information along:

Screen Shot 2019-12-05 at 3 04 39 PM
CoeJoder commented 4 years ago

Thank you for the response. I might be misinterpreting it, but I don't think it answered my question regarding the contract of the Exchange class. It looks like an update to the requirement. That is, instead of delivering an implementation of the Exchange class, there will be three classes: Trades, Balance and Margin which will act as proxies for the MetaTrader terminal, providing all of the interactivity as described in the screenshot (minus the last paragraph as this is out of scope) and the original bounty requirements. Please let me know if this is correct.

Other than figuring out how you want this packaged, it's pretty much done.

sleekmike commented 4 years ago

Hello CoeJoder, have you any progress or update on the issue that you are working on so we can try it? also why are you not on the discord group?

CoeJoder commented 4 years ago

@sleekmike Hi Mike. I have joined the discord group now. Currently I have a Python API for creating new market & pending orders, closing/deleting orders, checking all account properties (balance, margin, etc), checking all symbol properties (latest tick, fetching OHLCV bars), calling any of the built-in indicator functions, and fetching data from all available signals. These are demonstrated with a few dozen unit tests. I also have a partial implementation of Exchange but ran into the problem described in my previous messages. I can push this code to a forked branch if you are interested.

The last reply I received 8 days ago from @notadamking seems to suggest I abandon the Exchange implementation in favor of a MT4-driven "block/allow" paradigm. That is, a standalone Python class rather than an Exchange. If someone can confirm this is the new requirement to satisfy the bounty, I will have it ready soon.

sleekmike commented 4 years ago

Ok great! what's your discord id or name? I want us to collaborate on this issue.

CoeJoder commented 4 years ago

Sounds good. Name is same as here, CoeJoder.

TheSnowGuru commented 4 years ago

Hey CoeJoder, I am sorry if I confused you with my request. let's make things simpler . this is important that users will be able to easily understand what is inside a class. and it has to make sense. Find my request inline with your comments. Moreover, We have to divide the work with mt4 into 2, inputs & outputs. in regards to the classes you mentioned:

Inputs to TT from from the MT4 :

We get a lot of data , we need to have it all inside some kind of array that sums it all up, this should include. but some should go to stateand some to the environment in TT. correct me if I am wrong.

Exchange::portfolio()- **should return: balance, equity, margins, free margins, , margin level , which are related to the account exposures and appears in the trade tab in mt4- the name here is Fine. those should go mapped into state in TT.... correct me if I am wrong.

Exchange::trades()- ** Should include all the columns in the trade tab, which includes: order id, time, type, size, symbol, price, sl, tp, price, commission, swap, profit, comment.

Exchange::balance() - I think it's not necessary as we have it in portfolio So can be deleted. what do you think?

Exchange::net_worth() I think it's not necessary as we have it in portfolio I would change this to Exchange::exposure () http://prntscr.com/qcfc74 and give the agent an over look of it's overall account exposures this way: asset, volume, rate, usd

Sending & TMF - Trade Management functions.** Trades to MT4:

This was not discussed throughout the issue, and I am sorry I wasn't so clear about it, but it's crucial to the success of the implementation.

When sending trades to MT4, we have few types of new trades: buy/sell market, buy/sell stop, buy/sell limit, - are they all supported?

When we have open trades, we have few options that should be supported with TT & MT4. and all this relates to TMF - Trade Management functions. FullOrder Close, & Partial Close - can we support that inside the actions space?

TMF should return values back to agent TT and the agent should interact with MT4 in the following way: will be able to modify an open orders/open trades: 0 - check the trade's Entry, Stop, TakeProfit, and Trail parameters. 1 - Update an openOrder or openTrade with exitNow , CancelOrder , Trail, TP ,SL

Hope that's clearer now.

Cheers,

TheSnowGuru commented 4 years ago

Small note, most FX brokers nowdays supports more assets like CFD's , e.g gold, silver, crude oil, indices and more, it's important that the agent will be able to engage with those as well, and not just fx pairs.

these are the parameters and characteristics these assets have: Name,Price,Spread,RollLong,RollShort,PIP,PIPCost,MarginCost,Leverage,LotAmount,Commission,Symbol thx

CoeJoder commented 4 years ago

@TheSnowGuru Thank you for the very detailed response. The Exchange methods pass their return values to other components in the TradingEnvironment. Since these return values will be of a different type than the usual, it will not be compatible with any of the existing ActionScheme implementations (DiscreteActions, ContinuousActions, MultiDiscreteActions). I think this is as far as the incompatibility extends; all other components should be reusable as they operate using standard data frames. I will provide a very simple ActionScheme implementation to work with this Exchange so that it can perform an agent run.

Regarding output/TMFs, yes all of the features you describe are already implemented, except for modification of sl/tp & trail (but I will add this now) and will be accessible in the ActionScheme.

Regarding exotic symbols, this should be fine. However I'm not seeing the same parameters and characteristics that you've listed (see below). Where are you seeing those fields? The values returned by the MQL4 programming language are standard for all symbols so I am unaware of those fields.

cfd

CoeJoder commented 4 years ago

@notadamking @TheSnowGuru @sleekmike I'd like to discuss increasing the bounty prize on this to 2 ETH. This has been a lot of work! ETH also dropped in price by a lot since this started. Some stats:

sleekmike commented 4 years ago

Ok @CoeJoder I will get back to you on this soon!

CoeJoder commented 4 years ago

I was notified directly by the bounty sponsor that he and his partner are no longer interested in this feature, therefore I will stop work on it.

sleekmike commented 4 years ago

Hello CoeJoder, your bounty will be paid shortly, we are still interested in the feature so I suggest you continue working on it. Thanks

sleekmike commented 4 years ago

Hello CoeJoder!

sleekmike commented 4 years ago

Hello @CoeJoder, The issue has been funded with additional 1 ETH making it 2ETH just like you demanded. Please provide updates and commits on the issue. Thanks

CoeJoder commented 4 years ago

@sleekmike No, the bounty still shows 1ETH: https://gitcoin.co/issue/notadamking/tensortrade/97/3678 Also, I'm not demanding anything; it's an open bounty. 2 ETH is a very generous bid by me. For comparison, I made 12.5 ETH on my previous bounty which was much easier and smaller to do. I'm only making $5/hour on this ticket, and honestly, that's not worth it either. I provided a detailed explanation of why this bounty has ballooned into somewhat of a beast. I'm already working on other things now, so you would have to pay me more competitively to work on it. Otherwise, good luck in attracting another bounty hunter for such a low reward.

Please read the gitcoin guidelines on how to price a bounty effectively: https://gitcoin.co/blog/tutorial-how-to-price-work-on-gitcoin/

sleekmike commented 4 years ago

Hello CoeJoder, It really took you time to respond or reply, I was really worried. The bounty has been funded, please be patient you will see it soon, I was billed on the 6th of this month but there is a little technical issue that would be resolved soon and it will reflect. Also are you keeping abreast of the recent update on TensorTrade? Also you should join the discord group so that you will be more informed. Best regards.

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


The funding of this issue was increased to 1.75 ETH (446.81 USD @ $255.32/ETH) .

sleekmike commented 4 years ago

Hello Cojoeder

delaji-san commented 4 years ago

I've done years worth of work on MT4 previously and could take a look at this if:

Here's the caveats:

What I can do:

Could take a look at this soon if you can get me a working version with documentation. It will probably take a fair few days to implement and test.

sleekmike commented 4 years ago

Hello @delaji-san, thanks for showing interests on this issue and would be really glad to if you could implement the Buy/Sell orders, check orders and other things that you mentioned. I can give you a working version tensortrade framework that I use to playground with and develop, I can also help you with documentation and guidance in setting this framework on your PC. Thanks

TheSnowGuru commented 4 years ago

If it would be easier for you to implement using MT5 and not MT4 , than go for it. buy sell is 6 types: but limit sell limit buy market sell market sell stop and lastly buy stop

thanks

On Sun, Apr 5, 2020 at 11:23 AM Mike Ohanu notifications@github.com wrote:

Hello @delaji-san https://github.com/delaji-san, thanks for showing interests on this issue and would be really glad to if you could implement the Buy/Sell orders, check orders and other things that you mentioned. I can give you a working version tensortrade framework that I use to playground with and develop, I can also help you with documentation and guidance in setting this framework on your PC. Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tensortrade-org/tensortrade/issues/97#issuecomment-609378518, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIRHQZDGHI2C76NT7IWD7TRLA5ZVANCNFSM4JLKLMYQ .

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This Bounty has been completed.

Additional Tips for this Bounty: