Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1273

 

What the code would look like in Mql5

if (Close[1]-Open[1]>visota*Point)

{

....

}

 
Dmitriywelcome:

What the code would look like in Mql5

It looks like this

   MqlRates rates[2]; 
   int copied = CopyRates(NULL, 0, 0, 2, rates);
   if(rates[0].close-rates[0].open > visota*_Point)
     {
      /******************/
     }
Screw in the necessary checks yourself.
 
Dmitriywelcome:

How would the code look like in Mql5

You can also do this

if(iClose(NULL,0,1)-iOpen(NULL,0,1)>visota*_Point)
 

you can do that too:

#define  Close(shift) iClose(NULL,0,shift)
#define  Open(shift)  iOpen(NULL,0,shift)
....
if (Close(1) - Open(1) > visota*_Point)
 

44

Hello. I'm trying to write a condition, but I'm doing something wrong. Please help me figure it out.

When the price crosses the indicator line from bottom to top, I open a buy position.

I am trying to prescribe a condition for the same bar:

If the close price of the current candle is higher than the indicator line and the Bid price on any of the subsequent bars is higher than the indicator line - ...condition 1

How to do it correctly?

if (m_position.Select(_Symbol))         //проверка на наличие позиции
   { 
    Print ("Позиция открыта");
    if(m_position.PositionType()==POSITION_TYPE_BUY)
    {
     Print ("Открыта на покупку");
     if (close_1 > Sig_Up[0])   //цена закрытия текущей свечи выше линии индикатора 
       {
        int cl = 4;
     if (cl && Bid > Sig_Up[0])  // Bid больше линии индикатора
       {
        ....
     }
     }                        
     }                                                           
     }
 
Igor Makanu:

you can do it that way:

Don't do anything with the numbering of the bars. I.e. the code from a four with the first bar for a five will also have the first bar without numbering reversal?

 
Valeriy Yastremskiy:

and don't do anything with the numbering of the bars. I.e. the code from four with the first bar for five will also be with the first bar without numbering reversal?

From the documentation

shift

[in] The index of the time series value to be obtained (shifted relative to the current bar by the specified number of bars back).


A shift of 0 relative to the current bar will be the current bar. And if it is 1, it will be the previous one.

 
Igor Makanu:

you can do it that way:

Close[shift] has square brackets. failed.

Alexey Viktorov:

From the documentation

Relative to the current bar, shift 0 and it will be the current bar. And if it is 1, it will be the previous one.

Am I right in understanding that the time series numbering in 5 is the same as in 4?

 
Valeriy Yastremskiy:

Close[shift] has square brackets. failed.

It worked, here is code from@fxsaber

// Позволяет, как в MT4, работать с таймсериями: Open[Pos], High[Pos], Low[Pos], Close[Pos], Time[Pos], Volume[Pos].
// А так же задает привычные MT4-функции: iOpen, iHigh, iLow, iClose, iTime, iVolume.
#define  DEFINE_TIMESERIE(NAME,FUNC,T)                                                                         \
  class CLASS##NAME                                                                                           \
  {                                                                                                           \
  public:                                                                                                     \
    static T Get(const string Symb,const int TimeFrame,const int iShift) \
    {                                                                                                         \
      T tValue[];                                                                                             \
      return((Copy##FUNC((Symb == NULL) ? _Symbol : Symb, _Period, iShift, 1, tValue) > 0) ? tValue[0] : -1); \
    }                                                                                                         \
    T operator[](const int iPos) const                                                                     \
    {                                                                                                         \
      return(CLASS##NAME::Get(_Symbol, _Period, iPos));                                                       \
    }                                                                                                         \
  };                                                                                                          \
  CLASS##NAME  NAME;                                                                                           \
  T i##NAME(const string Symb,const int TimeFrame,const int iShift) \
  {                                                                                                           \
    return(CLASS##NAME::Get(Symb,  TimeFrame, iShift));                                                        \
  }
//+------------------------------------------------------------------+
DEFINE_TIMESERIE(Volume, TickVolume, long)
DEFINE_TIMESERIE(Time, Time, datetime)
DEFINE_TIMESERIE(Open, Open, double)
DEFINE_TIMESERIE(High, High, double)
DEFINE_TIMESERIE(Low, Low, double)
DEFINE_TIMESERIE(Close, Close, double)
//+------------------------------------------------------------------+

you can now write Close[1] > Close[2 ].

 
Sergey:


Hello. I'm trying to write a condition, but I'm doing something wrong. Please help me figure it out.

When the price crosses the indicator line from bottom to top, I open a buy position.

I am trying to prescribe a condition for the same bar:

If the close price of the current candle is higher than the indicator line and the Bid price on any of the subsequent bars is higher than the indicator line - ...condition 1

How to do it correctly?

the terminal has a sample of Moving Average.mq5

If I understand correctly, you need it like this ?

Photo by

Reason: