+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 30

Thread: MQL4 Moving Average Crossover System

  1. #1
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    90

    MQL4 Moving Average Crossover System

    Richard asked on the blog if we could come up with a version of our Robot Example 3 modified to use fixed take profit and stop loss levels, rather than simply doing a stop and reverse at each crossover.

    We've added in some sections of code from our Robot Example 2, and here is the resulting expert advisor:

    GuruEx03A.zip

    Experiment with it on different time frames and let us know what you think of it.
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  2. #2
    Junior Member
    Join Date
    Apr 2010
    Location
    Melbourne, Australia
    Posts
    5
    Thanks Jim, will have a play with it now.
    Quick question, will it work on 5 decimal place brokers ok ?

  3. #3
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    90
    Should work fine with 5 DPs. The TP/SL levels don't automatically adjust between 4 and 5 DPs, but then you'll probably want to experiment with those anyway. The defaults are certainly not optimised in any way!
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  4. #4
    Junior Member
    Join Date
    Apr 2010
    Location
    Melbourne, Australia
    Posts
    5
    One other question please. Does the new setting 'StpMode (True/False)', turn on/off the TP/SL override?
    If I want to try out my own TP and SL, should I have this setting set to False?

  5. #5
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    90
    Quote Originally Posted by rv73 View Post
    One other question please. Does the new setting 'StpMode (True/False)', turn on/off the TP/SL override?
    If I want to try out my own TP and SL, should I have this setting set to False?
    Hi Richard,

    That setting controls how the expert advisor sets up the TP/SL at your broker. With it set to False the TP/SL levels are included in the opening market order.

    When the NFA introduced the first-in first-out section of their notorious "no hedging" rule that method stopped working with a lot of so called STP brokers. If you get errors opening orders try changing StpMode to True.

    The new version of the EA always tries to use the TP/SL override.

    Jim
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  6. #6
    Junior Member
    Join Date
    Apr 2010
    Posts
    14
    Dear Jim,

    Firstly, I'd like to thank you for putting the Crossover EA into the public domain. I've have been looking at several coded examples of such an EA but have been frustrated by various factors when running the code, not least my own inability to program same but more often than not, the obvious omission of closing any existing orders that are in place when reversing trades. Refreshingly, I have found that your GuruEx03 EA example performs all the tasks perfectly.

    However, I have a request to make in respect of how the code manages positions which I would dearly like to see added to the EA, if at all possible. The idea is that a trade is taken on each crossover with a fixed or trailing stop loss yet has a profit target which if met, exists the trade until another crossover is made. In this instance, several trades would be executed until the profit objective is met.

    By way of example, on an intra-day chart of say n minute bars the EA would have a profit objective of x pips. If using a 5 minute chart with a profit objective of 50 pips then the idea is to take each trade on a crossover until the profit objective is met, at which point, stop trading until the next crossover. Clearly there will be several trades made before the profit objective is (possibly) met which might in fact cause a somewhat hefty drawdown but it would be interesting to find out exactly how well this performs in a backtest. Would it be at all possible for you to give this a bash?

  7. #7
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    90
    Hi Highfield,

    Quote Originally Posted by Highfield View Post
    I've have been looking at several coded examples of such an EA but have been frustrated by various factors when running the code, not least my own inability to program same.
    What do think has held you back from learning how to program (or at least modify) EAs yourself?

    Quote Originally Posted by Highfield View Post
    By way of example, on an intra-day chart of say n minute bars the EA would have a profit objective of x pips. If using a 5 minute chart with a profit objective of 50 pips then the idea is to take each trade on a crossover until the profit objective is met, at which point, stop trading until the next crossover. Clearly there will be several trades made before the profit objective is (possibly) met which might in fact cause a somewhat hefty drawdown but it would be interesting to find out exactly how well this performs in a backtest. Would it be at all possible for you to give this a bash?
    The new version 3A that Richard requested seems like it might do at least part of what you're asking for. If so I'm not sure I understand the rest yet. You want to add to that some sort of pyramiding, so that you can have several trades open at once, each entered on a crossover in the same direction? If that's the case, when do you exit if things turn pear shaped?

    Alternatively, you want your EA to work exactly like the original version 3 until your overall profit target is reached. Then you stop and wait for the next crossover? Again my question is the same. Where is your emergency exit, or are you happy just to let your drawdown get as big as it likes?
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  8. #8
    Junior Member
    Join Date
    Apr 2010
    Posts
    14
    Quote Originally Posted by Jim View Post
    What do think has held you back from learning how to program (or at least modify) EAs yourself?
    I have modified Metatrader indicators before and I even managed to produce my own from scratch (although I shan't embarrass myself by posting it here) but what is holding me back is the lack of a good book about MQL programming that I can really get my teeth into!

    Quote Originally Posted by Jim View Post
    The new version 3A that Richard requested seems like it might do at least part of what you're asking for. If so I'm not sure I understand the rest yet. You want to add to that some sort of pyramiding, so that you can have several trades open at once, each entered on a crossover in the same direction? If that's the case, when do you exit if things turn pear shaped?
    Indeed! I attempted to modify your GuruEx03 EA myself by adding a profit target to it but the code didn't want to work correctly (unsurprisingly). Then I downloaded the modifed 03A version and indeed I misunderstood your post in reply to Richard's request as the new code appears to do exactly as I outlined ("... rather than simply doing a stop and reverse at each crossover." I read this as though the EA would effectly take one crossover as a signal and then wait for either the profit target or stop loss to materialise).

    Quote Originally Posted by Jim View Post
    Alternatively, you want your EA to work exactly like the original version 3 until your overall profit target is reached. Then you stop and wait for the next crossover? Again my question is the same. Where is your emergency exit, or are you happy just to let your drawdown get as big as it likes?
    This is how I initially envisaged the EA as working; without a stop loss although the next stage would have been to implement that safeguard.

  9. #9
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    90
    Quote Originally Posted by Highfield View Post
    This is how I initially envisaged the EA as working; without a stop loss although the next stage would have been to implement that safeguard.
    OK. I'll ponder how to implement that, and see what I can come up with. I'm sure you're well aware that all the forex eBooks say working without a stop loss can only ever end in tears!
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  10. #10
    Junior Member
    Join Date
    Apr 2010
    Posts
    14
    There's nothing quite like taking one on the chin to know exactly how it feels though

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts