strategy refinement of the advisor - page 5

 
https://www.mql5.com/ru/code/7108 Here is also some interesting material on trawls
 

3. trailing the standard 'step' trailing.

void TrailingStairs(int ticket,int trldistance,int trlstep)

This type of trailing is a modification of the standard one. If I'm not mistaken, once similar model was created byKimIV(but because relative is nicer... :) It differs from the standard trailing, in that trailing stop-loss is not transferred by points (for example, trailing stop-loss at distance of 30 points at +31, at +32 - by +2, etc.).For example, trailing at a distance of 40 pips and the stoploss distance of 10 pips, when we reach +40 stoploss will be moved to +10 pips and nothing will change until we reach +50 profit (40 pips + step) (i.e. we give a certain freedom to the price, which is the point of this algorithm), and only at +50 stoploss will be moved from +10 to +20 pips, at +60 stoploss will be moved to +30 pips and so on.

Parameters:
ticket -
the unique order number (chosen before calling the function withOrderSelect());
trldistance - the distance from the current rate (points) at which we "trawl" (no less than MarketInfo(Symbol(),MODE_STOPLEVEL));
trlstep - the "step" of changing the stop loss (points) (no less than 1).

Iftrlstep=1, this function will not differ from the standard trailing stop. The main "feature" of this algorithm, again, is in providing the rate with some "freedom of movement" - Stop Loss is raised only after the price has "wandered around". This trailing algorithm I first encountered in the description of "Moving Channels" tactics rules already mentioned by V. Barishpolts.

=================

This one in the Expert Advisor is interesting

 
//+------------------------------------------------------------------+
//| ТРЕЙЛИНГ СТАНДАРТНЫЙ-СТУПЕНЧАСТЫЙ                                |
//| Функции передаётся тикет позиции, расстояние от курса открытия,  |
//| на котором трейлинг запускается (пунктов) и "шаг", с которым он  |
//| переносится (пунктов)                                            |
//| Пример: при +30 стоп на +10, при +40 - стоп на +20 и т.д.        |
//+------------------------------------------------------------------+
 
void TrailingStairs(int ticket,int trldistance,int trlstep)
   { 
   
   double nextstair; // ближайшее значение курса, при котором будем менять стоплосс
 
   // проверяем переданные значения
   if ((trldistance<MarketInfo(Symbol(),MODE_STOPLEVEL)) || (trlstep<1) || (trldistance<trlstep) || (ticket==0) || (!OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)))
      {
      Print("Трейлинг функцией TrailingStairs() невозможен из-за некорректности значений переданных ей аргументов.");
      return(0);
      } 
   
   // если длинная позиция (OP_BUY)
   if (OrderType()==OP_BUY)
      {
      // расчитываем, при каком значении курса следует скорректировать стоплосс
      // если стоплосс ниже открытия или равен 0 (не выставлен), то ближайший уровень = курс открытия + trldistance + спрэд
      if ((OrderStopLoss()==0) || (OrderStopLoss()<OrderOpenPrice()))
      nextstair = OrderOpenPrice() + trldistance*Point;
         
      // иначе ближайший уровень = текущий стоплосс + trldistance + trlstep + спрэд
      else
      nextstair = OrderStopLoss() + trldistance*Point;
 
      // если текущий курс (Bid) >= nextstair и новый стоплосс точно лучше текущего, корректируем последний
      if (Bid>=nextstair)
         {
         if ((OrderStopLoss()==0) || (OrderStopLoss()<OrderOpenPrice()) && (OrderOpenPrice() + trlstep*Point<Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)) 
            {
            if (!OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice() + trlstep*Point,OrderTakeProfit(),OrderExpiration()))
            Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
            }
         }
      else
         {
         if (!OrderModify(ticket,OrderOpenPrice(),OrderStopLoss() + trlstep*Point,OrderTakeProfit(),OrderExpiration()))
         Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
         }
      }
      
   // если короткая позиция (OP_SELL)
   if (OrderType()==OP_SELL)
      { 
      // расчитываем, при каком значении курса следует скорректировать стоплосс
      // если стоплосс ниже открытия или равен 0 (не выставлен), то ближайший уровень = курс открытия + trldistance + спрэд
      if ((OrderStopLoss()==0) || (OrderStopLoss()>OrderOpenPrice()))
      nextstair = OrderOpenPrice() - (trldistance + MarketInfo(Symbol(),MODE_SPREAD))*Point;
      
      // иначе ближайший уровень = текущий стоплосс + trldistance + trlstep + спрэд
      else
      nextstair = OrderStopLoss() - (trldistance + MarketInfo(Symbol(),MODE_SPREAD))*Point;
       
      // если текущий курс (Аск) >= nextstair и новый стоплосс точно лучше текущего, корректируем последний
      if (Ask<=nextstair)
         {
         if ((OrderStopLoss()==0) || (OrderStopLoss()>OrderOpenPrice()) && (OrderOpenPrice() - (trlstep + MarketInfo(Symbol(),MODE_SPREAD))*Point>Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point))
            {
            if (!OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice() - (trlstep + MarketInfo(Symbol(),MODE_SPREAD))*Point,OrderTakeProfit(),OrderExpiration()))
            Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
            }
         }
      else
         {
         if (!OrderModify(ticket,OrderOpenPrice(),OrderStopLoss()- (trlstep + MarketInfo(Symbol(),MODE_SPREAD))*Point,OrderTakeProfit(),OrderExpiration()))
         Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
         }
      }      
   }

