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

 
Tretyakov Rostyslav #:
No script?
 
Vladimir Baskakov #:
No script?
No
 
Hello all. Can someone help to edit the EA. I need to remove the order opening function, so the EA will not open orders by itself, but only work with manually opened orders. Many thanks in advance.
Files:
 
Vladimir Baskakov #:
No script?

We take a zig-zag and in OnCalculace check its buffer for values usually greater than 0 (it means that the buffer stores the value of the extremum, low or high). We loop through the buffer using the

int OnCalculate( const int rates_total,      // размер входных таймсерий 
                 const int prev_calculated,  // обработано баров на предыдущем вызове 
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[]         // Spread 
) {
 // код зиг-зага
 ...
 if (prev_calculated > 0) // дальнейший код сработает только один раз
   return (rates_total);
 // обработка значений зиг-зага
 for (int i = rates_total - 1; i >= 0; i--) {
   if (zigZag[i] > 0) { // найден экстремум
     // сохраняем time[i] в любую удобную форму для дальнейшей работы
   }
 }
 return (rates_total);
}

the loop above (from right to left) is intended for MQL5

for MQL4 the loop will be from left to right

for (int i = 0; i < rates_total; i++)

The above examples give new time values first. To get the values senior in time first, use ArraySetAsSeries or reverse the direction of the loop.

Data can be retrieved from the script using iCustom, CopyTime or iTime as well as iBars (instead of rates_total).

 
Tretyakov Rostyslav #:

I must be misunderstanding something.

if i switch the function in

void OnTick()
  {
// Получим значение индикатора
   dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.
   
// Если нет открытых ордеров, то входим в условие
      if(CountOrders()==0)
     {

// Если появился сигнал на покупку, то откроем ордер на покупку
      if(bSignalBuy() == true)
         vOrderOpenBuy();

// Если появился сигнал на продажу, то откроем ордер на продажу
      if(bSignalSell() == true)
         vOrderOpenSell();
     } 
       DrawLABEL("nextlot",1,5,0,Color1(),StringConcatenate("CURRENT LOT: ",DoubleToStr(LOT(),2)));
       DrawLABEL("currentlot",1,5,0,Color2(),StringConcatenate("NEXT LOT: ",DoubleToStr(LOT(),2)));
       TrailingOrders();
  }

then stop and takeaway are instantly shifted an infinite number of times

Ifyou don't use TrailingOrders(); then nothing shifts.

My task was not to create a trailing move, but to move stop and takeout one/two times.

I've been "inventing" things all day today, so far nothing works.

 
законопослушный гражданин #:

I must be misunderstanding something.

if i switch the function in

then stop and takeaway are instantly shifted an infinite number of times

Ifyou don't use TrailingOrders(); then nothing shifts.

My task was not to create a trailing move, but to move stop and takeout one/two times.

I've been "inventing" things all day long, so far nothing works.

Trailing stop should work if the price moved in the direction of TP, and it should not do anything if the price rolls back. The SL level should go only in the direction of the TP and not roll back.

 
Mihail Matkovskij #:

A trailing stop should be triggered if the price moves in the direction of the TP and do nothing if the price pulls back. The SL level should only go in the direction of the TP and not roll back.

I know

I wrote.

there is an infinite number of stop and take positions instantly

2021.12.23 21:07:51.634 2021.12.21 21 21:12:20 111 AUDUSD,M15: Buy order modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:20 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71288 tp: 0.72038 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:18 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:18 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71268 tp: 0.72018 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:16 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:16 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71248 tp: 0.71998 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:15 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:15 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71228 tp: 0.71978 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:13 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:13 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71208 tp: 0.71958 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:11 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:11 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71188 tp: 0.71938 ok

2021.12.23 21:07:51.634 2021.12.21 12:12:10 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:10 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71168 tp: 0.71918 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:08 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:08 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71148 tp: 0.71898 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:06 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:06 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71128 tp: 0.71878 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:05 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:05 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71108 tp: 0.71858 ok

2021.12.23 21:07:51.634 2021.12.21 21 12:12:00 111 AUDUSD,M15: Modify Buy Order Successful!

2021.12.23 21:07:51.634 2021.12.21 21 21:12:00 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71088 tp: 0.71838 ok

2021.12.23 21:07:51.634 2021.12.21 12:11:53 111 AUDUSD,M15: Buy Order Modification successful!

2021.12.23 21:07:51.634 2021.12.21 12:11:53 111 AUDUSD,M15: modify #2 buy 0.02 AUDUSD at 0.71028 sl: 0.71068 tp: 0.71818

2021.12.23 21:07:51.634 2021.12.21 12:11:52 111 AUDUSD,M15: Modify Buy Order Successful!


 
законопослушный гражданин #:

I know.

I wrote.

the stop and take are moved instantly an infinite number of times

You should get the SL of the order being modified and compare it with the calculated SL. If they are equal, the robot should do nothing until the calculated SL exceeds the SL of the order being processed. How to compare two double values: either compare NodmalizeDouble(value, Digits) (of each value) or EqualDoubleshttps://www.mql5.com/ru/docs/basis/types/double

Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
  • www.mql5.com
Вещественные типы (double, float) - Типы данных - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
законопослушный гражданин #:

I know.


You set it correctly. Did you change anything inside the TrailingOrders() function?

 
Mihail Matkovskij #:

You should get the SL of the order being modified and compare it with the calculated SL. ...

In general, the rules are as follows.

  • The calculated SL is less than the order's SL (less favourable) - do nothing
  • The calculated SL is equal to the order's SL - do nothing
  • The calculated SL exceeds the order's SL (more profitable) - modify it with the calculated value
These trawl rules can be used to build almost any trawl with any SL calculation algorithm.