Limit trading with orderhistory

 

Hello,

I'm trying to find a way to have my EA limit its trading after it gets a winner over a user defined threshold. I am using the following code

//----check for successful trade
for(cnt = OrdersTotal(); cnt >= 0; cnt--)
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)
{
if (TimeDayOfWeek(OrderCloseTime()) == TimeDayOfWeek(TimeCurrent()))
{
if (OrderProfit()/Point >= Int_Target)
{
Trade = false;
}
}
}
}
}

What I'm experiencing is that this will work only once on a global scale (no matter how many different pairs its running on) and then the EA will proceed as if the code didn't exist. The EA ignores this secion of code completely. Can anyone tell me why? I am trying to find a way to limit tne number of trades an EA takes by using this method. I would also eventually like to add the loss threshold too, so that if the EA trades a loss beyond a certain user defined threshold, it will stop trading. Can anyone help?

 

if (OrderProfit()/Point >= Int_Target)

That doesn't look good. Lets say $100 and EURUSD:

$100/0.0001 = $1000000.00

So, unless your target is a million bux, it will keep trading.

 
phy wrote >>

if (OrderProfit()/Point >= Int_Target)

That doesn't look good. Lets say $100 and EURUSD:

$100/0.0001 = $1000000.00

So, unless your target is a million bux, it will keep trading.

This was my way to determine the number of pips in each trade. Your math may be off a bit...$100/0.0001 = 0.0100 (or 100 pips), assuming a mini account. The problem is that this code DOES work...but only once PERIOD. If I have the EA on the GBP/USD & EUR/USD for example and both these pair make the user defined profit, ONLY one EA will shut down. The other keeps going as if the code didn't exist.

 

I do see an error in my reply, but it is not in the math.