[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 83

 

Please help. The version of the EA on page 82 works (written for opening 1 type of trade), but the one below (for all order types) turned out to have an error: it opens orders on every tick.

What is my mistake?

extern int     Magic       = 0;        //уникальный номер ордера
extern bool    BUY         = false;    //открыть ордер BUY
extern bool    BUY_STOP    = false;    //поставить ордер BUY STOP
extern bool    BUY_LIMIT   = false;    //поставить ордер BUY LIMIT
extern bool    SELL        = false;    //открыть ордер SELL
extern bool    SELL_STOP   = false;    //поставить ордер SELL STOP
extern bool    SELL_LIMIT  = false;    //поставить ордер SELL LIMIT
extern double  Lot         = 0.1;      //объем ордера
extern int     takeprofit  = 0;        //уровень выставления TP, если 0, то TP не выставляется
extern int     stoploss    = 0;        //уровень выставления SL, если 0, то SL не выставляется
extern int     DistanceSet = 40;       //расстояние от рынка для отложенника
extern int     slippage    = 3;        //максимально допустимое отклонение цены для рыночных ордеров
//--------------------------------------------------------------------
double SL,TP;
//--------------------------------------------------------------------
int start()
{
   if (BUY)
   {
      if (takeprofit!=0) TP  = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
      if (stoploss!=0)   SL  = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;     
      OPENORDER ("Buy");
   }
   if (SELL)
   {  
      if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
      if (stoploss!=0)   SL = NormalizeDouble(Bid + stoploss*Point,Digits);  else SL=0;              
      OPENORDER ("Sell");
   }
   if (BUY_STOP)
   {
      if (takeprofit!=0) TP  = NormalizeDouble(Ask + DistanceSet*Point + takeprofit*Point,Digits); else TP=0;
      if (stoploss!=0)   SL  = NormalizeDouble(Ask + DistanceSet*Point - stoploss*Point,Digits); else SL=0;     
      OPENORDER ("Buy Stop");
   }
   if (SELL_STOP)
   {  
      if (takeprofit!=0) TP = NormalizeDouble(Bid - DistanceSet*Point - takeprofit*Point,Digits); else TP=0;
      if (stoploss!=0)   SL = NormalizeDouble(Bid - DistanceSet*Point + stoploss*Point,Digits);  else SL=0;              
      OPENORDER ("Sell Stop");
   }
   if (BUY_LIMIT)
   {
      if (takeprofit!=0) TP  = NormalizeDouble(Ask - DistanceSet*Point + takeprofit*Point,Digits); else TP=0;
      if (stoploss!=0)   SL  = NormalizeDouble(Ask - DistanceSet*Point - stoploss*Point,Digits); else SL=0;     
      OPENORDER ("Buy Limit");
   }
   if (SELL_LIMIT)
   {  
      if (takeprofit!=0) TP = NormalizeDouble(Bid + DistanceSet*Point - takeprofit*Point,Digits); else TP=0;
      if (stoploss!=0)   SL = NormalizeDouble(Bid + DistanceSet*Point + stoploss*Point,Digits);  else SL=0;              
      OPENORDER ("Sell Limit");
   }
return(0);
}
void OPENORDER(string ord)
{
int ticket = -1;
int err;
while (ticket<0)
{
if (ord=="Buy") ticket=OrderSend(Symbol(),OP_BUY, Lot,NormalizeDouble(Ask,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell") ticket=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Buy Stop" ) ticket=OrderSend(Symbol(),OP_BUYSTOP, Lot,NormalizeDouble(Ask + DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell Stop") ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid - DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Buy Limit" ) ticket=OrderSend(Symbol(),OP_BUYLIMIT, Lot,NormalizeDouble(Ask - DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell Limit") ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lot,NormalizeDouble(Bid + DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ticket==-1) //неудачная попытка
{  
ShowERROR();
err++;Sleep(2000);RefreshRates();
}
}
return;
}
void ShowERROR()
{
   int err=GetLastError();
   switch ( err )
   {                  
      case 1:   return;
      case 2:   Alert("Нет связи с торговым сервером ",Symbol());return;
      case 3:   Alert("Error неправильные параметры ",Symbol());return;
      case 130: Alert("Error близкие стопы   Ticket ",Symbol());return;
      case 134: Alert("Недостаточно денег   ",Symbol());return;
      case 146: Alert("Error Подсистема торговли занята ",Symbol());return;
      case 129: Alert("Error Неправильная цена ",Symbol());return;
      case 131: Alert("Error Неправильный объем ",Symbol());return;
      case 4200:Alert("Error Объект уже существует ",Symbol());return;
   }
}

I thank you in advance.

 
nemo811:

Please help. The version of the EA on page 82 works (written for opening 1 type of trade), but the one below (for all order types) turned out to have an error: it opens orders on every tick.

What is my mistake?

I thank you in advance.

where in the code is the control of the number of orders?

 
nemo811:


In short, what is the idea behind the EA? at first glance, this code will not open trades at all.

I changed the values of the flags, trades opened once, but I don't understand what this EA is doing)))

 
nemo811:


extern int Magic = 0; //уникальный номер ордера
extern bool BUY = true; //открыть ордер BUY
extern bool BUY_STOP = true; //поставить ордер BUY STOP
extern bool BUY_LIMIT = true; //поставить ордер BUY LIMIT
extern bool SELL = true; //открыть ордер SELL
extern bool SELL_STOP = true; //поставить ордер SELL STOP
extern bool SELL_LIMIT = true; //поставить ордер SELL LIMIT
extern double Lot = 0.1; //объем ордера
extern int takeprofit = 0; //уровень выставления TP, если 0, то TP не выставляется
extern int stoploss = 0; //уровень выставления SL, если 0, то SL не выставляется
extern int DistanceSet = 40; //расстояние от рынка для отложенника
extern int slippage = 3; //максимально допустимое отклонение цены для рыночных ордеров
//--------------------------------------------------------------------
double SL,TP;
//--------------------------------------------------------------------
int start()
{
if (BUY)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;
OPENORDER ("Buy");
BUY=false;
}
if (SELL)
{
if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Bid + stoploss*Point,Digits); else SL=0;
OPENORDER ("Sell");
SELL=false;
}
if (BUY_STOP)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask + DistanceSet*Point + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask + DistanceSet*Point - stoploss*Point,Digits); else SL=0;
OPENORDER ("Buy Stop");
BUY_STOP=false;

}
if (SELL_STOP)
{
if (takeprofit!=0) TP = NormalizeDouble(Bid - DistanceSet*Point - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Bid - DistanceSet*Point + stoploss*Point,Digits); else SL=0;
OPENORDER ("Sell Stop");
SELL_STOP=false;
}
if (BUY_LIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask - DistanceSet*Point + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - DistanceSet*Point - stoploss*Point,Digits); else SL=0;
OPENORDER ("Buy Limit");
BUY_LIMIT=false;
}
if (SELL_LIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(Bid + DistanceSet*Point - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Bid + DistanceSet*Point + stoploss*Point,Digits); else SL=0;
OPENORDER ("Sell Limit");
SELL_LIMIT=false;
}
return(0);
}
void OPENORDER(string ord)
{
int ticket = -1;
int err;
while (ticket<0)
{
if (ord=="Buy") ticket=OrderSend(Symbol(),OP_BUY, Lot,NormalizeDouble(Ask,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell") ticket=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Buy Stop" ) ticket=OrderSend(Symbol(),OP_BUYSTOP, Lot,NormalizeDouble(Ask + DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell Stop") ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid - DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Buy Limit" ) ticket=OrderSend(Symbol(),OP_BUYLIMIT, Lot,NormalizeDouble(Ask - DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell Limit") ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lot,NormalizeDouble(Bid + DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ticket==-1) //неудачная попытка
{
ShowERROR();
err++;Sleep(2000);RefreshRates();
}
}
return;
}
void ShowERROR()
{
int err=GetLastError();
switch ( err )
{
case 1: return;
case 2: Alert("Нет связи с торговым сервером ",Symbol());return;
case 3: Alert("Error неправильные параметры ",Symbol());return;
case 130: Alert("Error близкие стопы Ticket ",Symbol());return;
case 134: Alert("Недостаточно денег ",Symbol());return;
case 146: Alert("Error Подсистема торговли занята ",Symbol());return;
case 129: Alert("Error Неправильная цена ",Symbol());return;
case 131: Alert("Error Неправильный объем ",Symbol());return;
case 4200:Alert("Error Объект уже существует ",Symbol());return;
}
}

In general, it opens orders once and places one pending order at a time.

 
NameLess:


In short, what is the idea behind the EA? at first glance, this code will not open trades at all.

I changed the values of the flags, trades opened once, but I don't understand what this EA is doing)))


))))This is a part of another EA. Putting it together brick by brick ))
 
The point of the other one is to take the total profit or profit separately for each pair (convenient when using diversification). + Trailing what you can and other functionality. This is based on the drknn universal_1_7 Expert Advisor
 
nemo811:
The point of the other one is to take the total profit or profit separately for each pair (convenient when using diversification). + Trailing what you can and other functionality. We are using drknn universal_1_7 Expert Advisor as a base.

This code will just sum up the spread and difference between openings, sootvno the current version will accumulate minus. i don't know where the profit will be taken)
 
NameLess:

This code will simply add up the spread and the difference between openings, so the current version will accumulate minus.)

This is a slightly outdated version of what I'm working on now. The author drknn gave me permission to post it.
Files:
 
NameLess:

In general, it opens orders once and places one pending order at a time.

Thank you, it works! )) We still need to determine how to control the number of orders
 
nemo811:
Thank you, it worked! )) Still need to determine how to control the number of orders


))) It is a thankless task to scratch someone else's code to understand how it works. If you trust the EA I wish you good luck and everything will work out)

I personally invented a bicycle and wrote my owl from scratch, but I know where and how things work and know why they don't work and where to look for errors)

That's the way it is.)