اف اكس ارابيا..الموقع الرائد فى تعليم فوركس Forex

اف اكس ارابيا..الموقع الرائد فى تعليم فوركس Forex (https://fx-arabia.com/vb/index.php)
-   منتدى تعليم الفوركس (https://fx-arabia.com/vb/forumdisplay.php?f=3)
-   -   هذا كود اغلاق الصفقات دفعة واحدة (https://fx-arabia.com/vb/showthread.php?t=10208)

مبتدىfx 30-06-2011 05:34 PM

هذا كود اغلاق الصفقات دفعة واحدة
 
السلام عليكم خواني

هذا كود اغلاق الصفقات دفعة واحدة

اين هو المكان الذي احدد فيه السعر الذي اريد الاغلاق علية

/+------------------------------------------------------------------+
//| CloseAll-PL.mq4 |
//| |
//+------------------------------------------------------------------+

extern int Profit=0;
double myProfit=0;
int EnableClose=0
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
myProfit=CalcProfit();
ShowInit();

if (EnableClose==1 && CntOrdAll(OP_BUY)==0 && CntOrdAll(OP_SELL)==0 && CntOrdAll(OP_BUYSTOP)==0
&& CntOrdAll(OP_BUYLIMIT)==0 && CntOrdAll(OP_SELLSTOP)==0 && CntOrdAll(OP_SELLLIMIT)==0) {
EnableClose=0; // Before Debug: EnableClose=1
}
if ( (Profit>0 && myProfit>=Profit) || (Profit<0 && myProfit<=Profit)) {
EnableClose=1;
}

CloseAll();

//----
return(0);
}
//+------------------------------------------------------------------+

void CloseAll () { // #function of CloseAll
if (EnableClose==1) { // #if Close is yes
int _total=OrdersTotal(); // number of lots or trades ????
int _ordertype;// order type
if (_total==0) {return;} // if total==0
int _ticket; // ticket number
double _priceClose;// price to close orders;
for(int _i=_total-1;_i>
=0;_i--)
{ //# for loop
if (OrderSelect(_i,SELECT_BY_POS))
{ //# if
_ordertype=OrderType();
_ticket=OrderTicket();
switch(_ordertype)
{ //# switch
case OP_BUYLIMIT:
OrderDelete(OrderTicket());
case OP_BUYSTOP:
OrderDelete(OrderTicket());
case OP_BUY:
// close buy
_priceClose=MarketInfo(OrderSymbol(),MODE_BID);
Print("Close on ",_i," position order with ticket ¹",_ticket);
OrderClose(_ticket,OrderLots(),_priceClose,3,Red);
break;
case OP_SELLLIMIT:
OrderDelete(OrderTicket());
case OP_SELLSTOP:
OrderDelete(OrderTicket());
case OP_SELL:
// close sell
_priceClose=MarketInfo(OrderSymbol(),MODE_ASK);
Print("Close on ",_i," position order with ticket ¹",_ticket);
OrderClose(_ticket,OrderLots(),_priceClose,3,Red);
break;
default:
// values from 1 to 5, deleting pending orders
// Print("Delete on ",_i," position order with ticket ¹",_ticket);
// OrderDelete(_ticket);
break;
} //# switch
} // # if
} // # for loop
} // #if Close yes
return;
} // #function of CloseAll

void ShowInit() {
string sComment = "";
string sp = "-----------------------------------------------------\n";
string NL = "\n";
sComment = sp;
sComment = sComment + "CloseByPL will close all trades at: " + Profit + NL;
sComment = sComment + sp;
sComment = sComment + "Current P/L="+DoubleToStr(myProfit,0)+ NL;
Comment(sComment);
return;
}
double CalcProfit() {
double _sum=0;
int _total=OrdersTotal(); // number of lots

if (_total==0) {return (0);}
_sum=AccountProfit();
return(_sum);
}

int CntOrdAll(int Type) {
//return number of orders with specific parameters
int _CntOrd;
_CntOrd=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType()==Type) _CntOrd++;
}
return(_CntOrd);
}

Benisafcom 30-06-2011 08:30 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
شكرا على المشاركة اخي.
لكن لو نظمت موضوعك احسن باستعمال الالوان و التسطير.
لاني لحد الان لم افهم كيف ادخال الكود

محمد نوارج 30-06-2011 08:44 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
ممكن يفيدك الأخ حكيم..،

Eng.Hamada 30-06-2011 09:14 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
ثواني بإذن الله وبجهزلك اللي بتريده

Benisafcom 30-06-2011 09:16 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
خد راحتك يا باشا

Eng.Hamada 30-06-2011 09:47 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
كود:

//+------------------------------------------------------------------+
//|                                                closs all pl.mq4 |
//|                                                          Hamada |
//|                                                www.fx-arabia.com |
//+------------------------------------------------------------------+
#property copyright "Hamada"
#property link      "www.fx-arabia.com"


extern int Profit=10; // ضع هنا الريح الاجمالي اللذي تريد اغلاق الصفقات عليه
double myProfit=0;
int EnableClose=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
myProfit=CalcProfit();
ShowInit();

if (EnableClose==1 && CntOrdAll(OP_BUY)==0 && CntOrdAll(OP_SELL)==0 && CntOrdAll(OP_BUYSTOP)==0
&& CntOrdAll(OP_BUYLIMIT)==0 && CntOrdAll(OP_SELLSTOP)==0 && CntOrdAll(OP_SELLLIMIT)==0) {
EnableClose=0; // Before Debug: EnableClose=1
}
if ( (Profit>0 && myProfit>=Profit) || (Profit<0 && myProfit<=Profit)) {
EnableClose=1;
}

