A question for MQL connoisseurs - page 10

 
Rita:

Oh, I was still thinking :)

If

if (NumberOfPositions(NULL, OP_BUY,Magic)>=2 && NumberOfPositions(NULL,OP_SELL,Magic)>=2) {
 for{
// а сюда счетчик, по которому 2 раза пройдет
                    ClosePosFirstProfit(NULL,OP_BUY, Magic);
                    ClosePosFirstProfit(NULL,OP_SELL, Magic);
}
}
Nah?

 
Thank you Abzasc, I will give it a try.
 
Hello! I just recently started to learn how to write in MQL4 and I don't understand how (with which command) one can connect not a built-in indicator, but one taken from Code Base to an Expert Advisor? Can you tell me please!
 
savage_pinguin:
Hello! I just recently started to learn how to write in MQL4 and I don't understand how (with which command) one can connect not a built-in indicator, but one taken from Code Base to an Expert Advisor? Can you tell me please!

iCustom() to help
 

Afternoon.

 if  ( Accumulation2MA_1<=MA_1  &&    Accumulation2MA_0>MA_0 )   {
// если линии пересеклись - открываем позицию
   ticket=OrderSend(Symbol(),0,Lot,Ask,Slippage,Bid-SL*Point,Ask+TP*Point,
                                             "Хи-Хи",MagicNum,0,CLR_NONE);
     if(ticket < 0) { Print("Ошибка открытия ордера BUY #", GetLastError()); 
               Sleep(10000);   return (0); }
   }

The Expert Advisor uses a custom indicator Accumulation2MA, on which the MA indicator is attached in iMAOnArray mode.

Entry/exit signals is line crossing!

I do not understand what is the matter. But half of the entry/exit signals are "brazenly" inhorized! No reason!

The same thing when closing:

 for (int v=0; v<OrdersTotal(); v++)                             {//сортируем       
      if (OrderSelect(v, SELECT_BY_POS, MODE_TRADES))               {//перебираем           
        if (OrderSymbol()==Symbol()&& OrderMagicNumber()==MagicNum)   {//выбираем 
//-----------------------------------------------------                  
if (OrderType() == OP_SELL) {//если линии пересеклись, то закрываем: 
      if( Accumulation2MA_1<=MA_1  &&    Accumulation2MA_0>MA_0 )   {
                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // закрываем позицию
                 return(0); // выходим
                }   
......

Almost half of the trades are missed in this way. Can you tell me what's wrong?

The conditions are the simplest! The lines are clearly moving! But positions are not always open/closed! The journal is "silent".

I showed them with arrows.

//------заполняем массив значениями Accumulation2MA -----------------
double Accumulation2MA[50];
int    i=0;  while (i<50)  {
Accumulation2MA[i]= iCustom(NULL, 0,"Accumulation2MA_v03",SMA,FMA,0, i);
                  i++;     }
//------Вешаем на Accumulation2MA - линию МА ---------------
ArraySetAsSeries(Accumulation2MA,true);
double MA_0 = iMAOnArray(Accumulation2MA,0,MA_Period,0,MODE_SMA,0);
double MA_1 = iMAOnArray(Accumulation2MA,0,MA_Period,0,MODE_SMA,1);
double Accumulation2MA_0=iCustom(NULL, 0,"Accumulation2MA_v03",SMA,FMA,0,0);
double Accumulation2MA_1=iCustom(NULL, 0,"Accumulation2MA_v03",SMA,FMA,0,1);
 
Rita:

Afternoon.

The Expert Advisor uses a custom indicator Accumulation2MA, on which the MA indicator is attached in iMAOnArray mode.

Entry/exit signals is line crossing!

I do not understand what is the matter. But half of the entry/exit signals are "brazenly" inhorized! No reason!

The same thing when closing:

Almost half of the trades are missed in this way. Can you tell me what's wrong?

The conditions are the simplest! The lines are clearly moving! But positions are not always open/closed! The journal is "silent".

Showed them with arrows.

Perhaps this may happen when skipping ticks. I.e. while Start() is running, a new tick arrives (in which conditions would be fulfilled), but it is ignored while Start() is running.

In the next tick the conditions are not fulfilled - they are gone.

In fact, crossing indicator lines is a very uncomfortable signal, I haven't used it for a long time. It is better to subtract one indicator from another and trace a zero crossing. However, it's a matter of taste.

 
Rita:

Afternoon.

The Expert Advisor uses a custom indicator Accumulation2MA, on which the MA indicator is attached in iMAOnArray mode.

Entry/exit signals is line crossing!

I do not understand what is the matter. But half of the entry/exit signals are "blatantly" inhorized! No reason!

The same thing when closing:

Almost half of the trades are missed in this way. Can you tell me what's wrong?

The conditions are the simplest! The lines are clearly moving! But positions are not always open/closed! The journal is "silent".

Perhaps it is easier to calculate the second line in the indicator. Then the problems should disappear

 
MetaDriver:

This can probably happen when ticks are skipped. I.e. while Start() is running, a new tick arrives (in which conditions would have been met), but it is ignored while Start() is running.

In the next tick the conditions are not fulfilled - it's done.

In fact, crossing indicator lines is a very uncomfortable signal, I haven't used it for a long time. It is better to subtract one indicator from another and monitor zero crossing. It is a matter of taste.

Isn't subtraction and tracing zero crossing practically the same as in the above example?

//если линии пересеклись, то закрываем: 
      if( Accumulation2MA_1<=MA_1  &&    Accumulation2MA_0>MA_0 )   {

At first sight, it seems to be a slap in the face!

What makes you think that "zero crossing" will work better?

 
VINAR:

It may be easier to calculate the second line in the indicator. Then the problems should disappear

I do not quite understand what do you mean by "calculate the second line in the indicator"? Can you explain?

============================

I am now testing the Expert Advisor again (by the way, it works by opening prices) and I am amazed to see that it works perfectly at the moment! Signal skipping has almost disappeared!

And yesterday it missed half of the signals in the same mt4! Some kind of miracles....

 
Rita:

Isn't subtraction and tracing a zero crossing practically the same thing as

At first glance, it's head-on as well as head-on!

What makes you think that "crossing zero" would work better?

In theory, whatever. In practice:

1) we can easily check the difference between the market position recommended by the indicator and the actual position in the orders. I.e. the resulting indicator will show a ready-made curve that can be interpreted as "positive/negative"=="go up/down". It's very convenient for upside down systems.

2) There is a possibility of convenient refinement of the signal (multiplication by coefficients, intersections with other criterion lines, etc.).

So, like I said, it's a matter of taste. :)