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:
#property copyright "senlin ge"
#property link "mailto"
#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()
{
//----
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:
#property copyright "senlin ge"
#property link "mailto"
#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(Bars<100 || IsTradeAllowed()==false) return;
//----
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MyKD)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
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;
}
//---- buy conditions
if(val_1>val_2&&val_3<val_4)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,0,0,"open more stores",MyKD,0,Blue);
res1=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,0,Ask+tp*point,"open more stores",MyKD,0,Red);
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(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MyKD || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
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)
OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
return(0);
}
}
return;
}
//+------------------------------------------------------------------+