Lot calculation and rejected orders
Hi All,
when calculating lots based on risk % sometimes I run into a situation where the order is rejected because not enough money in account. This is pretty straight forward to iron out however the problem is with the SYMBOL_MARGIN_INITIAL function as it is showing an inital margin that is equal to the contract value... $100,000 (which is wrong)
anyone know a workaround for this?
even in the contract specs it shows inital margin of $100,000...
// Check if there is enough money to place the order
double requiredMargin = SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL);
double freeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
double marginNeeded = requiredMargin * lots;
if (marginNeeded <= freeMargin) {
if (trade.BuyStop(lots, high, _Symbol, sl, tp, ORDER_TIME_GTC, 0, OrderComment)) {
Order = trade.ResultOrder();
}
} else {
Print("Not enough money to place the buy order.");
// Handle the situation when there's not enough money to place the order.
// log this or take specific actions based on trading strategy.
}
0
6 comments
Angus Knight
2
Lot calculation and rejected orders
Automated Traders Community
skool.com/automated-traders-community-7473
Let's collaborate to become better traders/programmers!
No spamming, no scamming!
Be kind to each other!
Powered by