Download MetaTrader 5
To add comments, please log in or register
The Market has more than 400 indicators. Try any of them!
MetaQuotes Software Corp.
Moderator
178205
MetaQuotes Software Corp. 2009.11.30 13:58 

Simple Expert Advisor:

Many people asks to post a simple expert advisor. Here is it.

Author: Vladimir Khlystov

Brian Dee - Random Trader
1762
Brian Dee - Random Trader 2009.11.30 15:50  

I think

void CLOSEORDER(string ord)
{
   for (int i=0; i<OrdersTotal(); i++)
   {                                               
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
      {
         if (OrderSymbol()!=Symbol()) continue;
         if (OrderType()==OP_BUY && ord=="Buy")
            OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);// Close Buy
         if (OrderType()==OP_SELL && ord=="Sell")
            OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);// Close Sell
      }   
   }
}

should be

void CLOSEORDER(string ord)
{
   for (int i=OrdersTotal()-1; i>=0; i--)
   {                                               
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
      {
         if (OrderSymbol()!=Symbol()) continue;
         if (OrderType()==OP_BUY && ord=="Buy")
            OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);// Close Buy
         if (OrderType()==OP_SELL && ord=="Sell")
            OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);// Close Sell
      }   
   }
}

FWIW

-BB-

Automated-Trading
Admin
94235
Automated-Trading 2009.11.30 16:29  
BarrowBoy:

Editor's remark:

You are right. Code corrected.

Thank you.

whroeder1
13959
whroeder1 2009.12.01 19:15  

I think

if (LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT);
if (LOT<MINLOT)                           LOT = MINLOT;
if (MINLOT<0.1) LOT = NormalizeDouble(LOT,2); else LOT = NormalizeDouble(LOT,1);

Should be

double	LotStep = MarketInfo( Symbol(), MODE_LOTSTEP );
LOT=MathFloor(	LOT / LotStep )*LotStep;
if (LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT);
if (LOT<MINLOT)                           LOT = MINLOT;

whroeder1
13959
whroeder1 2009.12.01 21:46  

Or simplier

void CLOSEORDER(string ord)
{
   for (int i=OrdersTotal()-1; i>=0; i--)  if (
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES)
   && OrderMagicNumber() == MagicNumber		// with my magic number,
   && OrderSymbol()	 == Symbol() ) {	// in my chart.
         if (OrderType()==OP_BUY && ord=="Buy")
            OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);// Close Buy
         if (OrderType()==OP_SELL && ord=="Sell")
            OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);// Close Sell
   }
}
MQL4 Comments
16319
MQL4 Comments 2010.01.25 23:32  

Could you tell more what 's Timeframe (M1)(M5)(M15) (M30) with EUR/USD are the best for this File.

Best Reguard ?

MQL4 Comments
16319
MQL4 Comments 2010.02.02 20:55  

yeh but what time frames ?

damianino
16
damianino 2015.05.14 16:23  
Hello Vladimir , although imposed stop loss and take profit , when it takes a position I have to put them manually , how come ?
Vladimir Khlystov
10252
Vladimir Khlystov 2015.05.14 17:32  
damianino:

В параметрах советника есть возможность устанавливать стоплосс и тейкпрофит.

Я не понимаю, что у Вас не получилось. 

/
To add comments, please log in or register