7

I am a novice, I would like to change an EA code article, my intention is: When KD Jin Cha at the same time for two single, one only set only win, just do a no win and stop, such as when the price reaches only Win bits with only one win will automatically open only to win, do a single time in the open KD Sicha. If price not only win the next place there must be two single KD Sicha Sicha open in KD. But there is no adaptation of the successful, I hope you brothers look at the following code to rewrite what is right.
Here is my EA code:

#define MyKD 20100720
//----
extern double Lots=1.0;
extern int tp=50;
extern int Leverage=100;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

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

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

//----
//----
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MyKD)
{
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
else return(-sells);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
//----
int res, res1;
double point =MarketInfo(Symbol(),MODE_POINT);
Print("point=",point);
//----
if(Volume[0]>2) return;
//----
double val_1=iCustom(NULL, 0, "KD",28,3,3,0,1);
double val_2=iCustom(NULL, 0, "KD",283,3,1,1);
double val_3=iCustom(NULL, 0, "KD",28,3,3,0,2);
double val_4=iCustom(NULL, 0, "KD",28,3,3,1,2);

Print("val_1=",val_1);
Print("val_2=",val_2);
Print("val_3=",val_3);
Print("val_4=",val_4);

//---- sell conditions
if(val_1<val_2&&val_3>val_4)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,0,0,"Open short positions",MyKD,0,Red);
res1=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,0,Bid-tp*point,"Open short positions",MyKD,0,Blue);
if (res <=0)
{
int error=GetLastError();
if(error==134) Print("Received 134 Error after OrderSend() !! ");
if(error==135) RefreshRates();
if(error==131) Print("Received 131 Error after OrderSend() !! ");
}
return;
}
if(val_1>val_2&&val_3<val_4)
{
if (res <=0)
{
error=GetLastError();
if(error==134) Print("Received 134 Error after OrderSend() !! ");
if(error==135) RefreshRates();
}
return;
}
//----
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
if(Volume[0]>2) return;
//----
double val_K=iCustom(NULL, 0, "KD",28,3,3,0,1);
double val_D=iCustom(NULL, 0, "KD",28,3,3,1,1);
double val_Ka=iCustom(NULL, 0, "KD",28,3,3,0,2);
double val_Da=iCustom(NULL, 0, "KD",28,3,3,1,2);

//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderMagicNumber()!=MyKD || OrderSymbol()!=Symbol()) continue;
//---- check order type
{
if(val_K<val_D&&val_Ka>val_Da)
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
return(0);
}
if(OrderType()==OP_SELL)
{
if(val_K>val_D&&val_Ka<val_Da)