Hi, I have a formula that calculates the ATR of a certain period and if ATR is too high i would like to check if my open orders are in profit or not. If they are in profit I will do nothing if they are negative I want to close my open order for that pair ( I trade forex). I already have the ATR and close orders function.
Thanks
Lucas,
here is a function I use, you can tweak it as per your needs.
double TotalBuyProfit()
{
int total=0;
double orderProfit =0;
double orderGross = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==magic)
if(OrderType()==OP_BUY)
orderProfit = orderProfit +OrderProfit();
total++;
}
else
Print(__FUNCTION__,"Failed to select order ",i," ",GetLastError());
}
return (orderProfit);
}
How to check open orders
There are no open orders in MT5. Orders become positions.
Why are you posting MT4 code in the Root / MT5 General section
There are no open orders in MT5. Orders become positions.
Why are you posting MT4 code in the Root / MT5 General section
Sorry, I didnnt notice
Lucas,
here is a function I use, you can tweak it as per your needs.
double TotalBuyProfit()
{
int total=0;
double orderProfit =0;
double orderGross = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==magic)
if(OrderType()==OP_BUY)
orderProfit = orderProfit +OrderProfit();
total++;
}
else
Print(__FUNCTION__,"Failed to select order ",i," ",GetLastError());
}
return (orderProfit);
}
Thanks a lot, I will try
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I have a formula that calculates the ATR of a certain period and if ATR is too high i would like to check if my open orders are in profit or not. If they are in profit I will do nothing if they are negative I want to close my open order for that pair ( I trade forex). I already have the ATR and close orders function.
Thanks