Few issues

 

Hey guys,

I‌'ve designed an algorithm in c++, the only language I got to know, and its proving great results, but I'm struggling with few aspects of it.

1‌) Is it possible to program trades expiration time (if trade is open for more than X hours/days/whatever - close it)

2‌) When it comes to the trade count, how can I limit the number of trade being made to 1 per currency pair (I've only managed to make it X-trades per the whole account, which just opened multiple trades in the same currency).

3‌) How can you define the lot size to be based on your current account balance?


S‌orry for possibly retarded questions, but I'm good at designing algorithms (my degree), but suck at implementing.

 
Artur Lewandowski:

Hey guys,

I‌'ve designed an algorithm in c++, the only language I got to know, and its proving great results, but I'm struggling with few aspects of it.

1‌) Is it possible to program trades expiration time (if trade is open for more than X hours/days/whatever - close it)

2‌) When it comes to the trade count, how can I limit the number of trade being made to 1 per currency pair (I've only managed to make it X-trades per the whole account, which just opened multiple trades in the same currency).

3‌) How can you define the lot size to be based on your current account balance?


S‌orry for possibly retarded questions, but I'm good at designing algorithms (my degree), but suck at implementing.

First off, the programming language used by MetaTrader is MQL and not C++ (although they are very similar in appearance). You can only use true C++ in DLL form as a library to be called from MQL, but that does not seem to be what you are discussing.

Now, considering that MQL is used (and not C++) to develop an EA (Expert Advisor) for trading, these are the answers to you queries:

  1. Yes, it is absolutely possible to close a trade after a set amount of time (expiration). However, this is done in code and does not happen automatically at the trade server (except for pending orders that have not been triggered).
  2. In your code you will have access to all the currently open trades, so you can easily count them, filtered them by Symbol and Magic Number (an ID used to separate orders from different EAs on different charts) and decided whether to open more or not.
  3. Well, you have access to the Account Balance and the Equity, as well as the Stop Size and Margin, so you can easily calculate the risk you want applied.

Now, from the various queries you have, it is obvious that you need to do plenty of reading (research), both on MQL coding as well trading knowledge.

For MQL, you should read over the documentation and have a look at the many examples available in the CodeBase. As for Forex and Trading knowledge, you will have to do a few searches on the Internet, but I recommend BabyPip's School of Pipsology which is free.‌

Reason: