Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 707

 
Roman Shiredchenko:

it's not a joke and that's not how I mock.

Look at the picture carefully before you post heresy.

The topic is so trite that it's disgusting to read it... ...then the visuals are missing, then the optimization...

Widen the window wider and you'll be happy. Do not confuse which window to expand.

 
ilvic:

The problem is the screen resolution.

Thank you very much, started to guess by looking at the pictures...

 
ilvic:

The problem is the screen resolution.

Thanks again. Everything works, the problem was in the text size (font) display


 
Good afternoon, help find a bug in the code for the indicator , comments are in the code , blue does not want to draw as I want to write. Idea to find the smallest Low value in time range from last update to last update High green line. Thanks.
{

if(prev_calculated<1) limit=rates_total-1;
if(prev_calculated>0)limit=rates_total-prev_calculated;
for(i=limit; i>=0; i--)
{
yesterday_weekday = TimeDayOfWeek(iTime(Symbol(),0,i+1))-TimeDayOfWeek(iTime(Symbol(),0,i));
if (yesterday_weekday !=0) // находим открытие нового дня
{

BH=open[i];BL=open[i]; // переменные ХАЙ ЛОУ  
Closebar=open[i]; // искомая переменная 
NHT=time[i]; // переменная время последнего обновления ХАЙ
PHT=time[i]; // переменная время предпоследнего обновления хай
}
CloseD[i]=Closebar; // буфер отрисовки искомая переменная СИНИЙ ЦВЕТ
HD[i]=BH;  // буфер отрисовки ХАЙ
LD[i]=BL; // буфер отрисовки ЛОУ

if (Fun_New_Bar==false)  // находим закрытие бара                             
    {                                             
     if (Prev_Time==0) 
     {
        Prev_Time=time[i];
        Fun_New_Bar=false;
     }
   if(Prev_Time!=time[i])                        
     {
      Prev_Time=time[i];

if(iHigh(NULL,0,i+1)>BH) // проверяем есть ли обновление Хай
{
C=PHT; // присвоим переменной время предыдущего бара обновления Хай 
NHT=iTime(NULL,0,i+1); // находим время обновления Хай
Pshift=iBarShift(NULL,0,C); // находим индекс бара предыдущего обновления Хай 
P=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,Pshift,i+1)); // находим наименьшее значение Лоу от обновления Хай настоящего до предыдущего (искомая величина) 
BH=iHigh(NULL,0,i+1); // прорисовываем Хай новый
Closebar=P; // прорисовываем искомую величину 
PHT=NHT; // сохраняем время последнего обновления Хай
} 
     
                             
      Fun_New_Bar=false; // ждем закрытие нового бара                           
     }
     }

Comment( NHT, C , Pshift ); // проверка

if(low[i]<BL)  BL=low[i]; // в процессе

}
   return(rates_total);
  }


 
Good afternoon! Help on the EA! I need to make a normal trailing stop, which works in steps, and moves SL to Breakeven!!! I.e.: An order is opened and after 25 (figuratively speaking) points in the right direction, SL isimmediately set tothe opening price!

i have this code, but it follows the price and stops at the open price!


bool tkt;
  for (int i = 0; i < OrdersTotal(); i++) 
  {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
      if (OrderType() == OP_BUY)
      {
      if(NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(OrderOpenPrice(), Digits) && 
      NormalizeDouble(Ask - OrderStopLoss(), Digits) > NormalizeDouble(TrailingStop * Point, Digits))
      tkt = OrderModify(OrderTicket(), 0, Ask - TrailingStop * Point, OrderTakeProfit(), OrderExpiration(), clrNONE);
      Print("Error setting Buy trailing stop: ", GetLastError());
      }
         
      if (OrderType() == OP_SELL)
      {
      if(NormalizeDouble(OrderStopLoss(),Digits) > NormalizeDouble(OrderOpenPrice(), Digits) && 
      NormalizeDouble(OrderStopLoss() - Bid, Digits) > NormalizeDouble(TrailingStop * Point, Digits))
      tkt = OrderModify(OrderTicket(), 0, Bid + TrailingStop * Point, OrderTakeProfit(), OrderExpiration(), clrNONE);
      Print("Error setting Sell trailing stop: ", GetLastError());
      }  
           }
   } 
i've been banging my head against the wall for a week now!
 
