Trend Trading EA with Automated Loss Recovery

Post your EA's using ALR here
Post Reply
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Trend Trading EA with Automated Loss Recovery

Post by SpiderX »

Dewey McG » Sun Jul 13, 2014 8:50 pm wrote:
I get history using tickstory and my tests show 0 mismatched chart errors--would there still be issues as you described?

Technically no....unless there is a crazy gap which hits one end of the ALR and gaps the other end.
Btw, the system does not cater for gaps, not sure how to handle them too.
How is the testing with the new version ?

Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Trend Trading EA with Automated Loss Recovery

Post by Dewey McG »

I just did another backtest with the new version and it works just the way it is supposed to. Good job!

I used the EURCHF because I figured this would be a terrible pair to use this strategy with since it ranges so much. The most turns it hit was 11. It shows no mismatched chart errors

I will download some data from more volatile pairs and test those later, but it looks now as if the EA is working fine.

The big dip you see on the back test chart is where the 11 turns happened and the losses were counted in before the TP's. The series of trades ended up with a small profit.
You do not have the required permissions to view the files attached to this post.
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Trend Trading EA with Automated Loss Recovery

Post by SpiderX »

theforexedge » Sun Jul 13, 2014 3:51 pm wrote: SpiderX

Can you post the code as well? as its always good to learn from the code changes :yahoo:

Thanks, JP
Sure why not.

There was some bug with the InitializeALRPositions() which somehow the first position in the ALR cannot be found. This results in an ALR setting with 0 lots and 0.00 price.

Code: Select all

datetime opendate= TimeCurrent();
changed to

Code: Select all

datetime opendate= 0;

Code: Select all

if(currentOrderType == OP_BUY || currentOrderType == OP_SELL)
         if(OrderOpenTime()< opendate)
changed to

Code: Select all

if(currentOrderType == OP_BUY || currentOrderType == OP_SELL)
         if((OrderOpenTime()< opendate)||(opendate ==0))
My original line of thought was that the new order should be earlier than TimeCurrent()...but apparently it is not.
So to avoid messing around, code was updated to a safer alternative.


Second change:
Created new function NormalizeLotsUp..this rounds up the Lot size to the next lot step instead of rounding down of NormalizeLots.
In this manner, the last position of the ALR is always "a bit more" than the theoretical position size.
In the case of rounding down, there is some possibility the series may close with a small loss.

Code: Select all

double NormalizeLotsUp(double lots)
{
   if(MathAbs(lots)==0.0) return(0.0); 
   
   int TotalSteps = (int)(MathCeil(lots / LotStep));
   
   double LotSize = TotalSteps * LotStep;
   
   if (LotSize < MinLot) LotSize = MinLot;
   if (LotSize > MaxLot) LotSize = MaxLot; 
   
   return LotSize; 

}
Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Trend Trading EA with Automated Loss Recovery

Post by SpiderX »

moncsicsi78 » Sun Jul 13, 2014 4:44 pm wrote:This ALR strategy is not good...
And it would be better to build an EA which can only open trades in the direction of the trend (buy stop and sell stop orders), with decreasing lot size (this is the rule of building pyramide trades), and use a trailing stop before every new level triggering.
If a new level is triggered, but before trailing stop is activated, and the price turns against us, at this point should start an "ALR mode"!
BUT!
If the price is breaking out form ALR zone in any direction, the EA should start to open pyramid orders in that direction with the rules mentioned above.

But the rules of ALR should be:
- adjustable lot multiplier
- adjustable SL, TP and ALR zone size, etc.
Hi,

Could sort of understand what you are trying to get at...but the idea seems complicated unless you simplify it.
Maybe it is good, if you can demonstrate some example and explain further on how this is better than the existing system.

Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
Haggadah
Trader
Posts: 154
Joined: Sat Dec 03, 2011 12:01 pm

Trend Trading EA with Automated Loss Recovery

Post by Haggadah »

SpiderX,

Is it possible to have Basket Version with a loss recovery to kick in when overall dd reach xx percentage.

God Bless,

Haggadah


_____________________________________________________________________________________________


“The Lord bless you and keep you; The Lord make His face shine upon you, And be gracious to you; The Lord lift up His countenance upon you, And give you peace.” Num 6:24-26
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Trend Trading EA with Automated Loss Recovery

