I am struggling to get an EA to stop trading once it makes profit for the month.
So basically I need the EA to stop trading for the month that it makes the first profit order in, then when the next month arrives it continues to make trades.
Here is roughly what I have used:
for (int i = 0; i<=OrdersTotal();i++)
{
OrderSelect(i-1,SELECT_BY_POSITION,MODE_TRADES);
if (type <= OP_SELL blah blah..)
{
if order is a buy order
{
if (OrderProfit() > 0) // check that order made a profit
{
if (TimeMonth(OrderCloseTime()) == TimeMonth(TimeCurrent()))
// check to see if the profit order closed in
the current month
{
buymadeprofit = true; // as it did, it is true.
}
}
}
}
}
if (buymadeprofit == false)
{
// Trade criteria goes here because order profit was not made
in the same month as present month
}
I have tried using static bool, plain bool, custom function, tried using static int instead of bool, and normal int.
All that happens is it will make a profitable trade and then it will never trade again. It is like once buymadeprofit is trigerred it stays triggered and doesnt re-set to 0 or false, even if I place that code outside of the function.
If anyone has any ideas or knows what im doing wrong it wud be very appreciated. Thanks.
So basically I need the EA to stop trading for the month that it makes the first profit order in, then when the next month arrives it continues to make trades.
Here is roughly what I have used:
for (int i = 0; i<=OrdersTotal();i++)
{
OrderSelect(i-1,SELECT_BY_POSITION,MODE_TRADES);
if (type <= OP_SELL blah blah..)
{
if order is a buy order
{
if (OrderProfit() > 0) // check that order made a profit
{
if (TimeMonth(OrderCloseTime()) == TimeMonth(TimeCurrent()))
// check to see if the profit order closed in
the current month
{
buymadeprofit = true; // as it did, it is true.
}
}
}
}
}
if (buymadeprofit == false)
{
// Trade criteria goes here because order profit was not made
in the same month as present month
}
I have tried using static bool, plain bool, custom function, tried using static int instead of bool, and normal int.
All that happens is it will make a profitable trade and then it will never trade again. It is like once buymadeprofit is trigerred it stays triggered and doesnt re-set to 0 or false, even if I place that code outside of the function.
If anyone has any ideas or knows what im doing wrong it wud be very appreciated. Thanks.