Experts: Simple Expert Advisor

 

Simple Expert Advisor:

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

Author: Vladimir Khlystov

 

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-

 
BarrowBoy:

Editor's remark:

You are right. Code corrected.

Thank you.

 

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;

 

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
   }
}
 

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

Best Reguard ?

 

yeh but what time frames ?

 
Hello Vladimir , although imposed stop loss and take profit , when it takes a position I have to put them manually , how come ?
 
damianino:

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

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