Useful features from KimIV - page 74

 
allarkoms писал(а) >>

Hello Igor!

I'm trying to learn MQL4 and due to lack of description of the language operators one problem has left me stumped. I have an indicator with 8 buffers of accumulated data. I need it to be displayed with the period of the next timeframe at a timeframe I have chosen. For this purpose, it uses iCustom() operator. But it returns a double value and I don't know how and whether iCustom can and should be used in this case.

I really hope for your help.

Hello, Alexey!

You should make a new indicator that would use the iCustom() function. Assign the values returned by this function to the buffers of the new indicator.

 
ProfitTrader писал(а) >>

Hello Igor! And good afternoon to all!

I am interested in the code which should be entered so that the Expert Advisor does not make any more trades on that day when it closes a trade...

I've found it but it does not work in the strategy tester, I want to test it, what code should I use instead?

Then I should add it in the entry condition.

Hello, Sergiy!

I do not even see why the use of my function given by you cannot work in the strategy tester. If it is still relevant to you, I suggest that you post the entire code of the EA. Let's try to figure it out...

 

There are questions about differences and peculiarities of SetOrder() and OpenPosition() functions in error handling.


SetOrder():

      if ( err==8 || err==141) Sleep(1000*100);
      if ( err!=135 && err!=138) Sleep(1000*7.7);
      if ( err==139 || err==140 || err==148) break;

OpenPositions(): Errors 8 (ERR_TOO_FREQUENT_REQUESTS), 138 (ERR_REQUOTE) and 139 (ERR_ORDER_LOCKED) are not handled, unlike SetOrder():

      if ( err==141) Sleep(1000*100);
      if ( err!=135) Sleep(1000*7.7);
      if ( err==140 || err==148 || err==4110 || err==4111) break;

In SetOrder() error 130 (ERR_INVALID_STOPS) is handled by stop correction, but in OpenPositions() it is not handled in any way.

In OpenPositions() processing 145 (ERR_TRADE_MODIFY_DENIED) is present. The sense of processing it here is not clear.

Besides, on the first page of this discussion there is a mention of errors handling of which is missing in both functions:

KimIV >>:

На паузу 7.7 секунды нарвутся ошибки 129 (Неправильная цена bid или ask), 130 (Неправильные стопы), 134 (Недостаточно денег), 136 (Нет цен).

Also, there is no processing of other (probably, important in this case) errors, for example, 3 (ERR_INVALID_TRADE_PARAMETERS), 6 (ERR_NO_CONNECTION), 7 (ERR_NOT_ENOUGH_RIGHTS), 9 ERR_MALFUNCTIONAL_TRADE, 137 (ERR_BROKER_BUSY), 144(!), 4067 (ERR_TRADE_ERROR), 4106 (ERR_UNKNOWN_SYMBOL), 4107 (ERR_INVALID_PRICE_PARAM)


Igor, please comment on the described points.

The SetOrder() and OpenPositions() functions I have mentioned are taken from b-Orders library of 05.11.2008 and b-Positions of 29.10.2008 from kimiv.ru site.


I would like to add. If error 5 ERR_OLD_VERSION occurs, it can be handled in the same way as 2, 64, 65, 133; 4109 ERR_TRADE_NOT_ALLOWED in the same way as 4110, 4111

 
What does error 142 mean? I couldn't find it in the error codes. I would also like to know if it is possible to reduce delays somewhere for the pipsator?
 
khorosh >> :
What does error 142 mean? I didn't find it in error codes.

https://docs.mql4.com/ru/trading/errors

142 An order has been queued up. This is not an error, but one of the communication codes between the client terminal and the trading server. This code can be received in a rare case, when during trading operation performance there was a break in connection and the connection was restored afterwards. It must be handled in the same way as error 128.

 
Здравствуйте Игорь! И всем Добрый день!

I am interested in a question about GEPs, they are not described in the book, and there is a lot new in this topic. I would like to know how to make a trade open every time a GEP appears. I want to know how to open orders when GEP appears. I have it, but for some reason this algorithm fails to work, what is the error here?

extern int     Magic                = 777;
extern int       TP                 = 6;
extern int       SL                 = 2;
extern double  Lots                 = 0.01;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
if(  iClose(NULL,0,1)>iOpen(NULL,0,0) && (iClose(NULL,0,1)-iOpen(NULL,0,0))>1*Point )
   { //покупаем
  OrderSend(Symbol(),OP_BUY, Lots,Ask,2,Bid- SL*Point,Bid+ TP*Point,
                                               NULL, Magic,0,CLR_NONE);}
                                                  
if(  iClose(NULL,0,1)<iOpen(NULL,0,0) && (iClose(NULL,0,1)-iOpen(NULL,0,0))>1*Point )
   { //продаем
 OrderSend(Symbol(),OP_SELL, Lots,Bid,2,Ask+ SL*Point,Ask- TP*Point,
                                              NULL, Magic,0,CLR_NONE);}

   return(0);
  }
//+------------------------------------------------------------------+
 
In the first condition the first sub-condition is superfluous, the second condition on selling is not feasible at all. Is one point a gap? You have a slippage of 2 and a stop of 2, there could be overlaps.
 
Roger >> :
In the first condition the first sub-condition is redundant, the second condition on sale is impossible. Is one point a gap? Your slippage is 2 and the stop is 2.

Thank you, but why is the first preface superfluous? You want a buy position to open when a new bar is above the close of the previous one and vice versa. >> Is that the right way?

if(  iClose(NULL,0,1)<iOpen(NULL,0,0) && (iClose(NULL,0,1)-iOpen(NULL,0,0))>2*Point )
   { //покупаем
  OrderSend(Symbol(),OP_BUY, Lots,Ask,2,Bid- SL*Point,Bid+ TP*Point,
                                               NULL, Magic,0,CLR_NONE);}
                                                  
if(  iClose(NULL,0,1)>iOpen(NULL,0,0) && (iClose(NULL,0,1)-iOpen(NULL,0,0))>2*Point )
   { //продаем
 OrderSend(Symbol(),OP_SELL, Lots,Bid,2,Ask+ SL*Point,Ask- TP*Point,
                                              NULL, Magic,0,CLR_NONE);}
 
That's right
if(  iClose(NULL,0,1)-iOpen(NULL,0,0)>10*Point )
   { //покупаем
  OrderSend(Symbol(),OP_BUY, Lots,Ask,2,Bid- SL*Point,Bid+ TP*Point,
                                               NULL, Magic,0,CLR_NONE);}
                                                  
if( iOpen(NULL,0,0)- iClose(NULL,0,1)>10*Point )
   { //продаем
OrderSend(Symbol(),OP_SELL, Lots,Bid,2,Ask+ SL*Point,Ask- TP*Point,
                                              NULL, Magic,0,CLR_NONE);}
 
Roger >> :
>> That's right.

As far as I understand the first condition automatically implies that the closing price is greater than the opening price. In the second, it is the other way round??????