Features of the mql5 language, subtleties and tricks - page 63

 
Please advise, 4 has such a function, and how to implement it in MQL5?

It sets the flag to hide indicators called by the Expert Advisor.

void  HideTestIndicators
(
   bool hide // флаг
);

 
fxsaber:

This requires that an EA "wire" is running in parallel, i.e. an auxiliary chart is required.

The situation in the example is somewhat different: there is one chart and some EA is already running on it. And we want to run OrderSend through the indicator without opening new ones.

Of course, without DLL, in order to pass the Market.

I have cornered the order taking possibility panel in the owl for this purpose and sometimes I drop orders in manual mode, but they go as the owl takes them.

 
Konstantin Nikitin:

I have added a possibility to place orders in the owl and sometimes place orders in the manual mode, but they are placed the way the owl takes them.

In the beginning it was a good trick when the indicator itself runs an order-script on OBJ_CHART.

 

Postfix operators (operator ++ and operator --) are defined as

Forum on trading, automated trading systems and testing trading strategies

Need help to spot some slight error .

whroeder1, 2014.07.07 11:37


  1. Prefix operator++
    Postfix operator++
    RaRev* RaRev::operator++(void){         // prefix
    
    RaRev RaRev::operator++(int){               // postfix
 
Pavel Verveyko:
Please advise, there is such a function in 4, but how to implement it in MQL5?

Set the flag to hide indicators called by the Expert Advisor.


This is something like that, see help.

MQL5 Reference Guide / Custom Indicators / Indicator Styles in Examples / DRAW_NONE
 
For MQL4 adepts there is an ancient way to work with the TF in MQL5, in the usual style

Forum on trading, automated trading systems and testing trading strategies

Testing 'CopyTicks'

fxsaber, 2016.10.19 07:59

// Позволяет, как в 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)

Maybe someone may find the MQL4 approach useful in working with tick history as well

// Позволяет работать с тиковой историей в MQL4-стиле
struct TICK_HISTORY
{
  const string Symb;
  
  TICK_HISTORY( const string sSymb = NULL ) : Symb(sSymb)
  {
  }
  
  const MqlTick operator []( const int Pos ) const
  {
    static const MqlTick NullTick = {0};
    static MqlTick Ticks[];
    
    return((::CopyTicks(this.Symb, Ticks, COPY_TICKS_INFO, 0, Pos + 1) > Pos) ? Ticks[::ArraySize(Ticks) - Pos - 1] : NullTick);
  }
};

const TICK_HISTORY Tick;


Application

if (Tick[0].bid > Tick[100].bid) // сравниваем текущий и исторический тики
  Print("Hello World!");

if (High[0] > Close[100]) // https://www.mql5.com/ru/forum/42122/page24#comment_2904023
  Print("Hello World!");
 
Alexey Volchanskiy:

I think so, see help.

MQL5 Reference Guide / Custom Indicators / Indicator Styles in Examples / DRAW_NONE

Thanks a lot, I will try it, the SD said IndicatorRelease should do this

 

Who has encountered, how will it be more correct to arrange fields in the structure in terms of alignment?

struct A
  {
   uchar  arr[20];
   // тут поля заполнители
   double val;
  };

struct B
  {
   double val;
   // тут поля заполнители
   uchar  arr[20];
  };

In idea alignment in structures is from top to bottom, but we have an array, for which there is a memory allocation under 20 elements, it seems like way A will be correct
 
fxsaber:
For MQL4 adepts there is an ancient way of working with TF in MQL5, in the usual way

// Позволяет, как в 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)

Application...


That's a cool way to put a whole class into Macros. Too bad I can't work with such a class in the Debugger :-((

 
Konstantin:

If you have encountered a problem, what is the correct way to arrange fields in the structure in terms of alignment?

Alignment in structures is supposed to go from top to bottom, but we have an array that is allocated memory under 20 elements, so way A is kind of right

If you mean MQL, there is no alignment.

If you mean C++, struct B is better.

Anyway, in C++ alignment is up to the programmer anyway.