I am completely lost

 

I want to create an "EA" as you call it. Though it's funny that you keep using that as an acronym, as far as I'm concerned, it stands for "evolutionary algorithm" which is exactly what my method actually is. If it works. Which it does, if the spread is low enough. It's on the fence.

Anyway, I have programming experience. And from what I have seen of it, MQL4 looks pretty much the same as C++. But I am missing some crucial details. I know about variables and constants and many different things already, but I need some kind of basic template to work from, and I am slightly lacking on a few conceptual things. Can someone post a sort of lousy example trading robot program which is simple but has all the elements I need and explain what each part of it does and then I can say "aha, this is how I do what I need to do".

Basically, I'd like my program to be able to download into my computer's RAM the following (downloading data to my computer through the currency trading platform):

high, low, open, close data for buy AND sell prices (since the value of the spread can vary) for some time increment that I specify within the program (if this can be done) including the most recent one either as soon as it is completed (so every minute, or every 5 minutes, or every 10 minutes, etc., whatever the time interval is) or possibly at every tick - every time the price changes - whichever of these can be done, I would also like to be able to have a variable which represents the amount of time since the last one completed (so if it's every 10 minutes, there would be a variable which is updated with every tick which counts up to 10 minutes from 0, and when it gets to 10 minutes, there's another update of the data), I would also like to download the total value of the account at liquidation, to download the total number of positions and size of the positions and the type of the positions (for instance USD/JPY is 10000 or 100000 DOLLARS worth of yen, but EUR/USD is 10000 or 100000 EUROS worth of dollars, but my account value will be in dollars, so it needs to be able to determine the variable lot size of a position). From the current buy and sell prices the program could of course simply subtract the one from the other to get the current value of the spread.

THEN I would like the program to be able to perform the following actions (uploading data from my computer through the currency trading platform)

buy or sell via market orders or limit orders. Also, please tell me if I put in a limit order but the price when it goes through, if I can expect it to give me the limit price I put in, or can it be better? For instance, suppose the EUR/USD price for buying is 1.3500 and I have a limit order to buy at 1.3501, will I pay 1.3501 or 1.3500? Should I expect the broker to cheat me there? Or is it functionally identical to putting in a market order with the exception that if the price is 1.3502 or more in by the time the order gets into the system, it will not happen?

FINALLY, I would like the example program to involve a function call to another function. Just some simple thing, that performs a simple computation of some sort with data that is passed into it and returns some value - if both pass by value and pass by reference are possible as it is in MQL4 then please include an example of each (commented to show what you are doing) in the sample program.

Also, please tell me, if it generally involves more than one actual file (with the mql4 extension?) like it can be in C++ or if it is generally just one single mql4 file, and is it compiled by the trading platform, or do I need some compiler for it and then the trading platform uses the machine code or whatever is generated by the compiler?

If someone were to do this, just to make a dummy program that contained all these elements, it would not only be very useful to me but it would be useful to others I imagine. Thank you in advance for anyone who does this.

 
Oh oh, better yet, for the variable which starts at 0 and counts up to 10 minutes (or whatever time you use) - it should be normalized - divided by the time unit - so that it is a double which varies between 0 and 1. I say that just in case there is some issue with a scaling factor. That way, maybe it could be applied to a 5 minute chart, or a 10 minute chart, or a 1 minute chart, but whatever the time unit, this variable is always between 0 and 1.
 
There isn't any such program which will give you everything you need to know about mql4 in an instance. I'll recommend going through the code-base for example ea since you already have some programming. If you do-not like learning by looking at codes but rather a language explanation then checkout the mql4_book. Also, theres the documentations for easy reference.
 
I was asking if someone would write one. If you know the basic format of the language it should take like 5 minutes, it should take about as long as it took to read my post. Just write the program, type up an example of each of these things and put it up. I looked at the mql4 book, it goes straight from explaining what a variable is to making presuppositions about my knowledge about functions and I get sleepy trying to find the transition point where it goes from way simpler than what I need to more than I am prepared to comprehend. You know, I'm not asking for someone to write an "economic advisor" for me, just some stupid thing that has in it every instruction that I might want to use. Some stuff that downloads into variables on my computer any information I might want to use, and every instruction I might want to enter - which now that I think about it, I'd like to not only be buy and sell limit and market orders but also something that cancels any existent orders, after all, I wouldn't want to leave any straggler limit orders sitting around in the event they don't get executed, I wouldn't want the program to forget about them.
 
