Discussion of article "The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor"

 

New article The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor is published:

This article explains how to use the major functionalities of the MQL5 Standard Library Trade Classes in writing Expert Advisors which implements position closing and modifying, pending order placing and deletion and verifying of Margin before placing a trade. We have also demonstrated how Trade classes can be used to obtain order and deal details.

Author: Samuel

 

Very useful article for me. Everything is much easier if you use libraries !

Request to developers: write a class to work with High[i] , Low[i]. Open[i], Close[i]. I think this class will be useful for everyone! I have solved this problem for myself, but I'm not sure that it is correct, because testing takes a lot of time....

 
Check out the Timeseries Class Group section
 
#include <Indicators\Series.mqh>

double High[];
 CiHigh z;

why this code gives an error

'1.mq5' 1.mq5 1 1

'Series.mqh' Series.mqh 1 1

'ArrayObj.mqh' ArrayObj.mqh 1 1

'Array.mqh' Array.mqh 1 1

'Object.mqh' Object.mqh 1 1

'StdLibErr.mqh' StdLibErr.mqh 1 1

'ArrayDouble.mqh' ArrayDouble.mqh 1 1

'CiHigh' - declaration without type 1.mq5 12 2

1 error(s), 0 warning(s) 2 1

in all the examples it is not necessary to declare the type...

if it is not difficult to write how to get

Print High[2], for example.

 
dimeon:

why this code gives an error


it is not necessary to declare the type in all the examples...

if it is not difficult, please write how to get

Print High[2], for example.

there is a misprint in the documentation. This class is located in the TimeSeries.mqh file.

Example of use (the script prints the last three Highs of the current chart):

#include <Indicators\TimeSeries.mqh>
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   double High[];
   CiHigh z;
   int count=3;
   if(z.Create(_Symbol,_Period)==true)
     {
      if(z.GetData(0,count,High)==count)
        {
         for(int i=0; i<count; i++) Print(i,"=",High[i]);
        }
      else
         Print("Failed to retrieve ",count," time-series data.");
     }
   else Print("Error creating time series.");
  }
//+------------------------------------------------------------------+
 
Quantum:

there is a misprint in the documentation. This class is in the TimeSeries.mqh file.

Example of use (the script outputs the last three Highs of the current chart):

Thank you very much ! I have been racking my brains !
 

I understand that everyone programs for himself and his needs, but I fundamentally do not like the Group of time series classes, because they basically all consist of one method and descriptive part more than functionality, and usually it is necessary to have all time series for a particular tool, I made one class in which there are all time series for the necessary tool, in the methods is made by paging history, approximately like this:

struct str_bars{
   datetime    time[];     // Timeseries array containing the opening time of each bar of the current chart
   double      open[];     // Timeseries array containing opening prices of each bar of the current chart.
   double      close[];    // Timeseries array containing closing prices of each bar of the current chart.
   double      high[];     // Timeseries array containing the maximum prices of each bar of the current chart.
   double      low[];      // A time series array containing the minimum prices of each bar of the current chart.
};
struct str_info{
   double   point;         // Current instrument point size in quote currency
   int      spread;        // Current spread
};
//____________________________________________________________________
class currency {
   public:
//---- данные      
      MqlTick TICK;        // tick data
      str_bars  BAR;       // time series data
      str_info INFO;       // tool information
      int error;
//---- методы      
      int create(string sym,ENUM_TIMEFRAMES period, int numbars);
      int refresh(void);
   private:
      string            symbol;
      ENUM_TIMEFRAMES   per;
      int               num;
      datetime          lastbar_time;
      int               tmpint1,tmpint2;
      int ch_load(void);
};
//____________________________________________________________________

I work with my class only in the part of already prepared data, and of course the class itself receives data by calling the refresh() method

 
Useful article!
 

there's an inaccuracy in the article

double lot_price = myaccount.MarginCheck(_Symbol,otype,Lot); // lot price/number of margin required

should be

   double lot_price=myaccount.MarginCheck(_Symbol,otype,Lot,price);  //--- lot price/number of margin required
 

Great article. Many thanks to the author. I would also like to write a check of Stop_Level before placing an order, and a check of spread value. The thing is that if the spread is floating, then at high values you can not enter the market, because it is not profitable. This will help the Expert Advisor not to trade during the news. I would also like to check for deviation - the reasoning is similar. And there is also a question about the library: what is a function (what kind of process does it denote and describe)?

FreezeLevel

Gets the distance of freezing trade operations in points.

int FreezeLevel() const

in simple language - please explain it if you know it.

And one more question. We can find out the limits, for example, Stop_Level at the current moment (let's say 10 points). We place a pending order with SL=10 points. After, for example, an hour the price reaches the price specified in the order, but Stop_Level at this moment is equal to, for example, 15 pips. What will happen - will the pending order work or will it be rejected? In addition, when the price reaches the price specified in the order, but the spread has changed - does it mean that entry or exit is possible at a worse price in relation to the expected price that was at the time of opening the order, or the order will not work at all?

 

What am I doing wrong ? Why is the Bid not printed ?

Here is the log of work


2011.01.31 20:20:18 00(EURUSD,M1) EURUSD 0

here is the code

#include <Trade\SymbolInfo.mqh>  //--- CSymbolInfo class
CSymbolInfo    my_symbol;        //--- Object of CSymbolInfo class
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
int OnInit()
  {   return(0);  }
//+------------------------------------------------------------------+
//| Expert deinitialisation function|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {  }
//+------------------------------------------------------------------+
//| Expert tick function|
//+------------------------------------------------------------------+
void OnTick()
  {
   my_symbol.Name(_Symbol);
   my_symbol.Refresh();
   Print(_Symbol," ",my_symbol.Bid());
  }
//+------------------------------------------------------------------+