النتائج 1 إلى 5 من 5
الموضوع: لماذا لم يعمل كود قفل الصفقات
- 30-04-2009, 10:10 AM #1
لماذا لم يعمل كود قفل الصفقات
هذ الإكسبرت اللي عمله الأستاذ وضاح العطار في دورة صناعة الإكسبرت , عملت باك تست , و لقيت إن البرنامج لا يستجيب لكود إغلاق الصفقات !!! ممكن توضيح السبب ؟؟ مو أنا
كود PHP:extern int Step=20;
extern int Takeprofit=50;
extern int Stoploss=50;
extern double Lots=1;
int Magicnumber=234561;
double Poin;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//Initialization to Check for unconventional Point digits number
if (Point == 0.00001) Poin = 0.0001; //6 digits
else if (Point == 0.001) Poin = 0.01; //3 digits (for Yen based pairs)
else Poin = Point; //Normal for 5 & 3 Digit Forex Quotes
return(0);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if(Hour()==0 && Minute()<5 && MyOrdersTotal(Magicnumber)>0)
{
DeletePendingOrders(Magicnumber);
CloseOrders(Magicnumber);
}
if(Hour()==0 && Minute()>5 && MyOrdersTotal(Magicnumber)==0)
{
double DayClose=iClose(Symbol(),PERIOD_D1,1);
double BuyPrice=DayClose+Step*Poin;
double BuyTP=BuyPrice+Takeprofit*Poin;
double BuySL=BuyPrice-Stoploss*Poin;
double SellPrice=DayClose-Step*Poin;
double SellTP=SellPrice-Takeprofit*Poin;
double SellSL=SellPrice+Stoploss*Poin;
OrderSend(Symbol(),OP_BUYSTOP,Lots,BuyPrice,3,BuySL,BuyTP,"",Magicnumber,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots,SellPrice,3,SellSL,SellTP,"",Magicnumber,0,Green);
}
return(0);
}
int MyOrdersTotal(int Magic)
{
int c=0;
int total = OrdersTotal();
for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
{
c++;
}
}
return(c);
}
int DeletePendingOrders(int Magic)
{
int total = OrdersTotal()-1;
for (int cnt = total ; cnt > 0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()!=OP_BUY || OrderType()!=OP_SELL))
{
OrderDelete(OrderTicket());
}
}
return(0);
}
int CloseOrders(int Magic)
{
int total = OrdersTotal()-1;
for (int cnt = total ; cnt > 0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
{
if (OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3);
}
if (OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3);
}
}
}
return(0);
}
- 30-04-2009, 12:48 PM #2
رد: لماذا لم يعمل كود قفل الصفقات
جرب هذا الكود لاغلاق الصفقات، ان شاء الله تضبط معاك:
كود:int CloseOrders(int Magic) { for (int cnt=0; cnt>=OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol()) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,0); } return(0); }
- 30-04-2009, 10:01 PM #3
رد: لماذا لم يعمل كود قفل الصفقات
تم التعديل و ما ظبط معاي
كود:extern int Step=20; extern int Takeprofit=50; extern int Stoploss=50; extern double Lots=1; int Magicnumber=234561; double Poin; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //Initialization to Check for unconventional Point digits number if (Point == 0.00001) Poin = 0.0001; //6 digits else if (Point == 0.001) Poin = 0.01; //3 digits (for Yen based pairs) else Poin = Point; //Normal for 5 & 3 Digit Forex Quotes return(0); //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if(Hour()==0 && Minute()<5 && MyOrdersTotal(Magicnumber)>0) { DeletePendingOrders(Magicnumber); CloseOrders(Magicnumber); } if(Hour()==0 && Minute()>5 && MyOrdersTotal(Magicnumber)==0) { double DayClose=iClose(Symbol(),PERIOD_D1,1); double BuyPrice=DayClose+Step*Poin; double BuyTP=BuyPrice+Takeprofit*Poin; double BuySL=BuyPrice-Stoploss*Poin; double SellPrice=DayClose-Step*Poin; double SellTP=SellPrice-Takeprofit*Poin; double SellSL=SellPrice+Stoploss*Poin; OrderSend(Symbol(),OP_BUYSTOP,Lots,BuyPrice,3,BuySL,BuyTP,"",Magicnumber,0,Green); OrderSend(Symbol(),OP_SELLSTOP,Lots,SellPrice,3,SellSL,SellTP,"",Magicnumber,0,Green); } return(0); } int MyOrdersTotal(int Magic) { int c=0; int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol()) { c++; } } return(c); } int DeletePendingOrders(int Magic) { int total = OrdersTotal()-1; for (int cnt = total ; cnt > 0 ; cnt--) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()!=OP_BUY || OrderType()!=OP_SELL)) { OrderDelete(OrderTicket()); } } return(0); } int CloseOrders(int Magic) { for (int cnt=0; cnt>=OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol()) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,0); } return(0); } //------------------------------
آخر تعديل بواسطة alshakatan ، 30-04-2009 الساعة 10:03 PM
- 01-05-2009, 02:59 AM #4
رد: لماذا لم يعمل كود قفل الصفقات
بعد فحص الكود، هناك خطئين، واحد من عندي والاخر من عندك.
الخطأ الاول في CloseOrders
الاشارة يجب ان تكون اصغر من (>)
كود:cnt>=OrdersTotal() الصحيح cnt<=OrdersTotal()
كود:int total = OrdersTotal()-1;
وبعد تعديل الكود:
كود:extern int Step=20; extern int Takeprofit=50; extern int Stoploss=50; extern double Lots=1; int Magicnumber=234561; double Poin; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //Initialization to Check for unconventional Point digits number if (Point == 0.00001) Poin = 0.0001; //6 digits else if (Point == 0.001) Poin = 0.01; //3 digits (for Yen based pairs) else Poin = Point; //Normal for 5 & 3 Digit Forex Quotes return(0); //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if(Hour()==0 && Minute()<5 && MyOrdersTotal(Magicnumber)>0) { DeletePendingOrders(Magicnumber); CloseOrders(Magicnumber); } if(Hour()==0 && Minute()>5 && MyOrdersTotal(Magicnumber)==0) { double DayClose=iClose(Symbol(),PERIOD_D1,1); double BuyPrice=DayClose+Step*Poin; double BuyTP=BuyPrice+Takeprofit*Poin; double BuySL=BuyPrice-Stoploss*Poin; double SellPrice=DayClose-Step*Poin; double SellTP=SellPrice-Takeprofit*Poin; double SellSL=SellPrice+Stoploss*Poin; OrderSend(Symbol(),OP_BUYSTOP,Lots,BuyPrice,3,BuySL,BuyTP,"",Magicnumber,0,Green); OrderSend(Symbol(),OP_SELLSTOP,Lots,SellPrice,3,SellSL,SellTP,"",Magicnumber,0,Green); } return(0); } int MyOrdersTotal(int Magic) { int c=0; int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol()) { c++; } } return(c); } int DeletePendingOrders(int Magic) { for (int cnt=0; cnt<=OrdersTotal(); cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()!=OP_BUY || OrderType()!=OP_SELL)) OrderDelete(OrderTicket()); } return(0); } int CloseOrders(int Magic) { for (int cnt=0; cnt<=OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol()) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,0); } return(0); } //------------------------------
- 01-05-2009, 06:57 AM #5
المواضيع المتشابهه
-
لماذا هذا الكود لا يعمل
By adsl in forum برمجة المؤشرات واكسبرتات التداول - Experts Advisor EAمشاركات: 9آخر مشاركة: 04-03-2010, 07:04 AM -
لماذا تغلق الصفقات قبل الاستوب؟
By aLcOmAnDa in forum سوق تداول العملات الأجنبية والسلع والنفط والمعادنمشاركات: 11آخر مشاركة: 19-09-2009, 05:54 PM -
لماذا لا يعمل MetaTrader 4
By بو محمد in forum استفسارات وأسئلة المبتدئينمشاركات: 2آخر مشاركة: 22-01-2007, 04:46 PM