//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
MinAccount=AccountEquity();
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
int start()
{
if(Bars<1) {Print("bars less than 1");return(0);}
double Price=iClose(NULL,0,0);
if (!ExistPositions()) {sB=0; sS=0;}
int T=0;
int B=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderComment()==Name_Expert)
{
int type=OrderType();
switch(type)
{
case OP_BUY:
sB=1;
T++;
LastB=OrderOpenPrice();
break;
case OP_SELL:
sS=2;
B++;
LastS=OrderOpenPrice();
break;
}
}
}
InitLots=MathCeil(AccountBalance()/10000)/cangliang;
LotsB=InitLots;
LotsS=InitLots;
LotsB=NormalizeDouble(MathFloor(LotsB*100)/100,minicang);
LotsS=NormalizeDouble(MathFloor(LotsS*100)/100,minicang);
if (minicang==2){
if (LotsB<0.01) LotsB=0.01;
if (LotsS<0.01) LotsS=0.01;}
if (minicang==1){
if (LotsB<0.1) LotsB=0.1;
if (LotsS<0.1) LotsS=0.1;}