Help me write an EA, thanks in advance - page 13

 
To the top, of course, let everyone think.
 
edikjefimov:
I think the indicators will only delay the opening of the order, and a lot of false signals, I think it is better to put Shto closed at 000.00 when reaching, say, 12 orders or Shto change this number may be at will and depending on the deposit
By the way - not a bad idea !!!!!!
 
//+------------------------------------------------------------------+
//|                                                        Канал.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);

  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
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 orders volume
   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));
}
// Окончание функции приведения значений к точности одного тика ---------------------------------------------------------------------// 
Files:
gwssp.mq4  12 kb
 
)))By the way - zig-zagging is more interesting!!!!!
 
OK, I'm starting to realise that I'm losing my grasp of how this strategy works, if you could describe it again point by point and specifically with examples.
 
)))Everything is exactly the same algorithm as described by Edik!!!!
 
Lucas_SPb:
)))Everything is absolutely according to the algorithm described by Edik!!!!


I understand it, but now I think I see it a bit differently, I don't even know how to explain it in words...

That's why I asked again and point by point.

%)

 

Here :

 

1.Check the ZigZag (although you could also add finding the bottom point of the indent)

2.Open a buy order

3.Place a sell order at the same time

4.When a Sell order triggers, we open a Buy order, etc.

5.In this case we increase the lot

 
sorry - not all the code !!!! Didn't get to the end of the selection