stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Trend Trading EA with Automated Loss Recovery
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3719
Page 1 of 14
Author:  SpiderX [ Tue Jul 08, 2014 4:34 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

SERIOUS WARNING
Most Forex traders lose all their money.
Using the robot posted here in trading Forex does not guarantee success.
Trading this robot could lead to serious financial loss.
Trading this robot without understanding its underlying trading strategies guarantees traders will lose their money.
This is not a set-and-forget ea; there is no such thing and anyone who tries to claim there is, is either stupid or lying. This ea requires frequent manual intervention.
At best, a trading robot is only 90% as good as the manual strategy it trades. At best. At worst, it can be much less effective. If the strategy is rubbish, so is the robot.
To trade this robot, you have to understand:
How to use EA's.

THIS IS AN EXPERIMENTAL EA NOT YET BEING USED ON OUR LIVE ACCOUNTS


This EA is a result of the discussion from :
http://www.stevehopwoodforex.com/phpBB3 ... =23&t=3682
http://www.stevehopwoodforex.com/phpBB3 ... =12&t=3708

USE THIS ON A 4H CHART ONLY

Trading Rules
Long Trade Entry
1. Price is above 240 Lwma
2. MACD Main signal below 0
3. Price open below 5ema shift 5 and close above

Long Exit:
1. Trade is in profit
2. Price opens above 5ema shift 5 and close below

Short Trade Entry
1. Price is below 240 Lwma
2. MACD Main signal above 0
3. Price open above 5ema shift 5 and close below

Short Exit:
1. Trade is in profit
2. Price opens below 5ema shift 5 and close above

Trade Exits will be invalid once first ALR trade has trigger.
After recovery trade has triggered, trades will exit either by sl or tp.
Please do not use Stoploss management with ALR as it will mess things up.


The EA is coded on a customized shell , which is a hybrid of Steve's and Tommaso.
The good thing is that most of the code is designed to be efficient and reduce CPU cycles in processing of the EA,
but the down side is that it is relatively untested compared to Steve's/Tommaso shell and there could be some bugs lurking around.(though hopefully unlikely)

Please test out this initial version and see if you encounter any bugs or errors.
Currently, the lot size setting if using FixedLot = false, is based on the Stoploss value, as such it is recommended to do your own Math and set StopLoss to be equal to (ALRZonePips + ALRTargetPipsOppDir).

At this point of time, it is nice if someone can backtest this EA on Empty4 in tick mode, just for sanity checking purpose. (Didnt manage to do this due to time constraints)
Dewey was testing out earlier and it seems to be fine (as long as the backtesting is not in candle mode)

Code: Select all

extern string   gen0a="====Automated Loss Recovery Settings====";
extern bool   useAutomatedLossRecovery = true;
extern double ALR_ZonePips                    = 50;
extern double ALR_TargetPips_SameDir   = 150;
extern double ALR_TargetPips_OppDir     = 150;
extern double ALR_TargetProfitDollars     = 10.0;
extern double ALR_DollarPerPipLot          = 10.0;
extern int    ALR_MaxTrades                   = 10;     
extern double ALR_SpreadPips           = 1;
The ALR settings can be adjusted as the above parameters and they are almost exact as per Dewey's spreadsheet.
Hopefully Dewey can recommend some settings and will hardcode it into the EA.


To do list:
1. Update more details on the EA in post 1.
2. Add ALR_PercentRisk parameter based on worse case loss when ALR sequence ends with a loss
3. Initial lots and risk calculation to be based on ALR settings rather than stop-loss when useAutomatedLossRecovery is enabled true.

Version Updates:
v1.01
-Added in code in consideration of ALR Max Trades Limit. (Forgot about this one)

v1.02
-Add trade comments to make trades more traceable
-Some code clean up and minor efficiency enhancements

v1.03a
-Some bug fixes in InitializeALRPositions, this should fix the issue of wrong lot sizes
-Initialize ALR to round up lots to next lot step in lot size calculation
-Note: If you are "backtesting" , try using visual mode at highest speed.

v1.03b
-Add tracking of number of positions in code
-If there is a discrepancy in positions, EA will close all positions for safety.

v2.00
-Major rework of ALR concept
-Initial trade is closed and loss is taken, while the next order in the opposing direction is opened.
-Basically, the next order in the opposing direction is taken to cover the losses of the previous trades
This results in smaller positions and smaller losses for same number of turns.
ALR Variables:

Code: Select all

extern bool   useAutomatedLossRecovery = true;
extern double ALR_ZonePips             = 50;
extern double ALR_TargetPips_SameDir   = 150;
extern double ALR_TargetPips_OppDir    = 150;
extern double ALR_ProfitPips           = 10.0;
extern double ALR_CommissionPips        = 1.0;
extern int    ALR_MaxTrades            = 10;    
extern double ALR_MaxLots              = 5.0;
ALR_ProfitPips is the number of addition pips in profit to add to each trade cycle.
ALR_CommissionPips is the number of pips your broker charges as commission which has to be taken to consideration with each trade that is closed.
ALR_MaxLots limits the maximum lots possible in the ALR progression and it supercedes ALR_MaxTrades.
If ALR_MaxLots is exceeded, then ALR_MaxTrades will automatically be toned down.

v2.01
-Patched in a missing line in the error catching code

v2.02
-Add in missing code to remove all pending trades when original trades are closed by the EA

v2.03
-More options to adjust timeframe for indicators
-The Timeframe settings for all indicators default to 0, which is chart tf settings.
Please look at variables:

Code: Select all

extern int      MACD_FastEMAPeriod =0;
extern int      TradingTimeFrame   =0;
extern int      FastMaTdTF    =0; 
extern int      SlowMaTdTF    =0;
v2.04
-Fixed bug that caused lot size calculation to be wrong
-Fixed bug that caused lot size of recovery trades to be wrong

v2.05
-Code improvements to better adjust profit at the end of the ALR progression
-The target price is no longer static and is adjusted slightly to precisely achieve the target profit.
-Please use ALR_ProfitPips if you like more profit at the end of the ALR progression.

v2.06
-Removed ALR_ProfitPips and replaced with ALR_TargetPercentProfit
Use this to set the target percent profit you wish to have at the end of an ALR progression
0 is ok, if you wish to minimize lot sizes, anything higher means higher lot sizes.
i.e: if you set 0.1%, you get a 0.1% profit for your account at the end of each ALR Progression upon hitting tp.

-new variable ALR_MaxPercentLoss
Determines the maximum hit to the account for ALR progression and supercedes MaxALRTrades
Use this to protect your account from more losses than acceptable.
i.e: for 20%, the maximum hit your account can take is 20% and no more.

Code: Select all

extern double ALR_TargetPercentProfit  = 0.1;
extern double ALR_MaxPercentLoss       = 20;
Cheers
Author:  SpiderX [ Tue Jul 08, 2014 4:35 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

ALR2.0 Trade Manager

This was a request from Dewey.
ALR2.0 Trade Manager will automatically manage any trade for the symbol with the same Magic number as the setting in the EA.
It will create a pending once there is a trade with the same Magic number, and this would be deleted if the trade was not stopped out.
Additional variable: ALR_AutoTPandSL
If set true, this ignores ALR_TargetPips and ALR_Zone, the target pips and zone pips are set according to the TP and SL of the initial trade.
If this is set false, the trade manager will automatically adjust the initial trade tp and sl to ALR_TargetPips_SameDir and ALR_ZonePips .

Trade manager moved here:
http://www.stevehopwoodforex.com/phpBB3 ... 792#p97774

Cheers
Author:  SpiderX [ Tue Jul 08, 2014 6:07 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

Hi,

Need to upload v1.01 as something just occured to me.

v1.01
-Added in code in consideration of ALR Max Trades Limit. (Forgot about this one)

ALRTrade management will exit onces the ALR_MaxTrades are reached.

Cheers
Author:  SteveHopwood [ Tue Jul 08, 2014 8:32 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

Fantastic stuff Spi. :clap: :clap: :clap:

I shall try to draw attention to this.

Any time you need another post at the top of this thread, post it as normal then ask Tommaso to change the time and date stamp and your new post will appear where you want it.

:xm:
Author:  milanese [ Tue Jul 08, 2014 8:42 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

Looks interesting, great work Spider!! :clap: :clap:

Cheers :)

Tommaso
Author:  dudest [ Tue Jul 08, 2014 8:54 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

You got mad skillz bro!, good show :)
Author:  Eamonn [ Tue Jul 08, 2014 9:11 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

With the right settings this could be just what us mere retail traders need to have any chance of success,

thanks a lot team, oh and lets not forget that Dustin Pass is selling his ALR system for $ 1997.00



Eamonn.
Author:  Dewey McG [ Tue Jul 08, 2014 9:57 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

Great work Spider!

Just remember folks, this whole concept is still in the testing phase to see how viable it is. No matter how tempting don't try on a live account. Test it, experiment, try every combination you can think of and share results.
Author:  pips400 [ Tue Jul 08, 2014 10:26 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

Thank you sooooooooo much guys for all your effort on this project. You've reached a new horizon by pushing the boundaries of what can be done. Like other's I'll test this out on demo and feedback anything that may be useful :good:

:!!:
Author:  erikskenne [ Tue Jul 08, 2014 10:27 am ]
Post subject:  Trend Trading EA with Automated Loss Recovery

Fantastico :yahoo: :clap: :clap: :clap:
All times are UTC Page 1 of 14