Post by Dewey McG »

Folks it would help if more people did some testing and gave feedback on what we are working with before asking for umpteen different variations. There is nothing wrong with suggestions that might improve this but we did ask for some help testing what we have already
moncsicsi78
Posts: 9
Joined: Sat Oct 12, 2013 9:56 am

Trend Trading EA with Automated Loss Recovery

Post by moncsicsi78 »

Hi,

Could sort of understand what you are trying to get at...but the idea seems complicated unless you simplify it.
Maybe it is good, if you can demonstrate some example and explain further on how this is better than the existing system.

Cheers
I try to explain in another way.

The 1st part of my idea
:
Imagine a EA whose main startegy is opne only stop orders i the direction of the trend.
Te EA should put some buy stops and some sell stops in the begining, and when one of them activated, for example the first buy stop, at this moment the EA should delete all stop orders.
The price goes up.
Before the second buy stop would be triggered, a trailing stop should be activated to save our first buy order which is already in some profit.
The price still goes up. Our 3rd buy is activated too, but before it, the trailing stop of our 2nd order is acteivated too, in order to save 2nd buy order.

So we have 2 buy order opened, and they are saved buy trailing stop, they will never go in minus.
And we have a 3rd buy position.

BUT!

Price starts to turn down before our 3rd trailing stop would have been activated!

And that is the moment when this "ALR strategy " should work.
So the 3rd buy position would be the 1st order of the ALR strategy.

Tha ALR is working: open sell order if the price contiues to go down, and open another buy positions (at the same level of our 3rd buy or at the same level of our ALR's 1st order).

The 2nd part of my idea is:
Suppose that the price after triggering ALR's sell level, still goes down. If it will continue goes down, the EA can close everything in profit. But depending our setting, this down movement should be more ...
But try to imagine what happened if we try to build pyramides with sell stop orders!
These sell stop orders should have been saved trailing stops in the case the would go up again, like the buy stop orders was in the begining.

And we just have to close (with trailing stop) the sell pyramide trades, not the ALR sell trade.
If the price goes down again (because it doesn't managed to close with the ALR strategy) the EA should start to put another sell stops....

And so on.

In fact all this is almost the same as your great EA, just not with grid-against-the trend (and then use ALR), but grid-with-the trend (and use ALR).

I hope it is clear enough - sorry, Englus is not my native language!

If the
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Trend Trading EA with Automated Loss Recovery

Post by Dewey McG »

I tested the GY and there are more bugs. Some of the series close for small losses instead of a small profit. I am not as concerned about those, but there is a huge loss when you get to 11 turns. There are also rogue SL's that close early and not with the series.

I have another question. I know you set this to H only, but does the EA respond when price hits the ALR point or at close of bar? It should be when price does.
You do not have the required permissions to view the files attached to this post.
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Trend Trading EA with Automated Loss Recovery

Post by SpiderX »

Hi Dewey

Can you check two things ?
1. Was the order filled at correct price ?
A gap could seriously mess things up.

2. Can you check the lots sizes and settings with your spread sheet ?
The formula used is the same as there.
The only update needed is to round up to the next lot step for each stage.
Please include a new variable min lotstep.

Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Trend Trading EA with Automated Loss Recovery

Post by SpiderX »

Hi Dewey,

Just had a look at the 3 pictures you posted.
This is my response.

1. Yes. This is strange. The same question can be asked...why is it the tp for the first trade was not hit , when the sl for the second is triggered ?
Could it due to spread issue ? , i.e Ask hit the sl, but bid did not touch the tp...or something of that sort.
You might have to zoom into the chart to scrutinize this.

2. Could it be due to a gap ?
Yes...it would be a crazy gap.
An additional note, once a buystop,sellstop, tp, sl is set...it is beyond the control of the EA.
if a buystop, sellstop, tp, sl is not correctly triggered...either the price was set wrong, or there was an error in the execution.
We have to distinguish between those two.

3. This could either be due to
1. wrong lot size or
2. one of the orders in the chain did not get filled correctly due to a gap in prices.
Could you check if it is (2) first ?

Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
Post Reply

Return to “Automated Loss Recovery”