ponochka:
Good afternoon! Help on the EA! I need to make a normal trailing stop, which works in steps, and moves SL to Breakeven!!! I.e.: An order is opened and after 25 (figuratively speaking) points in the right direction, SL isimmediately set tothe opening price!

i have this code, but it follows the price and stops at the open price!


i've been banging my head against the wall for a week now!

Please, wrote for myself and use them as well.

//======= Глобальные переменные

extern bool   UseBreakeven       = true;          //Использование безубытка
extern int    Breakeven          = 20;            //Профит безубытка
extern int    ValueBreak         = 3;             //Безубыток
extern bool   UseTrailingStop    = true;          //использование трейлинг стопа
extern int    TrailingStop       = 40;            //Величина трала
extern int    TrailingStep       = 3;             //Шиг трала 

double SL, TP;

//нннннннннннн Функция перевода в безубыток нннннннннннннннннннннннннннннннннннннннннннн
void BreakevenModify()
{ 
   int    i;
   double sl;
   
   int total = OrdersTotal();
   
   if(UseBreakeven)
   {
      for(i = total-1; i >= 0; i--)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         { 
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) 
            {
               if(OrderType() == OP_BUY)
               {
                  if(OrderStopLoss() < OrderOpenPrice() && (OrderOpenPrice() + Breakeven*point) <= Bid)
                  {   
                     sl = NormalizeDouble(OrderOpenPrice() + ValueBreak*point, Digits);
                     
                     OrderModifyX(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, 0);
                  } 
               }
            }
         }
      
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         { 
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) 
            { 
               if(OrderType() == OP_SELL)
               {
                  if(OrderStopLoss() > OrderOpenPrice() && (OrderOpenPrice() - Breakeven*point) >= Ask)
                  { 
                     sl = NormalizeDouble(OrderOpenPrice() - ValueBreak*point, Digits);
                     
                     OrderModifyX(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, 0);
                  } 
               }
            }
         }
      }
   }
}
//нннннннннннн Функция трейлинг стопа ннннннннннннннннннннннннннннннннннннннннннннннннннннн
void TrailingStopLoss()
{   
   int    i;
   double sl;
   
   int total = OrdersTotal();
   
   if(UseTrailingStop)
   {
      for(i = total-1; i >= 0; i--)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
            {
               if(OrderType() == OP_BUY) 
               {
                  if((OrderOpenPrice() + TakeProfit3*point) <= Bid)
                  {
                     if(OrderStopLoss() > OrderOpenPrice() && OrderStopLoss() + (TrailingStop + TrailingStep)*point <= Bid)
                     {
                        sl = NormalizeDouble(OrderStopLoss() + TrailingStep*point, Digits);
                        
                        OrderModifyX(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, 0);
                     } 
                  }  
               }
            }
         }
      
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
            {     
               if(OrderType() == OP_SELL)
               {
                  if((OrderOpenPrice() - TakeProfit3*point) >= Ask)
                  {
                     if(OrderStopLoss() < OrderOpenPrice() && OrderStopLoss() - (TrailingStop + TrailingStep)*point >= Ask)
                     {
                        sl = NormalizeDouble(OrderStopLoss() - TrailingStep*point, Digits);
                        
                        OrderModifyX(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, 0);
                     } 
                  }  
               } 
            }
         }
      }
   }
}


I wrote for myself and use them.

 
Youri Lazurenko:

Please, I wrote it for myself and use it for myself.

this is for tester only :-)

In real life, it is very dangerous to trawl based on Bid, Ask

 
Rustam Bikbulatov:
Hi guys. Can you please tell me why I have a couple dozen orders that are closed in staggered order or differently? How should I fix it? Is there a method of closing them all at once?

Close at the end, not at the beginning.

for(int i=OrdersTotal()-1; i>=0; i--)
Or I should make my own list and close orders by it?
 
Taras Slobodyanik:

close at the end, not at the beginning

or do you make your own list and use it to close?

how do you make a list?

 
Hi guys. Can you please tell me why I have a couple of dozens of orders closing in staggered order or differently at all? How do I fix it? Is there a method to close them all at once?
void CloseOrdB(){  
     for(int i=0;i<OrdersTotal();i++){
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
     if(OrderSymbol()==Symbol() && OrderMagicNumber()==456){    
if(OrderClose(OrderTicket(),OrderLots(),Bid,3,clrBlue)){CloseOrdB();}}}} }
Reason: