1 مرفق
سؤال برمجي للاخوة المبرمجين
السلام عليكم
اخوكم بيحاول يتعلم برمجة MQL4
ارجو المساعدة
هذا الكود لحساب الربح/الخسارة الاجمالي لجميع اوامر الشراء
سويته على شكل user-defined function
وين الخطأ ؟
كود:
// this function calculates net buys profit
double CalculateOpenBuyOrderNetProfit()
{
double totalNetProfit = 0.0;
int totalOrders = OrdersTotal();
for (int i = 0; i < totalOrders; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY)
{
double currentPrice = MarketInfo(Symbol(), MODE_BID); // Get current bid price
double orderOpenPrice = OrderOpenPrice();
double orderLots = OrderLots();
double pipValue = MarketInfo(Symbol(), MODE_POINT);
double contractSize = MarketInfo(Symbol(), MODE_CONTRACT_SIZE);
// Calculate current profit/loss in pips
double pips = (currentPrice - orderOpenPrice) / pipValue;
// Calculate profit/loss in account currency
double profit = pips * pipValue * orderLots * contractSize;
totalNetProfit += profit;
}
}
return totalNetProfit;
}