• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 5:18am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 5:18am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

MT4 build 1220 EA running OK, build 1260 not OK 1 reply

Why your broker is your friend and your enemy 4 replies

MT4 Compiler Build prior to Build 6xxx 7 replies

Making your Indicators work with MT4 Build 600+; Simple! 1 reply

Build 201 has new function names that can mess up your EA 0 replies

  • Commercial Content
  • /
  • Reply to Thread
  • Subscribe
  • 27
Attachments: How to Build your EA
Exit Attachments
Tags: How to Build your EA
Cancel

How to Build your EA

  • Last Post
  •  
  • 1 Page 23456 10
  • 1 Page 234 10
  •  
  • Post #21
  • Quote
  • Oct 8, 2016 3:15pm Oct 8, 2016 3:15pm
  •  samsane
  • | Joined Oct 2016 | Status: Junior Member | 1 Post
please will like to know if someone can convert an indicator in mql4 to mql5 will be very grateful. indicator attach below
Attached File(s)
File Type: mq4 S.S.Short Term_Trend.mq4   9 KB | 365 downloads
 
 
  • Post #22
  • Quote
  • Oct 8, 2016 10:12pm Oct 8, 2016 10:12pm
  •  MaxEnrik
  • | Joined Jun 2015 | Status: Member | 174 Posts
Hi,

I have zero experience about codes.

So I yesterday started build my (mini - for now) TradePanel.
I designed "Sell, Buy, Lot Size / (Lot -, +), Stop Loss and Take Profit (SL, TP unchangeable)".

So "Sell, Buy, Stop Loss and Take Profit (SL, TP unchangeable)" works perfectly.
But I do not know how can I write codes for "Lot Size / (Lot -, +)".

Whats your advice me?
Please help me.

Have a great Weekend,
Max
Inserted Code
// I designed Lot Box, Lot Minus, and Lot Plus - no functional for now.
ObjectCreate ( 0, trade_panel + "LOT_BOX",         OBJ_EDIT,            0, 0, 0 );
...
ObjectCreate ( 0, trade_panel + "LOT_MINUS",       OBJ_RECTANGLE_LABEL, 0, 0, 0 );
...
ObjectCreate ( 0, trade_panel + "LOT_MINUS_LABEL", OBJ_LABEL,           0, 0, 0 );
...
ObjectCreate ( 0, trade_panel + "LOT_PLUS",        OBJ_RECTANGLE_LABEL, 0, 0, 0 );
...
ObjectCreate ( 0, trade_panel + "LOT_PLUS_LABEL",  OBJ_LABEL,           0, 0, 0 );
...
// LOTs Close--------------------------------------------------
 
 
  • Post #23
  • Quote
  • Oct 9, 2016 1:42am Oct 9, 2016 1:42am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Quoting Thebeard
Disliked
Hey D. Great thread. I Have EA that relies soley on maths/indicator/logic. I have been trying to build it in FxPro Quant builder. It's drawn as flow chart with inputs, AND/OR logic and indicator values. And as such contains some code. Now i can get a simple buy on first tick EA to open but when I add other things into the mix it doesn't work. I don't know what bits of code do what. How do I arrange all the bits together to form a working EA? I understand it's a bit vague but I'm hoping this opens up questions so we can get into specifics. Reason...
Ignored
Great to know you are trying to build EA which work solely on indicators and logic. But the platform you chose to build "FXPro Quant Builder" is very primitive. It does not offer much functionality. Even I use it at some cases where I need to generate basic functions, but i suggest you to try a bit more advance builder such as "EA Builder" it not free entirely but a great tool to build EA and indicators.
Assembling the small code is not like joining with connectors as provided in Quant builder. The basic functions which is generated by Quant builder must be slightly changed according to your need before you can integrate them to build the final product. That's where the EA Builder comes, it provide much advance functionalities so we don't always need to integrate small codes in hard way.