zortharg: I was asking if someone would write one. If you know the basic format of the language it should take like 5 minutes, it should take about as long as it took to read my post. Just write the program, type up an example of each of these things and put it up. I looked at the mql4 book, it goes straight from explaining what a variable is to making presuppositions about my knowledge about functions and I get sleepy trying to find the transition point where it goes from way simpler than what I need to more than I am prepared to comprehend. You know, I'm not asking for someone to write an "economic advisor" for me, just some stupid thing that has in it every instruction that I might want to use. Some stuff that downloads into variables on my computer any information I might want to use, and every instruction I might want to enter - which now that I think about it, I'd like to not only be buy and sell limit and market orders but also something that cancels any existent orders, after all, I wouldn't want to leave any straggler limit orders sitting around in the event they don't get executed, I wouldn't want the program to forget about them.

I think you've come to the wrong place.

We do-not write codes for other people on this forum.

We expect you to write your own code.

If you get stuck, we point you in the right direction.

If you want someone to write codes for you then go here.

They do mql4 and mql5.

 
zortharg:

[...]

Well, this makes a change from discussing the major update to MT4 which is due in a few days.


I want to create an "EA" as you call it. Though it's funny that you keep using that as an acronym

Depends on your background. For better or worse, MT4 and MQL4 currently have a near-monopoly on the worldwide retail FX market, and the term "EA" has meaning for, at a minimum, hundreds of thousands of people.


And from what I have seen of it, MQL4 looks pretty much the same as C++

There are effectively two versions of the MQL4 language. The one which has existed for the last 9 years has no classes or objects and is therefore more like C than C++. On the other hand, it doesn't have pointers or explicit memory allocation.

The new version of MT4 and MQL4 - due for live release next Monday - adds classes, but again without really explicit memory allocation and management. It's debatable whether that's more like C++, or more like Javascript but without the duck-typing and lambda functions etc.


Basically, I'd like my program to be able to download into my computer's RAM the following [...]

Simplying things slightly, the platform does this for you automatically, and you have no easy means of overriding its standard behaviour. Downloading any external price data and then manipulating it within MQL4 - particularly traditional MQL4 rather than the new extended version - is not pretty.

You can get current prices, and you can easily manipulate historic prices for all the timeframes which the platform caters for: M1, M5, M15 etc but not M3, H2 etc.


high, low, open, close data for buy AND sell prices (since the value of the spread can vary)

The spread can indeed vary, but one of the charming idiosyncracies of the MT4 platform is that it only provides historic bid prices. (Current prices and current spread are obviously available.)


I would also like to download the total value of the account at liquidation [...] the total number of positions and size [...] but my account value will be in dollars

In effect, the platform constantly streams this data. There is no explicit "downloading" of it. For example, MQL4 code constantly has access to the current equity of the account via the AccountEquity() function. Open positions are automatically reported in your deposit currency.


For instance, suppose the EUR/USD price for buying is 1.3500 and I have a limit order to buy at 1.3501, will I pay 1.3501 or 1.3500?

It's broker-dependent but, on the whole, the platform/broker simply will not accept a limit order at or beyond the current BBO. I can't immediately think of an exception to this.


if it generally involves more than one actual file (with the mql4 extension?) like it can be in C++ or if it is generally just one single mql4 file

Broadly speaking, a project can consist only of one .mq4 file, but there can be multiple #included .mqh files. Therefore, you can have common code libraries and re-use them between projects. What you can't do is have multiple .mq4 files which exist in pari passu, i.e. which are compiled together as part of the same project. Despite MQL4's origins in C, the structure of a typical large project is different: one .mq4 file, plus one or more libraries of various kinds (pre-compiled or #included).


then the trading platform uses the machine code or whatever is generated by the compiler

The compiler generates a sort of byte-code/p-code/whatever-you-want-to-call-it rather than machine code. You can compile .mq4 files explicitly, or you can put them in the requisite folder of the software and they will be automatically compiled and made available for use on next start.


