|
|
|
|
|
الشكر موصول لك اخي اسامة
الكود مرفق بالكامل مع ملاحظة ان
الدالة MyRealOrder دائما قيمتها صفر حتى بعد تفعيل الصفقة
والدالة GetOrderType دائما قيمتها -1
كود:
//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern int Step=30;
extern double Lots=0.01;
extern int Magicnumber=123123;
double point;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
if(Digits<4){point=0.01;}
else{point=0.0001;}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double OpenPrice,Up11,Up12,Up13,Dn11,Dn12,Dn13;
if(Hour()==0 && Minute()<1 && MyOrdersTotal(Magicnumber)>0){DeletePendingOrders(Magicnumber);}
if(Hour()==0 && Minute()>5 && MyOrdersTotal(Magicnumber)==0)
{
OpenPrice=NormalizeDouble(iOpen(Symbol(),PERIOD_D1,0),4);
Up11=OpenPrice+Step*point;
Up12=Up11+Step*point;
Up13=Up12+Step*point;
Dn11=OpenPrice-Step*point;
Dn12=Dn11-Step*point;
Dn13=Dn12-Step*point;
int BUY=OrderSend(Symbol(),OP_BUYSTOP,Lots,Up12,3,0,Up13,"TEST_Buy#1",Magicnumber,0,Green);
int SELL=OrderSend(Symbol(),OP_SELLSTOP,Lots,Dn12,3,0,Dn13,"TEST_Sell#1",Magicnumber,0,Red);
int GOT=GetOrderType(Magicnumber);
int R=MyRealOrdersTotal(Magicnumber);
int mot=MyOrdersTotal(Magicnumber);
Comment("BUY = "+BUY+
"\nSELL = "+SELL+
"\nUp11 = "+Up11+
"\nUp12 = "+Up12+
"\nUp13 = "+Up13+
"\nDn11 = "+Dn11+
"\nDn12 = "+Dn12+
"\nDn13 = "+Dn13+
"\nMyRealOrdersTotal = "+R+
"\nGetOrderType = "+GOT+
"\nMyOrdersTotal = "+mot);
if((BUY>0 || SELL>0) && R>0)
{
DeletePendingOrders(Magicnumber);
// double Lots2=
OrderSend(Symbol(),OP_SELLSTOP,Lots,Up11,3,0,OpenPrice,"TEST_Sell#1",Magicnumber,0,Red);
}
}
//----
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 MyRealOrdersTotal(int magic)
{
int i=0;
int total = OrdersTotal();
for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL))
{
i++;
}
}
return(i);
}
//////////////////////////////////////////////////////////
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 GetOrderType(int magic)
{
int OT=-1;
int total = OrdersTotal();
for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL))
{
OT=OrderType();
}
}
return(OT);
}
مرفق ملف الكود بالمرفقات
|
|
|
|
|
،،،حسب مافهمت من الكود هو وضع امرين معلقين مع بداية اليوم حالى وعند افتتاح اليوم يتم مسح الاوامر التى لم تفعل ويتم وضع اوامر جديدة ، لكن الصياغة البرمجية للفكرة غير صحيحة فى الكود المرفق ، اذا كان مافهمته صحيح الرجاء اخبارى لاقوم بارفاق الكود الصحيح،،،