Ayúdame a escribir un EA, gracias de antemano - página 14

 
//+------------------------------------------------------------------+
//|                                                        Канал.mq4 |
//|                                          Copyright © 2011, Лукас |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Лукас"
#property link      "http://www.metaquotes.net"
extern int    magicnumber    = 1210;
extern double  Nach_Lot = 0.05;

extern int SL_BUY  = 500; 
extern int TP_BUY  = 700;
extern int Shirina_Kanala_STOP  = 200;

//int SL_SELL  = 400; 
//int TP_SELL  = 400; 
double Lot,Lot_BUY,Lot_SELL,Min_Lot;
string TF,Metka;
int Ticket_Open_BUYSTOP, Ticket_Open_SELLSTOP,Ticket_Open_BUY,Ticket_Open_SELL;
double Cena_Otkr_BUY,Cena_Otkr_SELL,TP_Otkr_BUY,SL_Otkr_BUY,TP_Otkr_SELL,SL_Otkr_SELL;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   Lot=Nach_Lot;
   Lot_BUY=Nach_Lot;
   Lot_SELL=Nach_Lot;
   Min_Lot =MarketInfo(Symbol(), MODE_MINLOT);   
   //StopLevel = ND(MarketInfo(Symbol(), MODE_STOPLEVEL)*Point);  
   return(0);

  }
//***********************************************************************************************************************************//
// Функция деинициализации советника-------------------------------------------------------------------------------------------------//
//***********************************************************************************************************************************//
int deinit()
  {
   return(0);
  }
// Окончание функции деинициализации советника---------------------------------------------------------------------------------------//

//***********************************************************************************************************************************//
// Функция старта советника----------------------------------------------------------------------------------------------------------//
//***********************************************************************************************************************************//
int start()
  {
  Metka=Symbol()+"-''Канал(v.1.0)''";

 double ZigZag_0=iCustom(NULL, 0, "ZigZag",12,5,3,1,0);
 double ZigZag_1=iCustom(NULL, 0, "ZigZag",12,5,3,1,1);
 
if((CalculateCurrentOrders_STOP(Symbol())==1)&&(CalculateCurrentOrders_OPEN(Symbol())==0))
  {
    Close_Order_BUYSTOP();
    Close_Order_SELLSTOP();
  }
if  (ZigZag_0>ZigZag_1)
{  
if((CalculateCurrentOrders_STOP(Symbol())==0)&&(CalculateCurrentOrders_OPEN(Symbol())==0))
  {
    Lot_BUY=Nach_Lot;
    Ticket_Open_BUY=OrderSend(Symbol(),OP_BUY,Lot_BUY,Ask,3,ND(Bid-SL_BUY*Point),ND(Ask+TP_BUY*Point),Metka,magicnumber,0,Green);
    Cena_Otkr_BUY=ND(Ask);
    TP_Otkr_BUY=ND(Ask+TP_BUY*Point);
    SL_Otkr_BUY=ND(Bid-SL_BUY*Point);
    TP_Otkr_SELL=SL_Otkr_BUY;
    SL_Otkr_SELL=TP_Otkr_BUY;
    Cena_Otkr_SELL=ND(Ask-Shirina_Kanala_STOP*Point);
    Lot_SELL=Nach_Lot*2;
    Ticket_Open_SELLSTOP=OrderSend(Symbol(),OP_SELLSTOP,Lot_SELL,Cena_Otkr_SELL,3,SL_Otkr_SELL,TP_Otkr_SELL,Metka,magicnumber,0,Blue);
  }
}  
if((CalculateCurrentOrders_STOP(Symbol())==0)&&(CalculateCurrentOrders_OPEN(Symbol())==1))
  { 
    Lot_BUY=Nach_Lot*4;
    Ticket_Open_BUYSTOP=OrderSend(Symbol(),OP_BUYSTOP,Lot_BUY,Cena_Otkr_BUY,3,SL_Otkr_BUY,TP_Otkr_BUY,Metka,magicnumber,0,Blue);
  }
  
if((CalculateCurrentOrders_SELL(Symbol())==1)&&(CalculateCurrentOrders_BUY(Symbol())==2)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_SELL=Nach_Lot*8;
    Ticket_Open_SELLSTOP=OrderSend(Symbol(),OP_SELLSTOP,Lot_SELL,Cena_Otkr_SELL,3,SL_Otkr_SELL,TP_Otkr_SELL,Metka,magicnumber,0,Blue);
  }  
  
if((CalculateCurrentOrders_SELL(Symbol())==2)&&(CalculateCurrentOrders_BUY(Symbol())==2)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_BUY=Nach_Lot*16;
    Ticket_Open_BUYSTOP=OrderSend(Symbol(),OP_BUYSTOP,Lot_BUY,Cena_Otkr_BUY,3,SL_Otkr_BUY,TP_Otkr_BUY,Metka,magicnumber,0,Blue);
  }  
  
if((CalculateCurrentOrders_SELL(Symbol())==2)&&(CalculateCurrentOrders_BUY(Symbol())==3)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_SELL=Nach_Lot*32;
    Ticket_Open_SELLSTOP=OrderSend(Symbol(),OP_SELLSTOP,Lot_SELL,Cena_Otkr_SELL,3,SL_Otkr_SELL,TP_Otkr_SELL,Metka,magicnumber,0,Blue);
  }  
  
if((CalculateCurrentOrders_SELL(Symbol())==3)&&(CalculateCurrentOrders_BUY(Symbol())==3)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_BUY=Nach_Lot*64;
    Ticket_Open_BUYSTOP=OrderSend(Symbol(),OP_BUYSTOP,Lot_BUY,Cena_Otkr_BUY,3,SL_Otkr_BUY,TP_Otkr_BUY,Metka,magicnumber,0,Blue);
  }  

if((CalculateCurrentOrders_SELL(Symbol())==3)&&(CalculateCurrentOrders_BUY(Symbol())==4)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_SELL=Nach_Lot*128;
    Ticket_Open_SELLSTOP=OrderSend(Symbol(),OP_SELLSTOP,Lot_SELL,Cena_Otkr_SELL,3,SL_Otkr_SELL,TP_Otkr_SELL,Metka,magicnumber,0,Blue);
  }   
  
if((CalculateCurrentOrders_SELL(Symbol())==4)&&(CalculateCurrentOrders_BUY(Symbol())==4)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_BUY=Nach_Lot*256;
    Ticket_Open_BUYSTOP=OrderSend(Symbol(),OP_BUYSTOP,Lot_BUY,Cena_Otkr_BUY,3,SL_Otkr_BUY,TP_Otkr_BUY,Metka,magicnumber,0,Blue);
  } 
  
if((CalculateCurrentOrders_SELL(Symbol())==4)&&(CalculateCurrentOrders_BUY(Symbol())==5)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_SELL=Nach_Lot*512;
    Ticket_Open_SELLSTOP=OrderSend(Symbol(),OP_SELLSTOP,Lot_SELL,Cena_Otkr_SELL,3,SL_Otkr_SELL,TP_Otkr_SELL,Metka,magicnumber,0,Blue);
  } 
  
if((CalculateCurrentOrders_SELL(Symbol())==5)&&(CalculateCurrentOrders_BUY(Symbol())==5)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_BUY=Nach_Lot*1024;
    Ticket_Open_BUYSTOP=OrderSend(Symbol(),OP_BUYSTOP,Lot_BUY,Cena_Otkr_BUY,3,SL_Otkr_BUY,TP_Otkr_BUY,Metka,magicnumber,0,Blue);
  }
  
if((CalculateCurrentOrders_SELL(Symbol())==5)&&(CalculateCurrentOrders_BUY(Symbol())==6)&&(CalculateCurrentOrders_STOP(Symbol())==0))
  { 
    Lot_SELL=Nach_Lot*2048;
    Ticket_Open_SELLSTOP=OrderSend(Symbol(),OP_SELLSTOP,Lot_SELL,Cena_Otkr_SELL,3,SL_Otkr_SELL,TP_Otkr_SELL,Metka,magicnumber,0,Blue);
  }  
        
  /*
if((CalculateCurrentOrders_STOP(Symbol())==0)&&(CalculateCurrentOrders_OPEN(Symbol())==0))
  {
    if (Key_BUY==true) Ticket_Open_BUYSTOP=OrderSend(Symbol(),OP_BUYSTOP,Lot_BUY,Cena_Buy,3,SL_Buy,TP_Buy1,Metka,magicnumber,0,Blue);
    if (Key_SELL==true) Ticket_Open_SELLSTOP=OrderSend(Symbol(),OP_SELLSTOP,Lot_SELL,Cena_Sell,3,SL_Sell,TP_Sell1,Metka,magicnumber,0,Blue);
  }
  */
 
  
  
  
   return(0);
  }
// Окончание функции старта советника------------------------------------------------------------------------------------------------//

//***********************************************************************************************************************************//
// Функция определения количества отложенных стоп ордеров ---------------------------------------------------------------------------//
//***********************************************************************************************************************************//
int CalculateCurrentOrders_STOP(string symbol)
{
   int buys=0,sells=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber)
        {
         if(OrderType()==OP_BUYSTOP)  buys++;
         if(OrderType()==OP_SELLSTOP) sells++;
        }
     }
   return(buys+sells);   
}
// Окончание функции определения количества отложенных стоп ордеров------------------------------------------------------------------//

//***********************************************************************************************************************************//
// Функция определения количества открытых ордеров ----------------------------------------------------------------------------------//
//***********************************************************************************************************************************//
int CalculateCurrentOrders_OPEN(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
// Окончание функции определения количества открытых ордеров--------------------------------------------------------------------------//

//***********************************************************************************************************************************//
// Функция определения количества открытых ордеров BUY ------------------------------------------------------------------------------//
//***********************************************************************************************************************************//
int CalculateCurrentOrders_BUY(string symbol)
  {
   int buys_b=0,sells_b=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber)
        {
         if(OrderType()==OP_BUY)  buys_b++;
        }
     }
   if(buys_b>0) return(buys_b);
   else       return(-sells_b);
  }
// Окончание функции определения количества открытых ордеров BUY --------------------------------------------------------------------//

//***********************************************************************************************************************************//
// Функция определения количества открытых ордеров SELL -----------------------------------------------------------------------------//
//***********************************************************************************************************************************//
int CalculateCurrentOrders_SELL(string symbol)
  {
   int buys_s=0,sells_s=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber)
        {
         if(OrderType()==OP_SELL)  sells_s++;
        }
     }
   if(sells_s>0) return(sells_s);
   else       return(-buys_s);
  }
// Окончание функции определения количества открытых ордеров SELL -------------------------------------------------------------------//

//***********************************************************************************************************************************//
// Функция приведения значений к точности одного тика -------------------------------------------------------------------------------//
//***********************************************************************************************************************************//
double ND(double A)
{
 return(NormalizeDouble(A, Digits));
}
// Окончание функции приведения значений к точности одного тика ---------------------------------------------------------------------// 

//***********************************************************************************************************************************//
// Функция закрытия ордера BUYSTOP --------------------------------------------------------------------------------------------------//
//***********************************************************************************************************************************//
void Close_Order_BUYSTOP() 
{
  for(int f=0;f<OrdersTotal();f++)
    {
      if(OrderSelect(f,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=magicnumber || OrderSymbol()!=Symbol()) continue;
      if(OrderType()==OP_BUYSTOP) OrderDelete(OrderTicket());
    } 
}
// Окончание функции  закрытия ордера BUYSTOP ---------------------------------------------------------------------------------------//

//***********************************************************************************************************************************//
// Функция закрытия ордера SELLSTOP -------------------------------------------------------------------------------------------------//
//***********************************************************************************************************************************//
void Close_Order_SELLSTOP() 
{
  for(int f=0;f<OrdersTotal();f++)
    {
      if(OrderSelect(f,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=magicnumber || OrderSymbol()!=Symbol()) continue;
      if(OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket());
    } 
}
// Окончание функции  закрытия ордера SELLSTOP --------------------------------------------------------------------------------------//
 
Bueno, puedes poner un límite en el código, digamos 50 lotes, y seguir con un lote constante.
 
Lucas_SPb:

1.Comprueba el ZigZag (aunque también podrías añadir encontrar el punto inferior de la sangría)

2.Abrir una orden de compra

3.Colocar una orden de venta al mismo tiempo

4.Cuando se activa una orden de venta, abrimos una orden de compra, etc.

5.En este caso aumentamos el lote


Ahhhhhh, ya lo tengo, gracias, ahora será más fácil, el único problema con la prueba es que mi ordenador se congela hasta el infierno cuando pongo "todos los ticks".
 
emonh:

Ahhhhhh, ya lo tengo, gracias, ahora será más fácil, el único problema con la prueba es que mi ordenador se congela hasta el infierno cuando pongo "todos los ticks".
)))Tuve que poner un montón de artilugios en mi ordenador....))))
 
Probado en la demo )) error allí, en lugar de un asiento 0,02 abrió una bau pendiente 0,04
 
debería ser así
 
 
)))¿Qué has probado? ¿Poner el búho en el gráfico?
 
Lucas_SPb:
)))Tuve que poner un montón de travesuras en mi ordenador....))))

Lo siento, ¿poner qué?
 
Lucas_SPb:
)))¿Qué has probado? ¿Poner el búho en el gráfico?

¿a quién?