//+------------------------------------------------------------------+
//|                                     martingeil-2direct-Laut real |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
 double startLots = 0.5;
// Лот-прогрессия 1-2 -3 -4  -5 -8
// Шаг-прогрессия 0-20-40-80-160-320 
 double Step=50;
 double StepFactor=2;



int k;
int ticket;
int Ordertype;
double priceClose;
double priceCloseB;
double priceCloseS;
double b1,b2,b3,b4,b5,b6,s1,s2,s3,s4,s5,s6;



int start()
 {

double Lots1 = startLots;
double Lots2 = startLots*2;
double Lots3 = startLots*3;
double Lots4 = startLots*4;
double Lots5 = startLots*5;
double Lots6 = startLots*8;




  k=OrdersTotal();


if (k==0)
   {
s1=Ask+Step*Point;
s2=s1+Step*StepFactor*Point;
s3=s2+Step*MathPow(StepFactor,2)*Point;
s4=s3+Step*MathPow(StepFactor,3)*Point;
s5=s4+Step*MathPow(StepFactor,4)*Point;



b1=Bid-Step*Point;
b2=b1-Step*StepFactor*Point;
b3=b1-Step*MathPow(StepFactor,2)*Point;
b4=b2-Step*MathPow(StepFactor,3)*Point;
b5=b4-Step*MathPow(StepFactor,4)*Point;



//Начальные ордеры
OrderSend(Symbol(),OP_BUY,Lots1,Ask,3,NULL,NULL,NULL,100,0,Blue);
OrderSend(Symbol(),OP_SELL,Lots1,Bid,3,NULL,NULL,NULL,200,0,Green);

OrderSend(Symbol(),OP_BUYLIMIT,Lots2,b1,3,NULL,Ask,NULL,101,0,Red);
OrderSend(Symbol(),OP_SELLLIMIT,Lots2,s1,3,NULL,Bid,NULL,201,0,Yellow);
OrderSend(Symbol(),OP_SELLSTOP,Lots1,b1,3,NULL,NULL,NULL,301,0,Green);
OrderSend(Symbol(),OP_BUYSTOP,Lots1,s1,3,NULL,NULL,NULL,401,0,Green);

OrderSend(Symbol(),OP_BUYLIMIT,Lots3,b2,3,NULL,b1,NULL,102,0,Red);
OrderSend(Symbol(),OP_SELLLIMIT,Lots3,s2,3,NULL,s1,NULL,202,0,Yellow);
OrderSend(Symbol(),OP_SELLSTOP,Lots1,b2,3,NULL,NULL,NULL,302,0,Green);
OrderSend(Symbol(),OP_BUYSTOP,Lots1,s2,3,NULL,NULL,NULL,402,0,Green);


OrderSend(Symbol(),OP_BUYLIMIT,Lots4,b3,3,NULL,b2,NULL,103,0,Red);
OrderSend(Symbol(),OP_SELLLIMIT,Lots4,s3,3,NULL,s2,NULL,203,0,Yellow);
OrderSend(Symbol(),OP_SELLSTOP,Lots1,b3,3,NULL,NULL,NULL,303,0,Green);
OrderSend(Symbol(),OP_BUYSTOP,Lots1,s3,3,NULL,NULL,NULL,403,0,Green);


OrderSend(Symbol(),OP_BUYLIMIT,Lots5,b4,3,NULL,b3,NULL,104,0,Red);
OrderSend(Symbol(),OP_SELLLIMIT,Lots5,s4,3,NULL,s3,NULL,204,0,Yellow);
OrderSend(Symbol(),OP_SELLSTOP,Lots1,b4,3,NULL,NULL,NULL,304,0,Green);
OrderSend(Symbol(),OP_BUYSTOP,Lots1,s4,3,NULL,NULL,NULL,404,0,Green);


OrderSend(Symbol(),OP_BUYLIMIT,Lots6,b5,3,NULL,b4,NULL,105,0,Red);
OrderSend(Symbol(),OP_SELLLIMIT,Lots6,s5,3,NULL,s4,NULL,205,0,Yellow);
OrderSend(Symbol(),OP_SELLSTOP,Lots1,b5,3,NULL,NULL,NULL,305,0,Green);
OrderSend(Symbol(),OP_BUYSTOP,Lots1,s5,3,NULL,NULL,NULL,405,0,Green);
   }


k=OrdersTotal();





if (k<=21)
{

   for(int m=0;m<=k-1;m++)
   {
      if(OrderSelect(m,SELECT_BY_POS) && OrderSymbol()==Symbol())
      {
      Ordertype=OrderType();
      ticket=OrderTicket();
      switch(Ordertype)
         {
         case 0:
         priceClose=MarketInfo(OrderSymbol(),MODE_BID);
         OrderClose(ticket,OrderLots(),priceClose,3,Red);
         break;

         case 1:
         priceClose=MarketInfo(OrderSymbol(),MODE_ASK);
         OrderClose(ticket,OrderLots(),priceClose,3,Red);
         break;

         default:
            OrderDelete(ticket);
            break;
         }
       }
   }      
}     
  
}


