EA Opening Too Many Trades

 

Hello all, first of all I've searched this site for an answer to my question and not found a clear answer.

I'm using Expert Advisor Builder for Meta Trader 4 Expert Advisor Builder for MetaTrader 4 to create an EA. The problem I have is that the EA opens a trade whenever:

A. the defined rules for opening a trade at the beginning of a new bar (ex. 1 hour) are true.

AND

B. if a trade opened as a result of the above has closed, and the defining bar (ex. 1 hour) is still active.

I'd like to know how to script or define additional rules so the EA will not continually open trades, within the same bar, if a trade had already been opened based upon the rules. I guess another way to state it is how do limit the EA to opening no more than one trade per hour or defined time frame or bar.

Thanks in advance to anyone who can offer a clear concise solution.

 

Hourly Magic

There are many way to do it .. but the simplest way to limit 1 trade per hour is to use ..

int Fixed = 100;

int MagicNumber = Fixed + Hour();

and check for orders with that magic no. before sending new orders.

regards.

 

extern double TakeProfit=10;

extern double StopLoss=10;

extern MagicNumber=772188;

datetime Stamp=0;

int start()

{

double MA1=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0);

double MA2=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);

double MA3=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,1);

double MA4=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);

// MA crossed

if(MA1>MA2 && MA3<MA4 && Stamp!=iTime(NULL,0,0))

{

result=OrderSend(OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,NULL,MagicNumber,0,Red)

if(result>1)

Stamp=iTime(NULL,0,0);

return(0);

}

}

The Stamp will limit you 1 trade / bar. Hope this help.

Regards,

David

 
davidke20:
The Stamp will limit you 1 trade / bar.

.. as long as the MT4 is not restarted.

 
auto:
.. as long as the MT4 is not restarted.

Yes. MT4 restart may cause it to fire up another trade if it happened within the same hour. However, this can avoid complication of having different magic number every hour. Such as:

Magic + 13 hour = 18000 + 13 = 18013

If current hour is 14:00, magic number had automatically changed to 18014. Trailing stop not function until next day's 13:00. No worries, this is not a debate. May be you prefer changing magic number.

Regards,

David

 

I've tried adding this but it fails to limit. I've added the three sperate portions correctly as followed.

datetime Stamp=60; (note:placed under the input parameters)

if(sto2>sto1&&sto4>sto3&&Stamp!=iTime(NULL,60,0)){ (proper spot)

if(isCrossed == 1) //Go to Buy

{ Lots=FRisk_MM(Account_Type,(Exposure/100));

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"stocEA1.2 orig",53,0,Blue);

if(ticket>1)

Stamp=iTime(NULL,60,0);

if(ticket>1)

{

Note:pasted into the ordersend and all compiles nicely but still allows. Any thoughts?

 
fretwell_2000@yahoo.com:
I've tried adding this but it fails to limit. I've added the three sperate portions correctly as followed.

datetime Stamp=60; (note:placed under the input parameters)

if(sto2>sto1&&sto4>sto3&&Stamp!=iTime(NULL,60,0)){ (proper spot)

if(isCrossed == 1) //Go to Buy

{ Lots=FRisk_MM(Account_Type,(Exposure/100));

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"stocEA1.2 orig",53,0,Blue);

if(ticket>1)

Stamp=iTime(NULL,60,0);

if(ticket>1)

{

Note:pasted into the ordersend and all compiles nicely but still allows. Any thoughts?

try:

if(ticket>0)

{

Stamp=iTime(NULL,60,0);

//other code in case of success goes here

return;

}
 

Multi buy/sell stop orders

Hi Guys,

Hi, sorry for my english but this is my first post... i've been watching the threads for a while now and i have a request that i wish you can help me for...

i'm looking for an ea that would post multi buy/sell stop at once... let me give you an example:

lets say that i prodect that the price would move 300 to 400 pip through the whole month (1D or any other time frame) time frame but in the same time i'm not happy/sure about my information...!!... to maximize my profit and to be in win win setuation, i would place a (take profit point, (price or pips from current market price) and i would place a buy or sell stop in every 25-50 pip all the way to take profit point (in both directions)...

so my parameters would be:

- Lot size:

- Take profit point (pips from the current market price) which i think would work in both ways (buy/sell stop) better

- spread pips between each deal to another in the same direction.

- when take profit/ target reached then all other pending deals will be automatically cancelled/deleted.

* it would be nice if it would be like on the chart (drag and drop) and the ea would be activated on first price movement.

* another "Close" option to close all trades at once same as the drag and drop) and the ea would be activated on first price movement.

* i would appreciate if it would work in both 4digit and 5digit broker...

I attached an ea that might clear the idea a little...

i know that i'm asking for a lot, but This would be somtething greate

Thank you

Thamer

Files:
Reason: