Questions from Beginners MQL5 MT5 MetaTrader 5 - page 794

 
007yurik:

Friends, help a dummy. The idea is as follows: When the "Ind" variable reaches the set level, switch to waiting for "Value" to change direction while waiting for "Ind" to no longer reconcile.


   if(Ind[0]<=-0.7)
     {
      while(Value[3]>Value[2]<Value[1])
        {
         if(CopyBuffer(InpInd2_Handle,1,SignalBar,3,Value)<=0)
           {
            Recount=true;
            return;
           }
        }
      if(BuyPosOpen) BUY_Open=true;
     }


What is the right way to do this?

   if(Ind[0]<=-0.7)
     {

replace by

   bool pravda=false;

   if(pravda || Ind[0]<=-0.7)
     {
      pravda=true;
 
007yurik:

...


pivomoe:

...


Please insert code correctly:Insert code correctly on the forum

 
007yurik:

Friends, help a dummy. The idea is as follows: When the "Ind" variable reaches the set level, we switch to waiting for "Value" to change direction, without checking "Ind" again while waiting.

What is the correct way to do it???

I think there is a mistake here :

while(Value[3]>Value[2]<Value[1])

It has to be:

while(Value[3]>Value[2] §§ Value[2]<Value[1])
 
Ivan Ivanov:

I think there's a mistake here:

It has to be:

Where on the keyboard is the paragraph symbol? I thought it had been disabled...

while(Value[3]>Value[2] §§  Value[2]<Value[1])
 
Ivan Ivanov:

I think there's a mistake here:

It should be:

This is not generally the case, you can get by with
while(Value[2]<Value[1])
 
pivomoe:

replace with

If I did it correctly (which is doubtful), it hangs, apparently it won't come out of the loop.
 bool pravda=false;

   if(pravda || Ind[0]<=-0.7)
   pravda=true;
   
   {   
      
      while(Value[2]<Value[1])
         {
         if(CopyBuffer(InpInd2_Handle,1,SignalBar,3,Value)<=0) {Recount=true; return;}                 
          }
          
         if(BuyPosOpen) BUY_Open=true;     
                                                  
         if(SellPosClose) SELL_Close=true;
         UpSignalTime=datetime(SeriesInfoInteger(Symbol(),InpInd_Timeframe,SERIES_LASTBAR_DATE))+TimeShiftSec;
         }
 
007yurik:
If I did the right thing (which is doubtful) it hangs, apparently it won't come out of cycle.
 if(pravda || Ind[0]<=-0.7)
 {
   pravda=true;         
 
pivomoe:
Tried it, same thing. When Ind goes over the level, it hangs.
 
1
007yurik:
Tried it, same thing. When Ind exceeds level, it hangs.

1. Make bool pravda global.(https://www.mql5.com/ru/docs/basis/variables/global)

2. Replace while with if.

3. When if (from step 2) works, return pravda=false.

Документация по MQL5: Основы языка / Переменные / Глобальные переменные
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
  • www.mql5.com
Глобальные переменные создаются путем размещения их объявлений вне описания какой-либо функции. Глобальные переменные определяются на том же уровне, что и функции, т. е. не локальны ни в каком блоке. Область видимости глобальных переменных - вся программа, глобальные переменные доступны из всех функций, определенных в программе...
 
007yurik:

Friends, help a dummy. The idea is as follows: When the "Ind" variable reaches a given level, we switch to waiting for "Value" to change direction while waiting for "Ind" not to be checked again.




What is the right way to do it???

Are you sure that the indicator is recalculated during the while loop?
Reason: