Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 136

 
ALXIMIKS:

No it won't, with every new tick the value of Flag will be true . https://book.mql4.com/ru/variables/types

You can either declare the variable globally, at the beginning of the program for example, outside of all functions.

Or make the variable static - static bool flag=true; .

Just remember that the variable is re-initialised on restart. So this approach is acceptable for a tester, but not for real trading.
 
Folks, could you suggest an indicator? It's based on two slides. And when it crosses it gives out the direction as arrows. Can't find it, thanks.
 
skyjet:

Thank you very much! And if we compare the opening and closing prices of each of the three bars, will the code change that much?

To clarify the problem. We need to compare the opening and closing of the same bar, i.e. whether bar number n is bearish or bullish. Throw the script below on the quotation window.

extern int n=4;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   for (int x=n; x>1; x--)
    {  
     if(Close[x]==Open[x])
      {
       Print("Бар номер ",n," плоский :)");
       continue;
      }
     if(Close[x]<Open[x])
      {
       Print("Бар номер ",n," медвежий");
       continue;
      }
     else // if(Close[x]>Open[x]) - В данном случае сравнение if можно пропустить
          // т.к. два случая (равно и меньше) уже обработаны
      {
       Print("Бар номер ",n," бычьий");
      }
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
paladin80:

To insert the code correctly here, click SRC and then the code there.

Throw this EA on the quote window.


I threw it in the window, like the indicator just writes the shift value as I understand it, but what should I add to the code so that I can add how many levels I need in the settings?
 
Danila_mactep:

I put it in the window, like the indicator just writes the shift value as I understand it, but what should I add to the code to be able to add to the settings how many levels I need?

It does not write a shift value. If memory serves me correctly, the code doesn't specify a shift, it just reads the value of the MAHA. So it outputs this value.

In order to see the shift value relative to the MA value, you need to set this value in external parameters and then output the MA value + shift value*Point for an upward shift and the MA value - shift value*Point for a downward shift.

 
Danila_mactep:

I threw it in the window, just like the indicator just writes the shift value as I understand it, but what should I add to the code so that I can add as many levels as I need in the settings?
extern int  sdvig=0;
//---
int init() 
{
  return(0);
}
//--------------
int start()
{
  double MA=iMA(NULL, 0, 12, 144, MODE_SMA, PRICE_CLOSE, sdvig);
  Comment("Для бара номер ",sdvig," значение МА = ",DoubleToStr(MA,Digits));
  return(0);
}
//--------------
int deinit()
{
  Comment("");
  return(0);
}
 
paladin80:


No, it's not. You need a shift up and down the MA by a given number of points. Not a bar shift in history.
 
artmedia70:

No, it's not. You need a shift up and down the MA by a given number of points. Not a bar shift in history.
extern int move=100; 
//---
int init() 
{
  return(0);
}
//--------------
int start()
{
  double MA=iMA(NULL, 0, 12, 144, MODE_SMA, PRICE_CLOSE, 0);
  double Sdvig=MA+(move*Point);
  Comment("Сдвиг на ",sdvig," пунктов от МА = ",DoubleToStr(Sdvig,Digits));
  return(0);
}
//--------------
int deinit()
{
  Comment("");
  return(0);
} 
 
paladin80:

And now in minus too... And he'll be happy :) Or will you leave it to him to "think" about how to shift down on its own?
 

And then he will also need to make the output of messages not by comments, but by objects, and in a bigger way...

A person will never learn to think in such a way.