CloseAll();

//----
return(0);
}
//+------------------------------------------------------------------+

void CloseAll () { // #function of CloseAll
if (EnableClose==1) { // #if Close is yes
int _total=OrdersTotal(); // number of lots or trades ????
int _ordertype;// order type
if (_total==0) {return;} // if total==0
int _ticket; // ticket number
double _priceClose;// price to close orders;
for(int _i=_total-1;_i>=0;_i--)
{ //# for loop
if (OrderSelect(_i,SELECT_BY_POS))
{ //# if
_ordertype=OrderType();
_ticket=OrderTicket();
switch(_ordertype)
{ //# switch
case OP_BUYLIMIT:
OrderDelete(OrderTicket());
case OP_BUYSTOP:
OrderDelete(OrderTicket());
case OP_BUY:
// close buy
_priceClose=MarketInfo(OrderSymbol(),MODE_BID);
Print("Close on ",_i," position order with ticket ¹",_ticket);
OrderClose(_ticket,OrderLots(),_priceClose,3,Red);
break;
case OP_SELLLIMIT:
OrderDelete(OrderTicket());
case OP_SELLSTOP:
OrderDelete(OrderTicket());
case OP_SELL:
// close sell
_priceClose=MarketInfo(OrderSymbol(),MODE_ASK);
Print("Close on ",_i," position order with ticket ¹",_ticket);
OrderClose(_ticket,OrderLots(),_priceClose,3,Red);
break;
default:
// values from 1 to 5, deleting pending orders
// Print("Delete on ",_i," position order with ticket ¹",_ticket);
// OrderDelete(_ticket);
break;
} //# switch
} // # if
} // # for loop
} // #if Close yes
return;
} // #function of CloseAll

void ShowInit() {
string sComment = "";
string sp = "-----------------------------------------------------\n";
string NL = "\n";
sComment = sp;
sComment = sComment + "CloseByPL will close all trades at: " + Profit + NL;
sComment = sComment + sp;
sComment = sComment + "Current P/L="+DoubleToStr(myProfit,0)+ NL;
Comment(sComment);
return;
}
double CalcProfit() {
double _sum=0;
int _total=OrdersTotal(); // number of lots

if (_total==0) {return (0);}
_sum=AccountProfit();
return(_sum);
}

int CntOrdAll(int Type) {
//return number of orders with specific parameters
int _CntOrd;
_CntOrd=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType()==Type) _CntOrd++;
}
return(_CntOrd);
}


الاسكربت عباره عن اسكربت لإغلاق كل العقود المفتوحه علي ربح معين يعني فرضا انت لو فاتح 2 لوت شراء علي اليورو دولار و لوت شراء علي الاسترليني دولار وعايز تقفل كل العقود اللي انت فاتحها علي اجمالي ربح 50 دولار
يبقي هتكتب في السطر اللي انا معلم عليه فوق بالازرق رقم 50 بدل رقم 10 وبطدع مجرد ما يوصل اجمالي ربح جميع الصفقات المفتوحه ل 50 دولار هيقفلك كل الصفقات



Eng.Hamada 30-06-2011 09:48 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
وثواني هرفع لجميع الاعضاء الاسكربت جاهز وازاي يعدلوا فيه ويكتبوا الربح اللي عايزينه

مبتدىfx 30-06-2011 10:02 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
مشكور ياغالي ماقصرت

وبالنسبة للاخ اللي يقول نضمت الموضوع انا نزلت الكود للاستفسار عن مكان وضع الرقم

Eng.Hamada 30-06-2011 10:11 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
1 مرفق
اول حاجة هننسخ الاسكربت لللمجلد اللي اسمه Scripts وهو موجود داخل المجلد اللي اسمه experts في مجلد الميتا تريدر
C:\Program Files\FXDD Malta - MetaTrader 4\experts\scripts

بعد كده هتفتح الميتا تريدر وهتعمل زي ما في الصورة هتضغط كليك يمين هلي اسم الاسكربت
http://fx-arabia.com/vb/uploaded/1622_11309461022.png

بعد كده هتعمل زي اللي في صورة دي بالظبط هتكتب الربح اللي انت عايزه وتضفط save وتقفل بعدها الميتا تريدر وتفتحه تاني
http://fx-arabia.com/vb/uploaded/1622_11309461054.png

اخر حاجة هتفتح اي شارت فاضي وتضغط 2 كليك علي اسم الاسكربت وهتلاقيها كتبتلك علي الشارت ربحك الحالي كذا وان الاسكربت هيقفل كل الصفقات المفتوحة علي الربح اللي انت كاتبه

Eng.Hamada 30-06-2011 10:15 PM

رد: هذا كود اغلاق الصفقات دفعة واحدة
 
اقتباس:

المشاركة الأصلية كتبت بواسطة مبتدىfx (المشاركة 162297)
مشكور ياغالي ماقصرت

وبالنسبة للاخ اللي يقول نضمت الموضوع انا نزلت الكود للاستفسار عن مكان وضع الرقم

الشكر لله ياغالي
واي حاجة تانية اوعي تتأخر في انك تسأل عنها
وشكرا علي الاسكربت كمان لان في ناس كتير هنا كانت بتدور عليها
بالتوفيق ياغالي


الساعة الآن 10:05 AM

Powered by vBulletin® Copyright ©2000 - 2024

جميع الحقوق محفوظة الى اف اكس ارابيا www.fx-arabia.com