//---- input parameters
extern int StopLoss=13;
extern int TakeProfit=13;
extern double Lot=0.01;
extern int myMagic=111;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
OrderSend(Symbol(),OP_SELL,Lot,Bid,3,Bid + Point*StopLoss,Bid - Point*TakeProfit,NULL,myMagic,0,Red);
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int total, oldtotal, cnt, myTicket;
bool myTrades = false;
total = OrdersTotal();
for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == myMagic)
{
myTicket = OrderTicket();
myTrades = true;
}
}
//----
int myColour, cmd;
double myPrice, myPriceClose, myStop, myProfit;
if(myTrades == false)
{
int i;
for(i=0; i<OrdersTotal(); i++)
if(OrderSelect(i, SELECT_BY_POS))
if(OrderMagicNumber() == myMagic)
{
if(OrderType() != OP_BUY)
{
cmd = OP_BUY;
myPrice = Ask;
myPriceClose = Bid;
myColour = Green;
myStop = Ask - Point*StopLoss;
myProfit = Ask + Point*TakeProfit;
}
else // down trend
{
cmd = OP_SELL;
myPrice = Bid;
myPriceClose = Ask;
myColour = Red;
myStop = Bid + Point*StopLoss;
myProfit = Bid - Point*TakeProfit;
}
}
myTicket = OrderSend(Symbol(),cmd,Lot,myPrice,3,myStop,myProfit,
NULL,myMagic,0,myColour);
}
//----
return(0);
}