- Why did you post here and not in the MQ4 section?
- for(int i=0; i<OrdersHistoryTotal();i++){What happens when OrderSelect loop doesn't find any order?
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
OProfit = OrderProfit();
OType = OrderType();
OLot = OrderLots();
} - What happens when OrderSelect loop finds a deleted order?
- You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
- Profit is profit + commission + swap
- if(OrdersTotal()==0)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 forum
- "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
- Print out your variables, and find out why.
zaharulrizal:
Why do you use break instead of continue in OrderSelect statement?
Hi all,
I'm having problem on the equation which will be one of the condition to my code. As you can see on my code below. I was trying to used counter "n" as a condition to my code. "n" can be n=n+3, n=n+2 and n=n-1 depend on the condition as below. But this equation seem not work at all. Please help me to solve this problem. Thanks.
int CheckForTrade()
{
//------------------ Check OrderType in History
for(int i=0; i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
{
//------------------ Check OrderType in History
for(int i=0; i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
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 all,
I'm having problem on the equation which will be one of the condition to my code. As you can see on my code below. I was trying to used counter "n" as a condition to my code. "n" can be n=n+3, n=n+2 and n=n-1 depend on the condition as below. But this equation seem not work at all. Please help me to solve this problem. Thanks.
{
//------------------ Check OrderType in History
for(int i=0; i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
OProfit = OrderProfit();
OType = OrderType();
OLot = OrderLots();
}
//------------------ Hedge Lot Calculation
Hedge_Lot = NormalizeDouble((OLot*3),2);
//------------------ Order is closed
if(OrdersTotal()==0)
{
//------------------ Initial trades
if(OProfit==0)
{
n=0;
Lot = Lot_Size;
Selling();
return(n);
}
//------------------ Hedge condition
if(OType==OP_SELL && OProfit>0)
{
if(n==0)
{
Lot=Lot_Size;
Buying();
}
else
{
n=n-1; //does not work
Lot = Lot_Size;
Buying();
}
return(n);
}
if(OType==OP_BUY && OProfit>0)
{
if(n==0)
{
Lot=Lot_Size;
Selling();
}
else
{
n=n-1; //does not work
Lot = Lot_Size;
Selling();
}
return(n);
}
if(OType==OP_SELL && OProfit<0)
{
if (OLot>1.3)
{
if(n==0)
{
n=n+3; //does not work
}
else
{
n=n+2; //does not work
}
Lot=OLot;
Buying();
}
else
{
Lot = Hedge_Lot;
Buying();
}
return(n);
}
if(OType==OP_BUY && OProfit<0)
{
if (OLot>1.3)
{
if(n==0)
{
n=n+3; //does not work
}
else
{
n=n+2; //does not work
}
Lot=OLot;
Buying();
}
else
{
Lot = Hedge_Lot;
Selling();
}
return(n);
}
}
return(n);
}