Any way I will be slowly covering all parts which will eventually clarify all your doubts and problems. Just Keep an eye on this thread.
 
 
  • Post #24
  • Quote
  • Edited 8:23am Oct 9, 2016 7:35am | Edited 8:23am
  •  Thebeard
  • | Joined Sep 2016 | Status: Member | 35 Posts
Lovely.

Thanks I'll take aclook at EA builder and go from there.

Do all these third party softwares have to use the same code.

For instance buy on first tick would be same actual piece of code regardless of software used.

Each software just has a different UI and way of displaying same code?
 
 
  • Post #25
  • Quote
  • Oct 9, 2016 10:37am Oct 9, 2016 10:37am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Quoting Thebeard
Disliked
Lovely. Thanks I'll take aclook at EA builder and go from there. Do all these third party softwares have to use the same code. For instance buy on first tick would be same actual piece of code regardless of software used. Each software just has a different UI and way of displaying same code?
Ignored
Yup... regardless of the software the working principle of the code is always the same..
 
 
  • Post #26
  • Quote
  • Oct 9, 2016 10:48am Oct 9, 2016 10:48am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Quoting samsane
Disliked
please will like to know if someone can convert an indicator in mql4 to mql5 will be very grateful. indicator attach below {file}
Ignored
Please use this below mentioned site. They convert for free. Though I don't know if it works properly after conversion. I did a conversion of your file and it generated mql5 file. I could have attached it for you.... but this will encourage others to not to learn and depend on others. Please try it yourself. Its very simple. You just need to upload and download. Still if you could not do it then i will help you to do so.

Use this website to convert from mql4 to mql5: http://mqlconvert.cyberfx.org/
 
 
  • Post #27
  • Quote
  • Oct 9, 2016 11:14am Oct 9, 2016 11:14am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Quoting MaxEnrik
Disliked
Hi, I have zero experience about codes. So I yesterday started build my (mini - for now) TradePanel. I designed "Sell, Buy, Lot Size / (Lot -, +), Stop Loss and Take Profit (SL, TP unchangeable)". So "Sell, Buy, Stop Loss and Take Profit (SL, TP unchangeable)" works perfectly. But I do not know how can I write codes for "Lot Size / (Lot -, +)". Whats your advice me? Please help me. Have a great Weekend, Max // I designed Lot Box, Lot Minus, and Lot Plus - no functional for now. ObjectCreate ( 0, trade_panel + "LOT_BOX", OBJ_EDIT, 0, 0, 0 ); ......
Ignored
Hi Max

Great man... Its good to see you taking small steps in the field of coding...
Seems like you have created 4 objects (in general term container) to hold data about your lots. This is just a internal container for the code. To display actual data on your MT4 platform you need to use ObjectSetText(); as below

ObjectSetText( trade_panel + "LOT_MINUS", My_Lot_Value ,30, "Verdana", Lime);

Hope this helps you. Don't worry i will be covering about it in details as I proceed with my posts. Keep an eye on each posts... the replies i provide to other traders queries will help you a lot.
 
 
  • Post #28
  • Quote
  • Oct 9, 2016 11:52am Oct 9, 2016 11:52am
  •  MaxEnrik
  • | Joined Jun 2015 | Status: Member | 174 Posts
Thanks for your reply, I highly appreciate that.
I will try it soon. If you can explain it a bit more, that will help me a lot. I am waiting for your next posts.

Warm Regards.
(P.S English is not my native language.)
 
 
  • Post #29
  • Quote
  • Edited 2:43pm Oct 9, 2016 2:31pm | Edited 2:43pm
  •  Ragusa
  • | Joined Jun 2013 | Status: Member | 175 Posts
Interesting thread!
Here some links which may be useful:

Mql4 book: S. Kovalyov

Programming in Algorithmic Language MQL4

Introductory Course

https://book.mql4.com/



MQL4 Reference
https://docs.mql4.com/
Investopedia:
http://www.investopedia.com/universi...dvanced-guide/
Mql-code
https://sites.google.com/site/market...s-once-per-bar
https://sites.google.com/site/market...once-per-bar-2