If someone were to do this, just to make a dummy program that contained all these elements, it would not only be very useful to me but it would be useful to others I imagine

Not a good time. Everyone on this forum is far too busy arguing about the first truly significant update to MQL4 in 9 years.

 
zortharg: I was asking if someone would write one.
You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
 

I wasn't asking anyone to produce something of commercial value for me. I'm not asking for someone to "code my method FOR me", WHRoeder. I just need a starting point. I may be able to figure something out from the link you put under "search", though I really would like a bare bones "this is what is needed". I don't know what the program should actually look like. I don't know what is strictly necessary to be in it. If I try to do it myself out of the blue without any point of reference, I'm just going to get compiler errors because I'm not even going to know what it's lacking. And if I make something that should work, I will initialize it wrong and I won't even know that I did it right. Ok, how about this. A simple example. Something that would lose your money if you did it in real life: an expert advisor that maintains a position which is daringness*(your account value)*(the difference between the price now and the price 1 time unit ago)/X, and X starts at 1 but every time unit, X is updated to be X=.9*X+.1*(price now-price 1 time unit ago)^2, and daringness is a user specified parameter. And to determine how many to buy or sell, it has to determine how many positions it already owns as well. So just a dumb program but it pretty much has all the elements in it that I would need to work from as a starting point.

gchrmt4 thanks. You answered a lot of my questions. But when you say "you can easily manipulate historic prices for all the timeframes which the platform caters for", how do I do that? Is there a function similar to AccountEquity() which returns a price at a given time, and you give it the time units ago and whether you want open low high close and what type of time units it uses? Is the type of time units determined by the type of chart you apply it to? That is, if you apply it to a 1 minute chart, 1 time unit ago refers to 1 minute ago, but if you apply it to a 5 minute chart, 1 time unit ago refers to 5 minutes ago, or is the time step hard coded into the program itself rather than it being applied to a chart? And the current spread, how do I access that? You say these things are "streaming" and easily accessible but how are they accessed?

Thank you for any help you choose to give.

 
zortharg:
Is there a function similar to AccountEquity() which returns a price at a given time, and you give it the time units ago and whether you want open low high close and what type of time units it uses? Is the type of time units determined by the type of chart you apply it to? That is, if you apply it to a 1 minute chart, 1 time unit ago refers to 1 minute ago, but if you apply it to a 5 minute chart, 1 time unit ago refers to 5 minutes ago, or is the time step hard coded into the program itself rather than it being applied to a chart? And the current spread, how do I access that? You say these things are "streaming" and easily accessible but how are they accessed?

Thank you for any help you choose to give.

There's a whole family of timeseries functions. For example, iHigh("USDJPY", PERIOD_H1, 2) will give you the high of the USDJPY H1 bar 2 bars back (where the current in-progress bar is #0). There are functions for converting times to bar indexes.

Current spread is available in a number of ways. The simplest is Ask - Bid (which gives you the spread for the symbol on whose chart your code is running). The spread for a different symbol to the current chart is available via different routes, and expressed in different terms, such as MarketInfo("symbol", MODE_ASK) - MarketInfo("symbol", MODE_BID), or MarketInfo("symbol", MODE_SPREAD)

 

@zortharg

There is a thing called documentation here (partially deprecated): docs.mql4.com/

and here (soon to come, partially not applicable): mql5.com/en/docs


There you find everything you ever wanted to know; also there is examples in the terminal itself. Examples of scripts, expert advisors and indicators. And also you can import DLLs, to accomplish things that are beyond MQL.

If you can get it from there, you are ready, and if not, well...


 

I understand your request, a working example to start from is very useful

https://www.mql5.com/en/code

also googling you can find free source of expert advisors to learn from

look for code doing simple tasks, group them in functions and try to keep your code simple and readable

start() {

   SearchOrders();
   DetectEnvironment();      
   UpdateIndicators();
   RiskAssessment();
   CalcVolume();
   if( EnterSignal() ) OpenOrder();
   if ( ExitSignal() ) CloseOrder();
   TrailingStop();
   DisplayInfos();

}