Questions from Beginners MQL5 MT5 MetaTrader 5 - page 879

 
lil_lil:

Thank you.

What's wrong now?

I suggested starting with HistorySelectByPosition and you've shoved it somewhere deep into the ifs...

There can only be one position per symbol in a netting account. Get the position ID, get the list of trades involved in the formation of this position and count them by trade direction and order type.

 
Alexey Kozitsyn:

Artyom, I'll repeat the question, please answer it:


Didn't see the question :)

Honestly - I don't remember, but I think it works in MT5 - doesn't it?

But in the tester I was putting the pending orders... And I worked with the mouse. But I may have got confused and I was working with the mouse on a real chart and using buttons in the tester...

I won't guess - I dismantled all my library to small screws about half a year ago, and I won't be able to check it quickly any more. I've postponed its rebuilding till about autumn. So, it's faster just to check work of event model OnChartEvent() in the tester. But I have not time for that yet - sorry :)

 
Artyom Trishkin:

Didn't see the question :)

Honestly - I don't remember, but I think it works in MT5 - doesn't it?

But I've been putting the pending orders in the tester... And I worked with the mouse. But it may well be that I must have got confused and I was working with the mouse on a real chart and using buttons in the tester...

I won't guess - I dismantled all my library to small screws about half a year ago, and I won't be able to check it quickly any more. I have postponed its rebuild till about autumn. So, it's faster just to check work of event model OnChartEvent() in the tester. But I have not time for that yet - sorry :)

There's all the test code:

switch( id )
{
default:
   Print( __FUNCTION__,": id = "+EnumToString( (ENUM_CHART_EVENT)id ) );
}

no response, unfortunately, in the tester. In the OnChartEvent() function. Called from the Expert Advisor.

 
Alexey Kozitsyn:

The whole test code is there:

no response, unfortunately, in the tester. In the OnChartEvent() function.

And CHART_EVENT_MOUSE_MOVE=true is set?
 
Alexey Viktorov:

I suggested to start with HistorySelectByPosition, but you shoved it somewhere deep into ifs...

In a netting account there can only be one position per symbol. Get the position ID, get the list of deals forming this position and count them by deal direction and order type.

I did, because I want to make a universal counting function, for netting and hedging, or is it impossible?

 
Artyom Trishkin:
Is CHART_EVENT_MOUSE_MOVE=true set?

No, but this is unlikely to solve the problem, as ctrl, shift and other keys have been pressed... there was no reaction.

 
lil_lil:

Stuck in because I want to make a universal counting function, for netting and hedging, or is that impossible?

It is possible. But the approaches are different, and they need to be properly planned first, rather than dumping everything into one line of code...

 
Alexey Kozitsyn:

No, but this is unlikely to solve the problem, as ctrl, shift and other keys have been pressed... There was no reaction.

Anyway, I really don't have time to experiment right now - I've got my own stuff waiting to be done.

Maybe I really forgot about it. But I have set the time-limits in the tester. It is quite probable - just the same buttons. I also know that I set them with the mouse. But maybe on a live chart too...

 
Artyom Trishkin:

Probably. But the approaches are different, and they need to be planned properly first, rather than dumping everything into one line of code...

So I'll do it separately, for now.

What did I miss?

int GetNum(const string aSymbol)
  {
   int    count=0;
   if(PositionSelect(aSymbol))
     {
      long pos_id=long(PositionGetInteger(POSITION_IDENTIFIER));

      if(pos_id>0)
        {
         if(HistorySelectByPosition(ulong(pos_id)))
           {
            int deals=HistoryDealsTotal();

            for(int i=0; i<deals; i++)
              {
               ulong deal_ticket=HistoryDealGetTicket(i);
               ulong order_ticket=ulong(HistoryDealGetInteger(deal_ticket,DEAL_ORDER));

               if(order_ticket>0)
                 {
                  long deal_entry=long(HistoryDealGetInteger(deal_ticket,DEAL_ENTRY));

                  if(deal_entry==DEAL_ENTRY_IN)
                    {
                     if(m_position.PositionType()==POSITION_TYPE_SELL)
                       {
                        count++;
                       }
                    }
                 }
              }
            if( count > 0 ) return(count);
           }
         else
           {
            Print("Не возможно получить историю позиции по символу ",aSymbol);
           }
        }
      else
        {
         Print("Не возможно определить идентификатор позиции по символу ",aSymbol);
        }
     }
   return( 0 );
  }
////////////
 
First it counts correctly, then, when 5 limit SELLs are activated, it writes 6 in the comment. where does the sixth one come from?
Reason: