| / | Forum |
|
sasuke
2006.10.23 21:24
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?
|
|
Ten Basic Errors of a Newcomer in Trading There are ten basic errors of a newcomer intrading: trading at market opening, undue hurry in taking profit, adding of lots in a losing position, closing positions starting with the best one, revenge, the most preferable positions, trading by the principle of 'bought for ever', closing of a profitable strategic position on the first day, closing of a position when alerted to open an opposite position, doubts. |
|
oldman
2006.10.25 09:17
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. |
|
sasuke
2006.10.25 19:53
oldman, Thanks for your help. I'll be waiting to see what others have to suggest.
|
|
oldman
2006.10.25 23:28
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. |
|
asmocon
2006.10.31 00:10
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. |
|
milchbubi
2010.11.25 22:36
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 |
|
Wooopa
2011.11.01 16:24
asmocon: 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. |
|
Wooopa
2011.11.01 16:25
This is exactly what I've been trying to add to my EA but I'm getting a load of errors...'Global Scope not allowed'...any idea how I can fix this. Thanks for you help. David. |
|
Wooopa
2011.11.01 16:26
sasuke: Did you ever find a solution?
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? |
1935 |
BarrowBoy
2011.11.01 16:55
> 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- |