Here is its full code, to be inserted in place of

//+------------------------------------------------------------------+
void TrailingStairs(int ticket,int trldistance)
   {
    int Spred=Ask - Bid;
    if (OrderType()==OP_BUY)
      {
       if((Bid-OrderOpenPrice())>(Point*trldistance))
         {
          if(OrderStopLoss()<Bid-Point*trldistance || (OrderStopLoss()==0))
            {
             OrderModify(ticket,OrderOpenPrice(),Bid-Point*trldistance,OrderTakeProfit(),0,Green);
             if (PolLots)
             if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
               {
               OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Ask,3,Green);
               }
             else
               {
               OrderClose(ticket,OrderLots(),Ask,3,Green);
               }
            }
         }
       }
     else
       {
        if((OrderOpenPrice()-Ask)>(Point*trldistance))
          {
           if((OrderStopLoss()>(Ask+Point*trldistance)) || (OrderStopLoss()==0))
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trldistance,OrderTakeProfit(),0,Red);
             if (PolLots)
             if (NormalizeDouble(OrderLots()/2,2)>MarketInfo(Symbol(), MODE_MINLOT))
               {
               OrderClose(ticket,NormalizeDouble(OrderLots()/2,2),Bid,3,Green);
               }
             else
               {
               OrderClose(ticket,OrderLots(),Bid,3,Green);
               }
             }
          }
        }
    }


this

 

I recommend to start modifying an EA you like, rather than inserting it into your own - the result will be almost the same, but there will be less hassle.

Besides, the ability to read and understand someone else's code will come in handy...

 
ktest0:

I recommend to start modifying an EA you like, rather than inserting it into your own - the result will be almost the same, but there will be less hassle.

Besides, the ability to read and understand someone else's code will come in handy...

As long as he wants to have, not be able to!
 
borilunad:
As long as he wants to have, not be able to!

))) That's where everyone starts... And then - the further into the woods, the fatter the partisans...
 

Can you please tell me how to write a code in an EA,
Which would form the High and Low for a certain period (e.g. 10.45 - 11.15)?

I have switched on the EA at 9.00 -> when 10.45 it switched on and started monitoring. When a bar closed (e.g. 15 min chart) 11.15 it reads and continues monitoring, for example I have identified High and Low and put orders not too far from these lines.

I thank you in advance for your feedback.

 
Well, you can spin the councillor....
 

I can't figure out what principle is used to connect the tralling.

It should, in fact, just work

 
IRIP:

I can't figure out what principle is used to connect the tralling.

After all, it should, in fact, just work.


Nothing and no one will "just work".

You need to understand what this particular trail searches for, on what conditions it trawls, with what step, if there are any additional conditions.

If you take apart trawl code, everything becomes clear, but the principle "plug and play" does not lead to good results....