Automatic Loss Recovery System (ALR) - read this first

Post your EA's using ALR here
Post Reply
ronkeous
Posts: 6
Joined: Wed Nov 12, 2014 8:26 pm

Automatic Loss Recovery System (ALR) - read this first

Post by ronkeous »

for your closing trades try using this... I never had any issues closing. try this

Code: Select all

void CloseAllTrades(bool CloseAll, int DontClose)
{
   if (CloseAll == false) return;  
	Alert (Symbol() + " Closing All Trades"); 

  for(int i=OrdersTotal();i>=0;i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    int type   = OrderType();
    bool result = false;

    if ( (OrderTicket() == DontClose) ||  (OrderSymbol() != Symbol())   )
    {
      result = true;  
      type = 999;
    }
    
    switch(type)
    {
      //Close opened long positions
      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                          break;
      
      //Close opened short positions
      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                          break;

      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
    }
    
    if(result == false)
    {
      Alert(Symbol() + " Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    }  
  }
  
  return;
}   

so your code should look like this
CloseAllTrades(true,902101321); note the 902101321 is just a value to pass.. if you know the ticket number it will close all trades except for that.
ronkeous
Posts: 6
Joined: Wed Nov 12, 2014 8:26 pm

Automatic Loss Recovery System (ALR) - read this first

Post by ronkeous »

macman » Fri Dec 05, 2014 4:27 am wrote:
TambaTrader wrote:I am about ready to give up on ALR. I thought the problem where it closes one side of the trades but not the other, was a problem with the fact my demo account was running on my laptop and not on my server.

It has just done it on my real account now though. That runs on my server. All the buys closed on Eurusd as it has just had a big movement up but the sells didn't. I was up to my 6th turn. I lost £90 which for my mini real account is a disaster. I'm only winning about a tenner a week when it goes well.

I like the Maths behind ALR but if you can't trust it will be executed properly the risk is too high.

Has anyone else had this problem?

I might not waste any more time on it and go back to using stop losses.

Yet another brick wall! That is so disappointing.
Do your logs give any indication as to why the operation failed?

As you already made 5 turns, it seems unlikely to be a software error.

Sorry to hear about the loss - 'things can only get better' as that well known song says :)

Best regards,

if your pending order fails because too close or maybe even gap try entering on Market. I use something like this...

Code: Select all


                     // Enter Pending trade
                     do
                        Trade[i] = OrderSend(Symbol(),OP_BUYSTOP ,ALZ_Lots[i],Zone_Upper,Slip,Zone_Lower_TP+Spread,Zone_TP_Price[i]+Spread,"ALZ Buy" ,MAGICMA,0,Lime); 
                     while(Trade[i] == 0);
         
                     //  if the Pending order can't be entered due to price being too close enter on Market Order
                     if (GetLastError() == 130) 
                     {
                        Trade[i] = OrderSend(Symbol(),OP_BUY ,ALZ_Lots[i],Ask,Slip,Zone_Lower_TP+Spread,Zone_TP_Price[i]+Spread,"ALZ Buy @ Market" ,MAGICMA,0,Lime); 
                     }


ronkeous
Posts: 6
Joined: Wed Nov 12, 2014 8:26 pm

Automatic Loss Recovery System (ALR) - read this first

Post by ronkeous »

i wish I could upload an image here to show you my initial analysis but here it is in text

eur/usd from Jan1 2014 to dec 2014

Initial Trade 90 Pips target

Zone 30 pips
Zone Take Profit 90

ZoneCount_X[1] : 4 : 0.14
ZoneCount_X[2] : 10 : 0.09
ZoneCount_X[3] : 3 : 0.12
ZoneCount_X[4] : 5 : 0.16
ZoneCount_X[5] : 4 : 0.21
ZoneCount_X[6] : 4 : 0.28
ZoneCount_X[8] : 4 : 0.51
ZoneCount_X[10] : 2 : 0.91
ZoneCount_X[12] : 1 : 1.61
ZoneCount_X[14] : 1 : 2.87
ZoneCount_X[15] : 1 : 3.82

the numbers in [] are the Zone trade count.. ie [3] means it took 3 zone trades (initial trade, 1st sell, 2nd buy, 3rd sell leg in order to hit Zone Take Profit to close all trades)

: 0.14 is the lot size used

during this time strategy to just by if currently no open orders with initial TP of 90 Pips... it only hit TP 5 times... all the rest was the ALR trades to try to get out at break even.

broker used has leverage of 400:1 so after 15 Lets the margin used to open all trades was about $1800.

I typically don't have much time to post or reply so it may take me a while to respond.

btw in some other test i think it went up to 19 trades

Ron
ronkeous
Posts: 6
Joined: Wed Nov 12, 2014 8:26 pm

Automatic Loss Recovery System (ALR) - read this first

Post by ronkeous »

ronkeous » Sat Dec 06, 2014 12:43 pm wrote:i wish I could upload an image here to show you my initial analysis but here it is in text

eur/usd from Jan1 2014 to dec 2014

Initial Trade 90 Pips target

Zone 30 pips
Zone Take Profit 90

ZoneCount_X[1] : 4 : 0.14
ZoneCount_X[2] : 10 : 0.09
ZoneCount_X[3] : 3 : 0.12
ZoneCount_X[4] : 5 : 0.16
ZoneCount_X[5] : 4 : 0.21
ZoneCount_X[6] : 4 : 0.28
ZoneCount_X[8] : 4 : 0.51
ZoneCount_X[10] : 2 : 0.91
ZoneCount_X[12] : 1 : 1.61
ZoneCount_X[14] : 1 : 2.87
ZoneCount_X[15] : 1 : 3.82

the numbers in [] are the Zone trade count.. ie [3] means it took 3 zone trades (initial trade, 1st sell, 2nd buy, 3rd sell leg in order to hit Zone Take Profit to close all trades)

: 0.14 is the lot size used

during this time strategy to just by if currently no open orders with initial TP of 90 Pips... it only hit TP 5 times... all the rest was the ALR trades to try to get out at break even.

broker used has leverage of 400:1 so after 15 Lets the margin used to open all trades was about $1800.

I typically don't have much time to post or reply so it may take me a while to respond.

btw in some other test i think it went up to 19 trades

Ron
i figured it out :yahoo: feeling pretty dumb that I didn't figure this out earlier :arrrg:
You do not have the required permissions to view the files attached to this post.
User avatar
macman
Trader
Posts: 118
Joined: Tue Nov 15, 2011 7:47 pm
Location: Somewhere on a European waterway, on my classic (old) Dutch barge

Automatic Loss Recovery System (ALR) - read this first

Post by macman »

ronkeous wrote:
ronkeous » Sat Dec 06, 2014 12:43 pm wrote:i wish I could upload an image here to show you my initial analysis but here it is in text

eur/usd from Jan1 2014 to dec 2014

Initial Trade 90 Pips target

Zone 30 pips
Zone Take Profit 90

ZoneCount_X[1] : 4 : 0.14
ZoneCount_X[2] : 10 : 0.09
ZoneCount_X[3] : 3 : 0.12
ZoneCount_X[4] : 5 : 0.16
ZoneCount_X[5] : 4 : 0.21
ZoneCount_X[6] : 4 : 0.28
ZoneCount_X[8] : 4 : 0.51
ZoneCount_X[10] : 2 : 0.91
ZoneCount_X[12] : 1 : 1.61
ZoneCount_X[14] : 1 : 2.87
ZoneCount_X[15] : 1 : 3.82

the numbers in [] are the Zone trade count.. ie [3] means it took 3 zone trades (initial trade, 1st sell, 2nd buy, 3rd sell leg in order to hit Zone Take Profit to close all trades)

: 0.14 is the lot size used

during this time strategy to just by if currently no open orders with initial TP of 90 Pips... it only hit TP 5 times... all the rest was the ALR trades to try to get out at break even.

broker used has leverage of 400:1 so after 15 Lets the margin used to open all trades was about $1800.

I typically don't have much time to post or reply so it may take me a while to respond.

btw in some other test i think it went up to 19 trades

Ron
i figured it out :yahoo: feeling pretty dumb that I didn't figure this out earlier :arrrg:
Thanks for the interesting posts.

ALR is an interesting concept for sure BUT to be of any real use the code of any EA needs to be 100% bullet proof, or at least able to warn users it is no longer functioning correctly. My own earlier post details how an ALR EA got stuck in a loop.

This opens up the can of worms that is the current state of Empty4/5 right now.

My own programming skills are not good enough to attempt this, so for now ALR is still a proof of concept for me.

Best regards,

Macman
This account takes ALL software generated trade calls from my FXW training course and is used to develop money management routines.
http://www.mt4i.com/mt4ichart.aspx?c=ch ... udent-demo
ronkeous
Posts: 6
Joined: Wed Nov 12, 2014 8:26 pm

Automatic Loss Recovery System (ALR) - read this first

Post by ronkeous »

i can see you getting issues if you lost the zone count and you need to start from the start again. Trt having a label to display the current zone count.


i am not 100% sure but if you change timeframes your variable might reset... depends on your int OnInit() and OnDeinit() functions on your ea.

try playing around with golbal variables so your count or varables remain the same.


string MaxTradesAllowed = "MaxTradesAllowed"; // Global settings for all pairs
GlobalVariableSet("MaxTradesAllowed",7);

GlobalVariableGet(MaxTradesAllowed);

Set("MaxTradesAllowed",7);


say you need to reboot the computer or clost Empty4 then try external variables to re-initialize your Zone count or zone levels.

so default would be 0 to let the program set it, but if not 0 then use the override settings.

hope that helps your cause.

Ron
Jack1

Automatic Loss Recovery System (ALR) - read this first

Post by Jack1 »

Empty4 close order function often fail, due to unknown reasons, may be brokers side servers.

ALR big threat is a failure to open/close orders when market is volatile or price change fast, and your EA have to run 24/5 mode on a reliable cloud environment.

Another issue is fixed target or recovery zone size. Dynamically size down (or scale down) recovery zone size to quickly bail out ALR processing may be needed for avoid of a stuck in the zone.

see my attached xls
You do not have the required permissions to view the files attached to this post.
TambaTrader
Trader
Posts: 51
Joined: Sat Jun 28, 2014 5:27 am

Automatic Loss Recovery System (ALR) - read this first

Post by TambaTrader »

ronkeous » Sat Dec 06, 2014 8:05 pm wrote:i am not 100% sure but if you change timeframes your variable might reset... depends on your int OnInit() and OnDeinit() functions
I have been changing timeframes on the chart that is running the EA so if that can cause problems that may have happened on mine.

I remember reading somewhere on this thread/forum about a version of ALR where you have stop losses so as to keep the lot size down. I am going to test that next I think. In my opinion the maths seems good for ALR but having so many trades open at such large lot sizes isn't good. In theory they are hedging and the net lot size isn't high. In reality something could go wrong.

There is more than one benefit to closing each trade before starting a new one.

1. Can keep lot sizes smaller as discussed already
2. No risk of one side of trades closing leaving you exposed
3. Results of each trade are independent from each other so if market is ranging and not hitting your take profit you can wait a few days/ weeks and finish off the ALR later when it's trending again. Or you can move to a completely different currency pair if you want.

Do you think point 3 is correct or is it just like a martingale then? Point 3 would mean you don't even need an EA you could just have your excel with the maths worked out and trade manually if you wanted.

Shona
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Automatic Loss Recovery System (ALR) - read this first

Post by Radar »

Hey Shona
TambaTrader » Sun Dec 07, 2014 5:34 pm wrote:
I have been changing timeframes on the chart that is running the EA so if that can cause problems that may have happened on mine.

I remember reading somewhere on this thread/forum about a version of ALR where you have stop losses so as to keep the lot size down. I am going to test that next I think. In my opinion the maths seems good for ALR but having so many trades open at such large lot sizes isn't good. In theory they are hedging and the net lot size isn't high. In reality something could go wrong.

There is more than one benefit to closing each trade before starting a new one.

1. Can keep lot sizes smaller as discussed already
2. No risk of one side of trades closing leaving you exposed
3. Results of each trade are independent from each other so if market is ranging and not hitting your take profit you can wait a few days/ weeks and finish off the ALR later when it's trending again. Or you can move to a completely different currency pair if you want.

Do you think point 3 is correct or is it just like a martingale then? Point 3 would mean you don't even need an EA you could just have your excel with the maths worked out and trade manually if you wanted.

Shona
Check out SpiderX's http://www.stevehopwoodforex.com/phpBB3 ... =81&t=3792

That system doesn't hedge, just closes out, and calculates the next lot-size, then enters in the opposite direction.

A few months ago, I had written a basket trader that incorporated ALR, using GlobalVariables to store all info needed in case of a restart/reboot, but I didn't like the death-runs, (and they always come eventually), so I threw it away :( Shame about that, 'cos a few days ago, I realized that if I just used ALR to recalculate the lot-size, then waited for a normal entry signal, I'd avoid the death-runs, (well, as long as my system had a good win/loss ratio in the first place).

As for whether ALR is a martingale, well, yeah, it is... It's just that we're increasing our risk by much smaller increments than with the standard martingale.

Have fun!

Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
ronkeous
Posts: 6
Joined: Wed Nov 12, 2014 8:26 pm

Automatic Loss Recovery System (ALR) - read this first

Post by ronkeous »

Here is an interesting stat that you might want to consider.

Leverage 400:1
0.01 Lots = $0.10 or 10 cents per Pip
30 Pip Zone and 90 Pip Take Profit

Total Margin and Drawdown @ 21 Zone Trades before it exit everything at Break Even is about $6600.00
Just something to consider when assessing potential risk.

I know that most people will argue that their strategy will not encounter this (especially if they are playing breakouts) however I don’t have such a good strategy so I just need to be aware of that and ensure that I am well funded for the hard times.

Happy Trading
Ron
Post Reply

Return to “Automated Loss Recovery”