هذا الكود توصلت اليه يضاف للاكسبيرت ، لحل مشكلة اغلاق الصفقات عند ارتفاع السعر بطريقة سريعة ورجوعة في نفس اللحظة قبل اكمال اغلاق الصفقات
فهو يمنع اغلاق الصفقات في تلك الحالة الى ان يستقر السعر
عن طريق ابطاء تغير الربح المفاجئ وجعل الربح يزيد تدريجيا مع الزمن في المدخلات
MQL4
كود PHP:
double GetDelayedProfit(double PipPrice,double AddPipEVERYmSec,double NowProfit){
static double LastProfit;
static double LastTimer;
double ProfitDiffMoney;
double ProfitDiffPips;
double ProfitDiffSec;
double range;
double AllowedProfitChange;// ''ربح معين يمكننا اضافته فقط ولا نقدر اضافة اكبر منه
double DelayedProfit;
//''اذا انخفض الربح - ينخفض خط الربح الوهمي في الحال
if(NowProfit <= LastProfit || AddPipEVERYmSec==0){
LastProfit = NowProfit;// ''تخزين اخر ربح
LastTimer = GetTickCount();// ''تخزين اخر زمن فحص
return(NowProfit);
}
ProfitDiffMoney = NowProfit - LastProfit;// ''ايجاد مقدار التغير في الربح عن اخر مرة
ProfitDiffPips = ProfitDiffMoney / PipPrice;// ''تحويل تغير الربح من مال الى عدد نقاط
ProfitDiffSec = MathAbs(GetTickCount() - LastTimer);///1000;// ''ايجاد التغير في الزمن عن اخر مرة تمت
range = ProfitDiffSec / AddPipEVERYmSec;// ''ايجاد مدى النقاط المسموح اضافته
AllowedProfitChange = range * PipPrice;// ''تحويل المدى بالنقاط الى مدى بالنقود يمكننا اضافته
DelayedProfit = AllowedProfitChange + LastProfit;// ''اضافة مدى النقود الى اخر ربح
if(DelayedProfit > NowProfit){DelayedProfit = NowProfit;}// ''اخذ المدى المتحقق فقط
LastProfit = DelayedProfit;// ''تخزين اخر ربح
LastTimer = GetTickCount();// ''تخزين اخر زمن فحص
return(DelayedProfit);
}
//---------------------------------------------------------------------------
double getPipD(double Lot){
double m;
m=Lot*MarketInfo(Symbol(),MODE_TICKVALUE)*10;
return(m);
}
//--------------------------------------------------------------------
double getLot(){
double Lot=0.0;
int i;
for(i=0;i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false){RefreshRates();return(0);}
Lot+=OrderLots();
}
return(Lot);
}
//-------------------------
if(LOT==0){LOT=getLot();}
double ProfitLoss=0;
ProfitLoss=GetDelayedProfit(getPipD(LOT),1000,AccountProfit());