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

 
azolotta:

Thanks, that really solved the problem!!!

If you don't mind, can you tell me what kind of construction should be added to make it not display two highs/lows in a row, but a variability (high-low-high)? I understand that I need a check, like "if the previous array element was high, then the second consecutive high should not be included in the array, and wait for low", but how should it be done?

I have already explained it to you.

 
DanilaMactep:

Good afternoon, all. I've got the check on, but I forgot to test it. Good thing I remembered about it today... Here's this check on the mod stop level

When tested this check gives the errors shown in the screenshot below

And what's interesting as I was advised I added to this check domination by 1.5 as follows


This addition does not solve the problem appeared test gives errors as in the screenshot below.

If this check on the mod stop level commented out, there are no errors. What is the error on the check, please advise? Without it, you can not start the grail on the real world - will be banned immediatelyL O_o

I think the error is not in the test, but where you prescribed it

and also here you can remove "*1,5"

if(tp<MarketInfo(Symbol(),MODE_STOPLEVEL)*1,5)
if(sl<MarketInfo(Symbol(),MODE_STOPLEVEL)*1,5)
 
DanilaMactep:

Good afternoon, all. I've got the check on, but I forgot to test it. Good thing I remembered about it today... Here's this check on the mod stop level

When tested this check gives the errors shown in the screenshot below

And what's interesting as I was advised I added to this check domination by 1.5 as follows


This addition does not solve the problem appeared test gives errors as in the screenshot below.

If this check on the mod stop level commented out, there are no errors. What is the error on the check, please advise? Without it, you can not start the grail on the real world - will be banned immediatelyL O_o

Check that it returns a stop level, it is often 0.

   int    Stoplevel = (int)MarketInfo(Symbol(), MODE_STOPLEVEL);
   int    Spread = (int)MarketInfo(Symbol(), MODE_SPREAD);

   if (Stoplevel == 0) Stoplevel = 2 * Spread;

   

So like this.

 
Alekseu Fedotov:

Check what the stop level returns , it is often 0.

Like this.

He doesn't need that, it's "if less than stoplevel".

 
DanilaMactep:

Good afternoon, all.

Gross mistake... didn't see it straight away.

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;// ПРОФИТУ ПРИСВАЕВАЕМ МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ ЕГО УСТАНОВКИ
 }

It's supposed to be DOTS.

 
azolotta:
Not to display two highs/lows in a row, but to be variable (high-low-high)

You can do it in a simple way. Declare a global variable and change it depending on events.

int direction=0;

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
   {


   for(n=0; n<=limit; n++)
     {
      if(direction>=0 && ((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];
         direction=-1;
        }
      else
         if(direction<=0 && ((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];
            direction=1;
           }
      }
.......

In indicators, use OnCalculate function and all its variables.

And Start is already unfashionable:)

 
Aleksei Stepanenko:

You can do it in a simple way. Declare a global variable and change it depending on events.

In indicators, use OnCalculate function and all its variables.

And Start is out of fashion:)

Thank you! It's a cool way!)

got it aboutOnCalculate, I'll be in it))

 
Aleksei Stepanenko:

You can do it in a simple way. Declare a global variable and change it depending on events.

In indicators, use OnCalculate function and all its variables.

And Start is already unfashionable:)

not work, the new high/low will not take them into account
 

Good afternoon. When I call the indicator in my Expert Advisor, there is an error indicated in the box. Why does it occur? And not always. It works fine on

terminal, it works fine.


 
Sergey Fionin:

Good afternoon. When I call the indicator in my Expert Advisor, there is an error indicated in the box. Why does it occur? And not always. It works fine on

terminal, it works fine.


This is a write-in violation, a system write-in ban.