Hi all,
Please help to check the below code, is there any error if I want to make this EA to put in a pending order at the same time everyday? I have tried to run the strategy tester, but end up it don't trade a single trade for 3 years period!!! I believe something wrong inside.
Concept for this EA is:
1. put the pending order for Buy stop and Sell stop at GMT5:59, anyone of them trigger, the other one will be deleted, and put down the expiration for them if they still haven't reach the SL or TP at GMT06:59.
2. The Entry point for the Buy stop is the Highest close value between the current and previous bar, mean bar for GMT4 and GMT5, the Entry point for the Sell stop is the Lowest clost value between the current and the previous bar also.
3. If the different for the Highest and the Lowest is more than 70 pips, then dun put the pending order.
Please help to check any error or the improvement for the programming inside.
*This program is actually modified from a program call 21hours, however it can't be work after i adjusted the entry point and time entry.
Thanks.
//------------------------------------------------------
extern double Lots = 0.1;
extern int ChasStartH = 05;
extern int ChasStartM = 59;
extern int ChasStopH = 06;
extern int ChasStopM = 59;
extern int SL = 40; //Stop Loss
extern int TP = 100; //Take profit
extern double BuyEP; //Entry point for Buy order
extern double SellEP; //Entry point for Sell order
int prevtime;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int OrderCountOtl=0;
int i=0;
int total = OrdersTotal();
for(i = 0; i <= total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == 12321)
{
if (OrderType()>1) OrderCountOtl++;
}
}
if (OrderCountOtl==1)
{
for(i = 0; i <= total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == 12321)
{
if (OrderType()>1) OrderDelete(OrderTicket());
}
}
}
if(Time[0] == prevtime)
return(0);
prevtime = Time[0];
if(!IsTradeAllowed())
{
prevtime = Time[1];
return(0);
}
if (TimeHour(TimeCurrent())==ChasStartH && TimeMinute(TimeCurrent())==ChasStartM)
{
If (High[1]>High[0])
{
BuyEP = High[1];
}
If (High[1]<High[0])
{
BuyEP = High[0];
}
If (Low[1]<Low[0])
{
SellEP = Low[1];
}
If (Low[1]>Low[0])
{
SellEP = Low[0];
}
If (BuyEP-SellEP)>70*Point
{
return(0);
}
OrderSend(Symbol(),OP_BUYSTOP,Lots,BuyEP,2,Ask-SL*Point,Ask+TP*Point,"",12321,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots,SellEP,2,Bid+S L*Point,Bid- TP*Point,"",12321,0,Red);
}
if (TimeHour(TimeCurrent())==ChasStopH && TimeMinute(TimeCurrent())==ChasStopM)
{
i=0;
total = OrdersTotal();
for(i = 0; i <= total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == 12321)
{
if (OrderType()==OP_BUY)OrderClose(OrderTicket(),Orde rLots(),Bid,2,Green);
if (OrderType()==OP_SELL)OrderClose(OrderTicket(),Ord erLots(),Ask,2,Green);
if (OrderType()>1)OrderDelete(OrderTicket());
}
}
}
//----
return(0);
}



Reply With Quote
