Hundreds of pending orders every day - little help with my EA

 

Hello,

I have been trying to program my own EA. Since I have been programming only for a month or so, I cant figure out, what Im doing wrong. Its a very simple EA, which should detect a candlestick pattern "hammer" and put a pending order with 1 day expiration. It already works as an indicator and puts text and arrows above and under "hammers". The EA doesnt give me any errors, but when I try to run it, it opens hundreds of pending orders every day. I have spent 2 days trying to figure out, how to solve this, but my programming skills are just too weak. I would really appreciate, if someone could take a look at it. Its a really short EA and wont take you more than a few minutes. Thanks a lot

Files:
help.mq4  7 kb
 

Hi

The file you posted is an indicator. The usual cause of multiple trades is that you keep executing a new trade while the condition is present. You must either put a boolean switch on the condition so if it has been done once it gets blocked until the condition has cleared or only trade on each new candle not every tick.

 
Ruptor:

Hi

The file you posted is an indicator. The usual cause of multiple trades is that you keep executing a new trade while the condition is present. You must either put a boolean switch on the condition so if it has been done once it gets blocked until the condition has cleared or only trade on each new candle not every tick.


Hi .. thx for reply ... yeah, you are right.... I ve created the EA from an indicator. I just added some OrderSends ... I figured out that it kept executing trades, because the condition was present with every new tick, so I added another condition - that it has to be 00:00 pm to execute the order, but it didnt work :) ... any other time didnt give me any trades at all and midnight didnt change the result - I still had too many trades... I will look at more EAs and try that boolean switch...

 

The line:

expiration = CurTime()+ PERIOD_D1;


CurTime is in SECONDS unit
Period_D1 is MINUTES unit

so you might want to do expiration = CurTime() + PERIOD_D1*60;

the way you have been doing has made all of your expirations 60 times less than what they should have been
 
eacoder:

The line:

expiration = CurTime()+ PERIOD_D1;

Thanks ... I have already corrected it today........ But that is not the main problem of the EA. It still keeps opening new trades with every tick. I need to open new trades only on new candles. Only once a day... I know its maybe a silly problem, but it is still out of my powers :)

 
That would be because once there is a tick meeting your trading rules, most likely many other ticks right after will also meet those rules. You can solve this by keeping a separate variable to record how many candles there were since your last trade, and only execute a new trade if # of candles is now different.
 

Hi

Use this to trade once per candle.


if (timeold!=Time[0]){
timeold=Time[0];

Put condition to trade here-----------

}

 
Ruptor:

Hi

Use this to trade once per candle.


if (timeold!=Time[0]){
timeold=Time[0];

Put condition to trade here-----------

}


Works great ... thats exactly, what I needed .... thx a lot ;-)

Reason: