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

 

MakarFX , what function does this bind: what function does it perform ?


input int BarTrade = 5; // I understand that this is the number of the tracked periods of 5.

int TimeBarTrade=BarTrade*Period()*60; // how do I understand? Why is it multiplied by 60?

 
Alexey Belyakov:

MakarFX , what function does this bind: what function does it perform ?


input int BarTrade = 5; // I understand that this is the number of the tracked periods of 5.

int TimeBarTrade=BarTrade*Period()*60; // how do we understand? Why is it multiplied by 60?

BarTrade*Period()*60

number of bars * current timeframe * 60 seconds

i.e. bar quantity converted to seconds

 
MakarFX:

BarTrade*Period()*60

number of bars * current timeframe * 60 seconds

i.e. number of bars converted to seconds

You can do it this way.

int TimeBarTrade = PeriodSeconds()*BarTrade;
 
MakarFX:

If you exclude errors related to

MODE_STOPLEVEL, MODE_TRADEALLOWED, MODE_MINLOT, MODE_LOTSTEP, MODE_MAXLOT

then the owls won't be hitting the server.

Makar, thank you very much for pointing out what checks need to be done to avoid distressing the server and banning the EAJ.

Checks done like this

mod stop level for stop

         //ПРОВЕРКА НА МОДЕ СТОП ЛЕВЕЛ- МИНИМАЛЬНЫЙ УРОВЕНЬ СТОПА 
         if(sl<MarketInfo(Symbol(),MODE_STOPLEVEL)) // ЕСЛИ СТОПОЛС МЕНЬШЕ ЧЕМ МИНИМАЛЬНО ДОПУСТИМЫЙ УРОВЕНЬ ЕГО УСТАНОВКИ ТО 
         {
          sl= MarketInfo(Symbol(),MODE_STOPLEVEL);//СТОП  ЛОССУ ПРИСВАЕВАЕМ МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ ЕГО УСТАНОВКИ
         }

mod stop level for profit

      // ПРОВЕРКА ТЕЙК ПРОФИТА НА МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ УСТАНОВКИ
      
  if(tp<MarketInfo(Symbol(),MODE_STOPLEVEL)) // ЕСЛИ ПРОФИТ МЕНЬШЕ ЧЕМ МИНИМАЛЬНО ДОПУСТИМЫЙ УРОВЕНЬ ЕГО УСТАНОВКИ ТО 
         {
          tp= MarketInfo(Symbol(),MODE_STOPLEVEL);// ПРОФИТУ ПРИСВАЕВАЕМ МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ ЕГО УСТАНОВКИ
         }
         


Check for trade authorization

//---- ПРОВЕРКА НА РАЗРЕШЕНИЕ ТОРГОВ ПЕРЕД ОТКРЫТИЕМ ОРДЕРОВ
   if(MarketInfo(Symbol(),MODE_TRADEALLOWED)==true)
   {// начало есл торговля разрешена
  /*
куча проверок на условия открытия и само открытие ордеров
*/
} // КОЕНЦ ПРОВЕРКИ НА РАЗРЕШЕНИЕ ТОРГОВЛИ
          
          else //ИНАЧЕ ЕСЛИ ТОРГОВЛЯ НЕ РАЗРЕШЕНА 
          
          { // НАЧАЛО ЭЛС ЕСЛИ ТОРГИ НЕ РАЗРЕШЕНЫ 
          
          Print("ТОРГИ НЕ РАЗРЕШЕНЫ- ПЫТАТЬСЯ ОТКРЫТЬ ОРДЕРА НЕ БУДЕМ");
          }  // КОЕНЦ ЭЛС ЕСЛИ ТОРГИ НЕ РАЗРЕШЕНЫ

Checking for max and min lot

First I got max lot and min lot values in the variables like this

  double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT);   // МИНИМАЛЬНЫЙ ЛОТ РАЗРЕШЁННЫЙ БРОКЕРОМ
double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);     // МАКСИМАЛЬНЫЙ ЛОТ РАЗРЕШЁННЫЙ БРОКЕРОМ

And then I check somewhere below as I write the Grail

  if(lot<Min_Lot) lot=Min_Lot; //ЕСЛИ ЛОТ ПОЛУЧИЛСЯ МЕНЬШЕ ЧЕМ МИНИМАЛЬНЫЙ ЛОТ У БРОКЕРА ТО ЛОТ ПРИСВАЕМАЕМ МИНИМАЛЬНЫЙ ЛОТ У БРОКЕРА
if(lot>Max_Lot) lot=Max_Lot;  //ЕСЛИ ЛОТ ПОЛУЧИЛСЯ БОЛЬШЕ ЧЕМ МАКСИМАЛЬНЫЙ ЛОТ У БРОКЕРА ТО ОЛТ ПРИСВАЕВАЕМ МАКС ЛОТ У БРОКЕРА

Is this correct or am I wrong?

I didn't check for lot step change because lot is calculated as a percentage of deposit and there this value is multiplied by a point and normalized - this check may be omitted - right, or should I do it anyway? If we still need to check how to write this check?

The main point of all these checks is to always have the correct value of stop, profit, and lot size, so we can generally start opening orders. If all these parameters are OK, the Expert Advisor will not bother the server; do I understand this correctly?

 
DanilaMactep:

Thank you very much, Makar, for telling me what checks to do to avoid the server and banning the EAJ.


//ПРОВЕРКА НА МОДЕ СТОП ЛЕВЕЛ- МИНИМАЛЬНЫЙ УРОВЕНЬ СТОПА
// ПРОВЕРКА ТЕЙК ПРОФИТА НА МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ УСТАНОВКИ

There may be a 130 error here due to slippage.

I would do this

         //ПРОВЕРКА НА МОДЕ СТОП ЛЕВЕЛ- МИНИМАЛЬНЫЙ УРОВЕНЬ СТОПА 
         if(sl<MarketInfo(Symbol(),MODE_STOPLEVEL)*1.5) // ЕСЛИ СТОПОЛС МЕНЬШЕ ЧЕМ МИНИМАЛЬНО ДОПУСТИМЫЙ УРОВЕНЬ ЕГО УСТАНОВКИ ТО 
         {
          sl= MarketInfo(Symbol(),MODE_STOPLEVEL)*1.5;//СТОП  ЛОССУ ПРИСВАЕВАЕМ МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ ЕГО УСТАНОВКИ
         }
      // ПРОВЕРКА ТЕЙК ПРОФИТА НА МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ УСТАНОВКИ
      
  if(tp<MarketInfo(Symbol(),MODE_STOPLEVEL)*1.5) // ЕСЛИ ПРОФИТ МЕНЬШЕ ЧЕМ МИНИМАЛЬНО ДОПУСТИМЫЙ УРОВЕНЬ ЕГО УСТАНОВКИ ТО 
         {
          tp= MarketInfo(Symbol(),MODE_STOPLEVEL)*1.5;// ПРОФИТУ ПРИСВАЕВАЕМ МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ ЕГО УСТАНОВКИ
         }
         
 

Hello all, has anyone had a problem with dangling points on the chart found through iHighest/iLowest?

Prehistory: I have minimal programming experience, I'm writing an indicator in mql4 which should display the points on the chart, found by the conditions of if and connect them with lines. Logically, it looks for the points correctly, but draws them with an offset, then for 2 bars, then for 3 bars. How do I fight this? I have attached the file with the code too.


int start()
  {
   int counted_bars=IndicatorCounted(); //хранит количество посчитанных индикатором баров. Функция IndicatorCounted() возвращает количество неизмененных баров после прошлого вызова функции start().
   int n,limit;
   int val_index;
   
  if(counted_bars>0)
      counted_bars--;
   limit=Bars-counted_bars; //количество последних баров, которые нужно пересчитать.
   if(limit>barsToProcess)
      limit=barsToProcess;

   for(n=0; n<=limit; n++)
     {
      if((Close[n+1]>Open[n+1] && Open[n+2]>=Close[n+2]) || (Close[n+1]>Open[n+1] && Open[n+3]>Close[n+3]))
        {
         val_index=iLowest(NULL,0,MODE_LOW,3,n+1);
         myAZBuffer[n]=Low[val_index];
         ExtLowBuffer[n]=Low[val_index];
        }
      else
         if((Open[n+1]>Close[n+1] && Close[n+2]>=Open[n+2]) || (Close[n+1]<Open[n+1] && Close[n+3]>Open[n+3]))
          {
            val_index=iHighest(NULL,0,MODE_HIGH,3,n+1);
            myAZBuffer[n]=High[val_index];
            ExtHighBuffer[n]=High[val_index];
           }
     }
   return (0);
  }
Files:
AZforum.mq4  8 kb
 
azolotta:

Hello all, has anyone had a problem with dangling points on the chart found through iHighest/iLowest?

Prehistory: I have minimal programming experience, I'm writing an indicator in mql4 which should display the points on the chart, found by the conditions of if and connect them with lines. Logically, it looks for the points correctly, but draws them with an offset, then for 2 bars, then for 3 bars. I have attached the file with the code as well.


The points are drawn correctly, without an offset.

If the condition is fulfilled and iHighest/iLowest are bigger or smaller than the current High/Low

it draws


 
MakarFX:

points are drawn correctly, without offset

if the condition is met and iHighest/iLowest is greater or less than the current High / Low

then draws


So, I think I'm starting to realise my mistake) So, in order to visually display these points in the right place, I need to enter some separate counter instead of n for myAZBuffer[n], ExtLowBuffer[n], ExtHighBuffer[n] ? but how to do this
 
azolotta:
So, I think I'm beginning to realize my mistake) It turns out that to visually display these points in the right place, I need to enter some separate counter instead of n for myAZBuffer[n], ExtLowBuffer[n], ExtHighBuffer[n] ? but how to do it

no, you understand correctly.

the condition uses two or three bars from the history,

that's why it draws after 2-3 bars when the condition is met

 
MakarFX:

no, you understand correctly.

the condition uses two or three bars from the history,

that's why it draws after 2-3 bars when the condition is met

OK, then how do I rework the code if I need, for example, to choose the highest high from the last 3 bars (that meet the conditions in if) and place a point on it (right on this high!), then also find the low point.