https://sites.google.com/site/market...ding-functions
https://sites.google.com/site/market...a-forex-mt4-ea
On line generator:
http://www.forexeadvisor.com/expert_generator.aspx
Babypips:
How to Create a Simple Forex EA Using the MetaEditor Wizard

Simple tutorial:
http://smartforexlearning.com/mt4-ea-course-first-forex-expert-advisor/


Add Custom Indicator to Expert Advisor https://forum.mql4.com/45675

How to get iCustom values from indicators

http://www.forexfactory.com/showthread.php?t=387508


How to Create an Expert Advisor for a SuperTrend Trading Strategy
By Tradinformed
 
1
  • Post #30
  • Quote
  • Edited 2:43am Oct 10, 2016 1:51am | Edited 2:43am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Seeing lots of useful links added by different members in the posts, periodically i will take them to the beginning of the first post so that all the important materials will not be lost within different posts and could be found at one place. Do check the starting post time to time as it will be updated slowly.
 
 
  • Post #31
  • Quote
  • Oct 10, 2016 7:18am Oct 10, 2016 7:18am
  •  Passerby
  • | Joined Jan 2012 | Status: Droid master | 894 Posts
D.s, got question for you. So i have an ea, as most of mine is rather complicated. I know im knot a good coder, so i just make it works at first with all calculation working. Then i optimize the code manually, eliminate some i dont use and making it more "readable" by adding comments, grouping similar steps, etc. This often create problems, which i then sort after some times. This is my kinda SOP.

I curious about these, hope you could helps clarify this:
1. I confirm than the result of these formula is different after debugging:
(A>=B) are not equal to (A>B || A==B), its weird

2. Sometimes i repeat similar calculation with slight dif(like pairs, tf, or period), to make it simple and less error prone i made it into function(void) and called it when i need it. But i notice after test it on tester that my code runs significantly slower using function. I dont mind longer code, but if i does the job done with less line and dont deteriorate execution time it will be better.

Is this the way it is on mt4 or its just i got problem somewhere else, thanks.
 
 
  • Post #32
  • Quote
  • Oct 10, 2016 9:22am Oct 10, 2016 9:22am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Quoting Passerby
Disliked
D.s, got question for you. So i have an ea, as most of mine is rather complicated. I know im knot a good coder, so i just make it works at first with all calculation working. Then i optimize the code manually, eliminate some i dont use and making it more "readable" by adding comments, grouping similar steps, etc. This often create problems, which i then sort after some times. This is my kinda SOP. I curious about these, hope you could helps clarify this: 1. I confirm than the result of these formula is different after debugging: (A>=B) are not equal...
Ignored
I tried to confirm your first issue where (A>=B) are not equal to (A>B || A==B), but could not recreate the problem and i have never faced such type of issue in other programming language. Seems like your issue might be caused by different datatype for A and B.

For your second question where you think adding few more lines is slowing down your performance significantly, then you might be using computers from 1800s...... just kidding..
Our current processing speed is much better so its not systems fault. Only in one condition it may happen when you recursively call a function within a function... this can slow down your processing speed. Just check if you are not doing such issue like there is two functions you have created: fun1() and fun2(). And then you are calling fun2() inside fun1() and again calling fun1() inside fun2(). I did such blunder once and it crashed my system.
But on thing determine your execution speed in MT4, if you wrote your code inside function void OnTick (), then unless there is a new tick data send by your server, your entire program will wait for it and will execute each time there is a new tick data sent. This can explain your code slow execution.

Hope it helped you in any way....
 
 
  • Post #33
  • Quote
  • Edited 12:50pm Oct 10, 2016 11:22am | Edited 12:50pm
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Elaborating Second step: Drawing out our personal flow diagram.

Though drawing flow diagram is very primitive technique for a coder, but as most of us are Traders not exactly coders, this step will help us visualize our whole system and help us to understand and create our automated system easily.

