#property copyright "System"
double TakeProfit =100; //150 150 /Bien 80 92 tres bien 100
double TakeProfit2 =100;
double StopLoss2 =500;
double StopLoss =500; //250 / b100 100 100
int i=0;
double Max=1;
double A=1,b=1;
extern double Lot=0.1;
int start()
{
double ADXP,ADXC,ADXDIPP;
double ADXDIPC,ADXDIMP,ADXDIMC;
double Lots;
int cnt, ticket, total;
int li;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
Lots = Lot;
total=OrdersTotal();
if(total<2)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"1er position",12,0,Green);
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"1er position",12,0,Red);
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY && OrderMagicNumber() ==12) // long position is opened
{
if((Ask-OrderOpenPrice())>=(20*Point))
{OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
OrderSend(Symbol(),OP_BUY,2*Lots,Ask,3,Bid-StopLoss2*Point,Ask+TakeProfit2*Point,"2eme position",13,0,Green);
}
}
if(OrderType()==OP_SELL && OrderMagicNumber() ==12)
{
if ((OrderOpenPrice()-Bid)>=(20*Point))
{OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
OrderSend(Symbol(),OP_SELL,2*Lots,Bid,3,Ask+StopLoss2*Point,Bid-TakeProfit2*Point,"2er position",12,0,Red);
}
}
if(OrderType()==OP_BUY && OrderMagicNumber() ==13)
{if((Ask-OrderOpenPrice())<=(10*Point))
{OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
OrderSend(Symbol(), OP_BUYSTOP, 2*Lots, Ask + 10 * Point, 3, 0, Ask +10 + 30 * Point,"2eme position", 13, 0, Blue);
//OrderSend(Symbol(),OP_BUY,2*Lots,Ask,3,Bid-StopLoss2*Point,Ask+TakeProfit2*Point,"2eme position",13,0,Green);
}
}
if(OrderType()==OP_SELL && OrderMagicNumber() ==13)
{if((OrderOpenPrice()-Bid)<=(10*Point))
{OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
OrderSend(Symbol(), OP_SELLSTOP, 2*Lots, Bid - 10 * Point, 3, 0, Bid - 10 - 30 * Point, "2eme position", 13, 0, Red);
}}
}
}
return(0);
}