Programming question - sleep after a loss trade.

 

Hi guys, I am working on promising EA, the problem is it required sleep function after loss trade and I dont know how to implement this. Any chance you can help with this.

Thanks

Aleks

 

Hi

What do you mean by "sleep"? It should work but don't trade or it shouldn't run at all? It may check time when starts and if the "sleep" time has not passed yet just return without doing anything.

wookey

 
wookey:
Hi

What do you mean by "sleep"? It should work but don't trade or it shouldn't run at all? It may check time when starts and if the "sleep" time has not passed yet just return without doing anything.

wookey

I mean the sleep () command/function or other function to stop trading (but still running) for example for 5 minutes after stop loss trade.

aleks

 
aleksd:
Hi guys, I am working on promising EA, the problem is it required sleep function after loss trade and I dont know how to implement this. Any chance you can help with this.

Thanks

Aleks

int MinutesToNextTrade = 5;

int orders=HistoryTotal();

OrderSelect(orders-1,SELECT_BY_POS,MODE_HISTORY);

if (OrderProfit()<0 && CurTime()-OrderOpenTime()<MinutesToNextTrade) return(0);

Try this... maybe it works...

Raff

 
raff1410:
int MinutesToNextTrade = 5;

int orders=HistoryTotal();

OrderSelect(orders-1,SELECT_BY_POS,MODE_HISTORY);

if (OrderProfit()<0 && CurTime()-OrderOpenTime()<MinutesToNextTrade) return(0);

Try this... maybe it works...

Raff

Hi RAff

Thanks for your help, but I cant get it to work, I try to past this in expert start function part of code, I also try to put this in Signal End part but still no effects. Can you tell me where I should place this code, I mean in which part of the EA code - sorry I'm really bad with programing

aleks

 
aleksd:
Hi RAff

Thanks for your help, but I cant get it to work, I try to past this in expert start function part of code, I also try to put this in Signal End part but still no effects. Can you tell me where I should place this code, I mean in which part of the EA code - sorry I'm really bad with programing

aleks

int MinutesToNextTrade = 5;

int orders=HistoryTotal();

OrderSelect(orders-1,SELECT_BY_POS,MODE_HISTORY);

if (OrderProfit()<0 && CurTime()-OrderOpenTime()<MinutesToNextTrade*60) return(0);

Hi, it should be placed at the beggining of "start" function...

Also there should be " *60 "... Sorry, my mistake...

Raff

 

Hi RAff

Thanks for all your help. Unfortunately I can get this code to work, maybe I am doing something wrong, the truth is that this is my first EA and I don’t have much experience with this sort of programming. The problem with this ea is very minor, from time to time it opens trades one after another in wrong direction, please see statement so you can understand what I am talking about. Apart of this it is really good especially as my first EA. I attached the code so maybe you can have a suggestion how I can solve my little problem.

regards

aleks

Files:
alx.gif  6 kb
alx.mq4  10 kb
 
 

Hi elihayun

I know the back test sucks but it is the only way to quickly optimize EA which I know. I do not really trust in this sort of testing in 100% but its the only way to find the weaknesses of EA in a short time.

In regards 10pips in one minute trade that's real when you have 2pips spread and the market is going strongly. As you can see from this statement very often the trade is close with 1,2 or 0 pips, the indicator is very sensitive (maybe too sensitive) and as you know even in strong trend you get weak moments and that's way you getting some 10pips trades closed in less than one minute.

Thanks for the code, could you please explain the purpose of it, how its working etc. I would like to learn little bit more about it so I dont have to ask you the same question again in future.

regards

aleks

 

this line just check if past half of the time from the starting of the period.

 
Reason: