النتائج 1 إلى 15 من 22
الموضوع: سؤال برمجي للاخوة المبرمجين
- 19-01-2025, 03:53 PM #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; }
- 19-01-2025, 04:39 PM #2
هل الخطأ اني بدأت
i=0
يمكن المفروض ابدا اللووب
i=1
????
- 19-01-2025, 09:32 PM #3
- 20-01-2025, 07:49 AM #4
- 20-01-2025, 11:35 AM #5
- 21-01-2025, 07:39 AM #6
- 23-01-2025, 12:28 AM #7
اخي لماذا لا تستخدم الدالة الجاهزة
OrderProfit()
ويصبح الكود هكذا
// 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 =OrderProfit();
totalNetProfit += profit;
}
}
آخر تعديل بواسطة wajdyss ، 23-01-2025 الساعة 12:38 AM
- 23-01-2025, 12:26 PM #8
- 24-01-2025, 12:50 AM #9
- 24-01-2025, 01:13 AM #10
- 24-01-2025, 01:16 AM #11
يصبح الكود هكذا
ما رايكم استاذتنا المبرمجين ؟
كود:// 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 profit =OrderProfit(); totalNetProfit += profit; } } return totalNetProfit; }
- 24-01-2025, 11:56 AM #12
- 24-01-2025, 04:31 PM #13
ربي يسعدك ويحفظك
وينفع بعلمك المسلمين
- 26-01-2025, 11:54 PM #14
- 26-01-2025, 11:57 PM #15
هناك ملاحظة اخي
كي تحسب الربح بشكل صحيح فيجب ان تحسب السواب والكوميشن
يعني
OrderSwap()+OrderCommission()
بالاضافة طبعاً للسابق
OrderProfit()
الأكثر زيارة
رد مع اقتباس