To teach flow diagram I took an example, let me design a simple EA which will trade on below conditions:
1. Let me generate my trading signals using 10, 20 and 50 period moving average (SMA).
2. 20 Period SMA should be above 50 period SMA and 10 period SMA should be above 20 period SMA then initiate buy signal.
3. 20 Period SMA should be below 50 period SMA and 10 period SMA should be below 20 period SMA then initiate sell signal.
4. Close trade when there is 100 Pips profit or a new opposite signal is generated or my risk increases or 10 between 20 and 50 or 50 between 10 and 20.

FLOW Dig:
INPUTS BY US [Initial Lot Size, Time Frame, Moving Average_1, Moving Average_2, Moving Average_3, Risk Percentage of my account] --------> EA CONTROL CENTER[ Is there a new buy signal call the open new_trade_function() and provide (buy and lot size) to it.
Else is there a new sell signal then call the new_trade_function()and provide (sell and lot size) to it.
Is there an already open trade and a new signal is generated then close the open trade.
Is the open trade reached the designated profit level (100 pips) then close the open trade.
Is the risk is too great for the account then close the open trade using close_trade_function() and then RESET.] <-------- SIGNAL GENERATOR [20 Period SMA should be above 50 period SMA and 10 period SMA should be above 20 period SMA then initiate BUY signal.
20 Period SMA should be below 50 period SMA and 10 period SMA should be below 20 period SMA then initiate SELL signal.
10 Period SMA between 20 and 50 period or 50 between 10 and 20 period Initiate CLOSE signal.]

Independent new_trade_function() to open new trade when used.
Independent close_trade_function() close all open trades available.
Independent RESET function, to reset everything for a fresh trade to begin.

Arrow represent the external flow of data. Inside EA CONTROL CENTER block one by one condition is executed serially in a loop.
Sorry I could not draw in the forum so I tried to put each block inside [ ] and displayed a simple flow diagram. Please let me know if any point you are not able to understand. And start drawing your personal flow diagrams as per your trading rules.

In my next post I will discuss about dividing the code into small independent modular functions and how to generate them without actually writing.
 
 
  • Post #34
  • Quote
  • Oct 10, 2016 12:41pm Oct 10, 2016 12:41pm
  •  Ragusa
  • | Joined Jun 2013 | Status: Member | 175 Posts
Always reset after closing an open trade or only reset after closing a trade because "the risk is too great"? The first, I suppose.

I dont understand why you initiate "close signal" when "10 period SMA between 20 and 50 period or 50 between 10 and 20 period". After the initial rules, trades are only closed "when there is 100 pips profit or a new opposite signal is generated or risk increases", and "10 period SMA between 20 and 50 period" is not an opposite signal (nor is an opp signal that "50 period is between 10 and 20 period"). May be the explanation is that you mean this situation as equivalent to "risk increases"?
 
 
  • Post #35
  • Quote
  • Oct 10, 2016 12:49pm Oct 10, 2016 12:49pm
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Quoting Ragusa
Disliked
Always reset after closing an open trade or only reset after closing a trade because "the risk is too great"? The first, I suppose. I dont understand why you initiate "close signal" when "10 period SMA between 20 and 50 period or 50 between 10 and 20 period". After the initial rules, trades are only closed "when there is 100 pips profit or a new opposite signal is generated or risk increases", and "10 period SMA between 20 and 50 period" is not an opposite signal (nor is an opp signal that "50 period is between 10 and 20 period"). May be the explanation...
Ignored
oops.... I did some faulty explanation..... Actually this closing condition should also be added to my initial trading rule. i.e 10 between 20 and 50 and 50 between 10 and 20. As the fast moving average is not in synchronize with slow moving average, a close trade signal should be initiated.

And RESET will be triggered after a trade is closed. No matter how it is closed. Reset will take all the variables value to their default values so that calculations of previous trade will not affect the new trade calculations.
 
 
  • Post #36
  • Quote
  • Oct 10, 2016 2:17pm Oct 10, 2016 2:17pm
  •  Fernand
  • | Joined May 2016 | Status: Member | 115 Posts
another link:
Forex Strategy Builder Pro
14 days free trial,and very easy to use
 
 
  • Post #37
  • Quote
  • Oct 11, 2016 1:02am Oct 11, 2016 1:02am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Quoting Fernand
Disliked
another link: Forex Strategy Builder Pro 14 days free trial,and very easy to use
Ignored
I looked at the tool, though I have never used it, just by look I can say it eliminates tasks of two different tools ( designing tool and testing tool) and we can work on it without internet connection as it is a downloadable software. I downloaded it too. Great video tutorials also available to learn its use. Love it man....
I recommend others to have a look and download too --- Forex Strategy Builder Pro

I will also be updating the link at the beginning.
 
 
  • Post #38
  • Quote
  • Oct 11, 2016 10:37am Oct 11, 2016 10:37am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Guys.... I am not getting any doubts or questions from your end. So I am assuming that you are able to understand what I have shared till now. I hope every body is ready with their automated system blue-print in their workshop..
Well then in that case I will be starting more difficult part.... I hope traders are ready to become coders..
 
 
  • Post #39
  • Quote
  • Oct 13, 2016 11:07am Oct 13, 2016 11:07am
  •  D.s
  • | Commercial Member | Joined Jul 2016 | 252 Posts
Generating modular Functions for your EA

Till My last post every thing was related to pre-EA_Design, which was your own trading rules and a way to visualize your Ea before creating it actually.
From now onward, every post will be directly related to your EA requirement.

A good programmer always tries to write less code but accomplish greater task. Only way it is possible is to reuse your own code as much as possible. This is where dividing the EA into many modular small functions comes into picture.
To illustrate it clearly, let me take the same previous example, I have already generated the flow diagram for it, now it is time to define its functions.
No matter what type of EA you design there are some basic functions which cannot and should not be avoided.

1. OnTick() - This is the main function which is automatically executed by the EA, its name cannot be changed. Whenever a new tick data is sent by your server. So your entire core code( not other functions) must be inside this function, which you need to execute every time there is a new tick received.

2. Signal() - Your signal function will always generate signals like (Buy, Sell, Close, Do_Nothing) . This function can be written by hand or can be generated using any code generating tool I have mentioned at the first post such as: EA Builder , This function should always be called as soon as a new tick data is sent by the server. According to the output produced by the signal function, we will take appropriate decision..

3. Refresh() - This function will provide you with current market Bid, Ask, Sperad and all shorts of data which changes regularly. So that you will not do any calculation with old data and cause serious issue. This function is used just prior to any major calculation or prior to any opening or closing of trade.

4. Open_Trade() - As the name suggest you can call this function and provide it with your lot size, trade signal(Buy or Sell) and trade identifying magic number if interested and it will open a trade instantly. It can be generated using tool mentioned.

5. Close_Trade() - As the name suggest you can call this function and provide it with your trade identifying unique magic number and it will close the trade trade partially or fully as per your need. It can be generated using tool mentioned.

6. Profit () - This function will basically calculate the difference between your equity and free margin and let you know if you did any positive profit or negative profit (loss) at any point of time. It can be almost generated using tool mentioned.

7. Save_Data() - This is the most crucial function which will save your calculations every time it changes so that if you change your time frame manually or the EA is suddenly closed due to any incident, then on re-opening the EA, it will automatically update itself with the saved data and will not go mad.

8. Reset() - Any time all the open trades are closed and you need to start fresh with new signal, then this function will make sure that data from old trade do not confuse your EA.

These eight functions are always required for a EA to work normally. You can always change their name or can add new functions as per your requirement.

These are just function overview, if you have doubts post it. And if you can use the tools mentioned at the starting post, it will be much easier and better.

In the next post, i may pick any of this function and describe you the code within it.
 
 
  • Post #40
  • Quote
  • Oct 13, 2016 5:23pm Oct 13, 2016 5:23pm
  •  Kissa
  • | Joined Aug 2012 | Status: Member | 432 Posts
I am very interested.
I have a question but need to think it out, about the flow...be back with that in a day
 
 
  • Commercial Content
  • /
  • How to Build your EA
  • Reply to Thread
    • 1 Page 23456 10
    • 1 Page 234 10
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023