Stop trading after losses

 
I'm trying to figure out how to get my EA to sleep for X amount of time after it has made N number of losses and then continue to trade as usual when it wakes up. Can anyone help me with this coding?
 
I would count each time it closed for a loss, put that in a global variable, check that variable each tic and sleep(x) when var reaches your max losses..
You may have to run through your history to find the closed orders and see what profit they made,
Set your terminal history for "last three days" (shouldn't use "today" ,.... might roll over and miss one)
You might want to play with this to insure your trades are not gone from history before your max losses occur... ie, you lost one tuesday, one wednesday and one saturday... if you had last three days history only, then you would only retrieve one trade...

for instance (and i am rough in this, bare with me)

int losses,maxlosses,h,history;
int x =milliseconds to sleep;
int init() {
history=HistoryTotal();
GlobalVariableSet("history",history); //// we reset these each time we start the ea.
GlobalVariableSet("losses",0); //// We now know how many we have in history presently
}

init start() {

h=HistoryTotal();
history=GlobalVariableGet("history",history); // we need to get this each tic
if(h>history) { ///// we have a new addition to history, lets check if a loss. ....
GlobalVariableGet("losses", losses);
OrderSelect(h-1, SELECT_BY_POS, MODE_HISTORY);
if(OrderProfit() < 0) {
losses++;
GlobalVariableSet("losses", losses);
if(losses>maxlosses) {
GlobalVariableSet("losses", 0); /// we found the number we were looking for so we reset this
///for next time
sleep(x);
}
}

GlobalVariableSet("history",h); /// reset the history to current trades when it wakes up.
}

} //// end of this little messed up script. I would not use it until someone a little more knowledgeable in this remarks on it... shouldn't be too long.
 
oldman, Thanks for your help. I'll be waiting to see what others have to suggest.
 
It appears from trial and error that historytotal() -1 is the last order closed. . for some reason.
I modified the script above to reflect that.
 

Hopefully this might be something useful. I know that you are wanting it to wait for so long after "multiple losses," but the way we do it is to have it wait after a single loss. And the wait time can easily be optimized because it is based on the candles drawn.

First:
extern int Shift = 1;


Then:
WaitTime=iTime(NULL,0,Shift);

Finally:

total=OrdersTotal();
if(total>=1 && OrderProfit()<0)
{
CloseTime=iTime(NULL,0,0);
}
if(total<1 && WaitTime<=CloseTime)
{
Pause=true;
}
else
{
Pause=false;
}


Basically, it assigns "shift" as a variable. Then, you can optimize how small-large you want the "shift" to be. we did this because we found that a lot of times after a full stop-loss trade, it would end up opening another trade that would lose. This way, after any loss it forces the EA to wait however long "shift" is set for. And the shift is the number of candles. Basically, if you have a shift of 2 and you are attached to a 30minute chart, it would wait for 2 full candles to process before it started to look at options for opening a positions. In the very least, hope this might be able to help in some manner.

 
milchbubi:

hi,


i'm new here and i have a little problem.

my ea, using MA, MACD and ADX, is like a little baby. sometimes good, sometimes not.

backtesting with "each tick-mode" from 2006 in 1 hour bars looks - hmmm.... 55% plus.

but first go up from 100k to over 250k, then down to 80k up to 155k (now).

its not so good. (155 is good but the down is very, very bad - i do my best on it next time)

but my problem is understand mql and all this i made with ea builder.

vars and bools are not the problem because i learned telecommunications-electric many years ago.

so, now i write so much and it's time for my problem.

sometimes my ea open & close so many positions in 1 bar - i don't want it.

i want that my EA, when a signal for open comes in any bar > Open and, here is the problem, after Close : WAIT til next bar.

today i found that i can't use sleep in backtesting so, what's your idea about a timer or anything else til next bar open?


thanks for helping me.

thorsten

 

> then continue to trade as usual when it wakes up

Having maybe missed some winning trades...?

Always better to determine a strategy for identifying adverse circumstances and simply stop trading for that period...

-BB-

Reason: