Help with Max Trades

 

Hi,


I have a EA that I downloaded from a forum which backtests pretty well, it is a scalper with a small TP and much larger SL, when a buy position is opened and the market goes down it will open a sell position, the max opened positions is two, one buy and one sell, now I was trying to figure out how to add a code that would limit the number of trades to one at a time, so that I can run it with the new NFA rules of no hedging and FIFO.


(I added extern int MaxTrades = 1; but aside for that being a new input in the EX4 once compiled, it's still not limiting the amount of open trades).


I was wondering if anyone can please explain me what has to be done to get the max trades feature to work.


I am a total newbie to code.


Thanks a bunch.

 

This question is asked regularly.

Please search the forum before posting and you will find many posts on this subject.

Here's just one example.

'One Order Per Day'


CB

 

Put this test around the buy & sell conditions


if(OrdersTotal()<1){


Buy & Sell code


}

 

Thanks.


I was trying to put a parameter of "max trades" as one of the inputs which I did by adding extern int MaxTrades = 1; but I am wondering what to put i to have that take affect.

 

I am not sure if this has been answered, but I can see there were some attempts.

The extern int MaxOrders that you created are correct. As long as you put it near the top of the file with the other extern entries.

Now there is a body of code in the area marked start, everything that has an if condition ( a statement with "if" at the beginning). Usually there are many of them. Sometimes you will find it is the first major part of the document, that sets a condition, if xxx is true then do the following.

If statements are wrapped with () parens, the true and false conditions are wrapped with {}. the finished if condition might look like:

if (OrdersTotal() < MaxOrders)

{

We can take a trade here

}

else

{

We cannot take a trade

}

This if condition says if OrdersTotal() (this is the number of orders that are open) is less than MaxOrders, then do the stuff in the first set of curly braces, else it is not less than MaxOrders so do the stuff in the second set of curly braces below the word else

Now what you want to do is to just build the true part of the if statement. Trick is to figure out where. I can't help you much here because it will depend on the code in the file. You could send it to me and I could fix this MaxOrders for you. email: smsbvt(at)hotmail(dot)com.

But if you can fingure out where the buy statements are being made, you can place the if condition before the buy or sell with an open curly brace and then place a closing curly brace after the buy or sell order. Now the tool will only trade when this condition is true.

 

Thanks.


Sent E-mail.


1836.

 
Ruptor wrote >>

Put this test around the buy & sell conditions

if(OrdersTotal()<1){

Buy & Sell code

}

Hello friend,

I can be wrong, but I think the correct way to write your idea is:

if( !HasOpenOrder() )

and then:

bool HasOpenOrder()

{

for( int i = 0; i < OrdersTotal(); i++ )

if( OrderSelect(i, SELECT_BYPOS) && OrderCloseTime()==0) return (true);

return (false);

}

This is to skeep already closed orders, as OrdersTotal() also returns history.

[]´s,

Gero.

 
Gero.Gero wrote >>

Hello friend,

I can be wrong, but I think the correct way to write your idea is:

if( !HasOpenOrder() )

and then:

bool HasOpenOrder()

{

for( int i = 0; i < OrdersTotal(); i++ )

if( OrderSelect(i, SELECT_BYPOS) && OrderCloseTime()==0) return (true);

return (false);

}

This is to skeep already closed orders, as OrdersTotal() also returns history.

[]´s,

Gero.

Oops... SELECT_BY_POS, etc...

 
Paul:

Put this test around the buy & sell conditions


if(OrdersTotal()<1){


Buy & Sell code


}

Thanks a lot , very good help me

 
@signallineif(OrdersTotal()<1){
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
          Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
          MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
Reason: