S.B.T. Site Admin
Joined: 30 Dec 2005 Posts: 73 Location: Japan
|
Posted: Tue May 05, 2009 1:56 pm Post subject: Tutorial |
|
|
Let's create your first EA on EAB!
SEE ALSO: Guide
0.Table Of Contents
1.Summary
2.Add 'Buy strategy'
3.Add 'Close(Buy) strategy'
4.Set 'Order options'
5.'Complete!'
6.Exercise
1.Summary
We create very simple EA this time.
The strategy is the following.
* Open a position when 14 Moving Average(MA) crosses and goes above 28MA(golden-cross).
* Close the long position when 14MA crosses and goes below 28MA(dead-coross).
2.Add 'Buy strategy'
We add the strategy to open a long position.
1. Click 'Buy strategy' tab to set the strategy.
2. Click 'Add' button to add new logic, then a logic section is shown.
3. Select 'Moving Average' as the left value.
4. Select '<' as logical operator for each logical value.
5. Select 'Moving Average' as the right value.
6. Input '14' to 'Period' parameter for the left MA.
7. Input '1' to 'Shift' parameter for the left MA.
8. Input '28' to 'Period' parameter for the right MA.
9. Input '1' to 'Shift' parameter for the right MA.
We finished to create the 'Buy #1' logic.
The left value means '14MA 1 bar ago', and the right value means '28MA 1 bar ago'.
This logic means '14MA 1 bar ago is less(<) than 28MA 1 bar ago'.
10. Click 'Add' button again to add new logic.
11. Choice 'AND' as logical operator for each logic to combine the 'Buy #2' logic to with the 'Buy #1' logic.
12. Select 'Moving Average' as the left value.
13. Select '>' as logical operator for each logical value.
14. Select 'Moving Average' as the right value.
15. Input '14' to 'Period' parameter for the left MA.
16. Input '0' to 'Shift' parameter for the left MA.
17. Input '28' to 'Period' parameter for the right MA.
18. Input '0' to 'Shift' parameter for the right MA.
We finished to create the 'Buy #2' logic.
The left value means 'Current 14MA(0 bar ago)', and the right value means 'Current 28MA(0 bar ago)'.
This logic means 'Current 14MA(0 bar ago) is greater(>) than current 28MA(0 bar ago)'.
This strategy means 'Open a long position, when 14MA 1 bar ago is less than 28MA 1bar ago and current 14MA is greater than current 28MA'.
If you'd like to know how to build typical strategy, see 'APPENDIX.How to build typicaly strategy' section in the guide, please.
3.Add 'Close(Buy) strategy'
We also add the strategy to close the long position which has been opened by 'Buy strategy'.
1. Click 'Close(Buy) strategy' tab to set the strategy.
2. Click 'Add' button to add new logic.
3. Select 'Moving Average' as the left value.
4. Select '>' as logical operator for each logical value.
5. Select 'Moving Average' as the right value.
6. Input '14' to 'Period' parameter for the left MA.
7. Input '1' to 'Shift' parameter for the left MA.
8. Input '28' to 'Period' parameter for the right MA.
9. Input '1' to 'Shift' parameter for the right MA.
We finished to create the 'CloseBuy #1' logic.
You've already known what this logic means.
That's right! This logic means '14MA 1 bar ago is greater than 28MA 1 bar ago'.
10. Click 'Add' button again to add new logic.
11. Choice 'AND' as logical operator for each logic to combine the 'CloseBuy #2' logic to with the 'CloseBuy #1' logic.
12. Select 'Moving Average' as the left value.
13. Select '<' as logical operator for each logical value.
14. Select 'Moving Average' as the right value.
15. Input '14' to 'Period' parameter for the left MA.
16. Input '0' to 'Shift' parameter for the left MA.
17. Input '28' to 'Period' parameter for the right MA.
18. Input '0' to 'Shift' parameter for the right MA.
We finished to create the 'CloseBuy #2' logic.
This logic means 'Current 14MA(0 bar ago) is less than current 28MA(0 bar ago)'.
This strategy means 'Close a long position, when 14MA 1 bar ago is greater than 28MA 1bar ago and current 14MA is less than current 28MA'.
4.Set 'Order options'
We set the options for the order which is executed by your EA.
1.Click 'Order options' tab.
2.Choice 'Complete Bar'.
3.Set some values if you'd like.
If you'd like to know what is the 'SignalMode', see '8.Order options section' section in the guide, please.
5.'Complete!'
We finished to creat EA.
When you just click 'Complete!' button, you can get your EA!
To use your EA on MT4, you need move the file to 'experts' folder in your MT4 folder.
After you compile the file on MQL Editor, you can use your EA.
6.Exercise
This EA executes only orders to open / close a long position.
Now, you should add the strategy to open / close a short position, when 14MA and 28MA make dead-cross.
Let's try to add the strategy!
S.B.T. |
|