re-thought
I see I was making a stuff-up, all one doesn't have to count the closed orders, as they are wrapped up in the accountbalance or accountequity. So the calc is far more simple, maybe this is right.
bool IsProfitforDayReached()
{
//Got to get this function to see the new Day
static int totalPips = 0;
static double totalProfits = 0.0;
static double currentBal
if newday()
{
totalPips = 0;
totalProfits = 0.0;
currentBal = AccountEquity();
}
if((AccountEquity()-currentBal)/currentBal>0.05)
{
return(true);
}
else
{
return(false);
}
}
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I am working on a function to determine whether an ea has hit is daily profit target, but I am unsure if I am doing this right. Specifically when I check the closed orders. All my orders open up as pending orders, does a pending order's ordertype convert from OP_BUYSTOP to OP_BUY when the stop is reached and the order is executed?
Please check my function - if you have a better way please let me know
bool IsProfitforDayReached()
{
//Got to get this function to see the new Day
static int totalPips = 0;
static double totalProfits = 0.0;
static double currentBal
if newday()
{
totalPips = 0;
totalProfits = 0.0;
currentBal = AccountBalance();
}
int orders = OrdersTotal();
//check is there is an existing order
for(int i=orders-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGICMA) continue;
switch (OrderType())
{
case OP_BUY:
totalPips += (Bid-OrderOpenPrice())/Point;
totalProfits += OrderProfit();
break;
case OP_SELL:
totalPips += (OrderOpenPrice()-Ask)/Point;
totalProfits += OrderProfit();
break;
}
}
for(int i=orders-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGICMA) continue;
//check that the order was opened and closed today
if (OrderOpenTime()<TimeToStr(CurTime(),TIME_DATE)) continue;
switch (OrderType())
{
case OP_BUY:
totalPips += (OrderClosePrice-OrderOpenPrice())/Point;
totalProfits += OrderProfit();
break;
case OP_SELL:
totalPips += (OrderOpenPrice()-OrderOpenPrice)/Point;
totalProfits += OrderProfit();
break;
}
}
if(totalProfits/currentBal>0.05)
{
return(true);
}
else
{
return(false);
}
}
////////////////////
bool newday()
{
//Returns true if it is a new Day
int lastVal;
int curretVal;
//We have the current value
currentVal = Day();
//Get the previous value
gvname = "newday"
gvvalue = Day();
if(GlobalVariableCheck(gvname))
{
lastVal = GlobalVariableGet(gvname);
}
else
{
//there was no previous value so set up a previous value and return true so things can start
GlobalVariableSet(gvname,gvvalue);
return(true);
}
if (lastVal!=currentVal)
{
return(true);
GlobalVariableSet(gvname,gvvalue);
}
else
{
return(false);
}
}