I have decided to post my EA here for two reasons:
1) I like it but am sure it could be much better and want to get help to improve it
2) I was humbled by the way others (George) have freely shared their code, ideas, and most importantly their time, to assist others.
So here's my back story...(briefly)
After blowing several thousand dollars over the past few years I started looking through this site and came across a few ideas and indicators I thought worth looking at in more detail to see if I could make them work for me. In particular I picked up some ideas/indicators from Alien, Jim Brown (JagFX), Jim Dandy (check his Youtube channel) and Astorcoder - so kudos go to them...but also the many who contributed to their systems as well.
I have found two major stumbling blocks in my trading - I am in Eastern Australia (Sydney) so am always asleep when the major markets are open, and I am too emotional so tend to dive in too early, take quick small profits and sit on losses.
My solution (as an ex programmer) was to develop a robot that would take the emotion out and trade when I was asleep.
So I have developed a robot which I have called Gurumarra Forex (Gurumarra is an aboriginal word meaning something like "electrical storm" or "dry lightning") and I am now sharing it.
I have only just commenced running it live and have mixed results in my account due to some bugs that were not identified in back testing and which resulted in some losses. But here's a sample test result attached.
Some comments and explanations:
I have tried the EA out on multiple time frames but am concentrating on M30 charts - having said that I get comparable results on H1 and H4 as well.
The EA does NOT work on every pair - much of my testing has been to identify those pairs that seem to produce the best result.
I am happy to take a large DD so long as I can be confident that the price will come back to profit so I do NOT use stops but do control maximum DD via a parameter.
I want the profits to run but have no idea where to set the TP so have incorporated various options for the exit as you will see in the parameters and in the code. I have no idea how many pips or $ to set as a target so have decided to set the target as a % of the account balance.
As far as the exit is concerned I have noted that a turn of the OsMA works well at getting out with a profit so I use a smoothed average value of this indicator to exit (if the target % has not yet been reached) and the PA (price action) is turning the wrong way.
With all the indicators in the world I reckon you still can't predict which way the PA will go so the EA places a straddle on the trigger bar and then waits for it to be triggered.
I have not massaged the code to make it pretty but no apologies - take it or leave it as you will - but improvements are welcome (see above).
In the next post I will explain the parameters and provide the indicators required - OSMA should be in your basic MT4 package but the others are ALL required and available elsewhere on this site as well. The QMP Filter, QQE Advisor and MACD Platinum are thanks to Jim Brown who uses them in his trading strategy and is happy to share them - they are essentially the "trigger" for the trade. The RSIOMA is used as a filter to weed out the trades that are at extreme values (actually somewhat opposite to Jim's approach). Note that the indicators aren't required on the chart but they are needed in the environment.
UPDATE - Note that this EA uses bar open to control exit/entry however testing should still be performed on every tick
UPDATE - Latest version of the EA is now attached to this post #1. Code has been cleaned up somewhat and some minor changes in message handling/descriptions and the time limit for Friday trading - now set to cease trading on Friday after 12 noon - you may want to configure to your local time zone.
UPDATE/CORRECTION to post #5
The value for STDDEV for initial testing runs should be 99999. My bad. Testing this for values between 1-10 should be done after the RSIOMA, Risk and other parameters have been tuned.
UPDATE 29 May 2019 - New version 1.4 attached - see post #51 below for details
Requires Gann-High-Low-Activator in environment (copy attached here)
UPDATE / WARNING 05 June 2019
Running multiple copies of the EA on the same pair but different times (e.g. M30 & H1) AND permitting multiple open orders appears to result in interference between the two, resulting in orders being closed with a loss. I am investigating this but for the time being please follow the original recommendation of permitting only 1 open order at a time. ...and yes I got hit last night Australian time
Gurumarra Forex V1.1.mq4
Gurumarra Forex V1.4.mq4
As I said in the first post the code is scrappy so there are some inconsistencies in the way the parameter values are configured.
Buy Target/Sell Target
These were originally developed as a single value but I soon realised that the ability to set them separately provided a more "fine-tuned" approach. This parameter has a value between 0 and 1. This is a percentage of the account balance so an example: if you have a $1000 balance and enter 0.10 then the target profit is 10% of your account balance or $100. A value of 1 means you are looking for a 100% ($1000) profit as your target.
This is the % of your account free margin you are willing to risk. Depending on the pair i have found values between 2% and 7% are the maximum - above that the DD (draw down) quickly increases to very large levels.
The maximum lot size you are prepared to run at - my broker has a limit of 20 lots but others may have smaller or greater lot size limits
True - the EA will automatically close trades if the exit conditions are met - recommended
False - the EA will send a message to your email and MT4 that a close condition has been met but will NOT close the position
Should be self explanatory
The maximum number of active orders for this magic number (I recommend leaving at 1)
The minimum and maximum values that the RSIOMA indicator must be before a trade will be triggered. This has to be tested and set for each pair, for each timeframe and each broker the EA is running on. This may need adjustment over time as the market changes so be prepared to conduct confirmation testing on a monthly basis.
Expire in Mins
As noted the EA places Limit orders as a straddle on the trigger bar. This parameter sets the number of minutes after which the orders will expire.
This is the smoothing factor for the OsMA - generally a value of 6 periods seems to work but this too needs to be tested for each pair/tf
Maximum DD (drawdown)
This is the control for catastrophic SL (stop loss). In testing and selecting the best performing pairs I set this to a value of 0.6 (60%). The code will close an order if the DD goes above this value. You should set this based on your intestinal fortitude but lower values lead to a lot of stop outs.
Close After / Close Negative
These parameters work together to control the amount of time that a position will be negative before a theoretical SL will close the position. So for example if you set these as 1 / 0.01 the EA will close the position if (a) the position is more than 1 hour old; AND (b) the maximum loss is less than 1% of the account balance. Play with these to see what works best. In my initial testing I always set the time to 999999 and leave the % at 0.01 meaning it will never trigger. I only tune this after other basic parms (Risk, RSIOMA) have been set.
New Code Activated
This is for testing new code so that I can determine the impact. Once happy that the new code is OK and embedded in the EA this can be turned off - for the coders out there this can be useful. For this first version leave it as "true" as I have not yet performed the clean-up and the code is running OK.
This is essentially experimental - I found that often the OsMA would indicate an exit well away from a better profit. By calculating a standard deviation I have improved the profitability by setting this parameter such that if the profit was 'x' standard deviations away from the median then the EA would close the position and capture the profit - a better way might be to close part of the position (say 50%) at this point and leave the rest on the table. Any suggestions here very welcome.
This is another "experimental" parameter and I may remove it at some stage. Basically it says that if the profit has reached this value as a % of the account then take a profit no matter what the other profit setting parameters are set at. On the face of it this would seem to be interfering with the other parameter settings yet I have found that it seems to improve profitability. Another parameter that needs to be tested.
This is strictly for controlling the visual back test speed (thanks Jim Dandy)
The lot size algorithm calculates the order size based on margin, risk and cost. This permits the user to further fine-tune the lot size (and ultimately the DD and profit) by reducing (or I suppose increasing) it by multiplying the base lot size by this value - so for example say the algo calculates a lot size of 2 and this parm is set to 0.9 then the actual order size will be 1.8 lots.
That's it for the parms so please find attached the code and the required indicators - over to you .....
Gurumarra Forex V1.mq4
read all posts...and tested ea...
1 buy stop 1 sell stop , only close the winning trade and if lose happens exit trades at breakeven.
the basic theroy maybe wrong...
1 before blew up, make money as much as possible.
2 trading multiple pairs EX.
buy on EU is in -50 pips, the next trade is on UJ will be doubled on size. if we still get -50 pips, then the next trade on next pair should be doubled............exit untill we get some profit.
no offence dude only talking about the ea, 7 years i have been looking for a long trem profitable ea...
very few of them are profitable, some of them have SL, the others will start hedging to cover the loss.
Test 1 - set the parameters as per the attached - the first thing is to find the best settings for the RSIOMA - so set all other values as shown and then backtest just those values.
Test 2 - having set the RSIOMA test for the best risk setting
Test 3 - after setting RSIOMA and risk test for Standard Dev
Test 4 - now test lot_control
Test 5 - now try different combinations for the Buy and Sell targets - does a fixed TP % return better results?
Now do this for every pair you want to try against and select the best - I have found on the 30m chart the best pairs for me (and my broker) are in descending order:
On the H4 chart:
BUT BUT BUT - results may vary depending on your broker settings for things like MIN_LOT, LOT_STEP, and LEVERAGE
Do lots of testing!!!
Update - I use Tick Data Suite and my testing period is currently from Dec 1, 2015 to Apr 30, 2019 which gives plenty of trades. On June 1 I will roll my test period forward by 1 month and test again to confirm that my results remain within my expectations - e.g. profit and drawdown are within just a couple of % of my previous results.
Update - I noticed an error in the settings I loaded for initial backtest and have corrected the attached .jpg
A few downloads but only 1 comment - updates (even just to tell me you are testing or you hate it) would be very welcome. Especially any ideas for other indicators that might improve the entry/exit or reduce the DD.
I'm going to work on the next version - goal is to incorporate a partial close of the position when the profit is greater than STDDEV and set a profitable (hidden) stop loss for the rest of the order. Hopefully this will increase profitability.
I've tried partial close with the OrderClose function but this does not work with my broker. Reading through the forums indicates the only effective way to do this is to open multiple orders and then close the positions gradually. I'm not sure how to do that last part (gradual closing of the positions) specifically so will keep investigating. If anyone has a function or idea about this please share.
I'm thinking to close this down since no-one actually seems to want to contribute. Guess I was wrong about posting something here...
Hold on buddy. I'm downloading and will try some tests today. I'll follow that sequence you posted.
Thank you for sharing.
Yes and regarding a partial close during operations, for American traders FIFO rules apply. So I believe multiple orders would have to be made and then closed on a First In First Out basis.
Thanks for sharing your hard work. Funny enough I was checking out some of Jim's stuff earlier and just so happened to come across this thread 2 hours later.
Is your entries exactly the same except for the added filter?
Are you hedging yourself out of losses?
I'll be doing some testing next week
Can you post a backtest with fixed lot sizes?
If I try to backtest it, it tells me that there is an "array out of range".
No I am not hedging. The trades are straight forward but the DD can be very deep (60% of account) and so without confidence in the price coming back you may have a few sleepless nights. This is why I have the Maximum DD as a parameter - it is up to the trader to determine how deep they are prepared to go before taking a loss. I hate using a SL as I have seen too many times where the stop was taken and then price moved back. There is a thread here (frequented by @Robots4me and @GeorgeAUS) which discusses the presence of a market maker who manipulates the prices to target heavy SL areas.
My testing has found that fixed lot sizing definitely reduces the profitability.
That is why I look for results where the EA does not have any losses at all over a 42+ month period - that confirms for me that the strategy is right. I have had to sit on a loss for 3 months before the price returned and took a profit - but it did come back and I did get a profit.
At the end of the day all trading is a risk - if you can't afford the loss then don't trade or run with tight parameters that will make you comfortable with the DD - you are still in charge at the end of the day and price diving forever could happen with any EA or trading strategy.
There is no holy grail and I do not claim that this is.
© Forex Factory