Automatically initialise and reinitialise the EA from a file - page 7

 
Fry_Антон:

I see.

Specifics: tomorrow I will think about how to catch a position on the fly on FORTS. In fact, what I need most of all is to know the actual opening price of a position that has cleared (reopened at the clearing price).

The position on FORTS is gained by the sum of trades on one (or more orders). On clearing there is a technical trade without a ticket, we need to figure out how to determine the POSITION_PRICE_OPEN price that was before clearing.

It can be stored. Only decide on the lifetime. For example, to forget if the EA is out of the market (no positions).
 
Dmitry Fedoseev:

Obviously, if:

You have to keep chiselling. But at least don't block the expert. Maybe less brazenly chisel, as the number of errors increases, increase the pause between attempts. The simplest solution is a few attempts and a pause until the next bar opens.

What about the Exchange penalties for exceeding 2,000 transactions? Let's say I have 50 EAs and 2,000 transactions have passed. What do I do next, receive monetary penalties from the Exchange?
 
Fry_Антон:

I see.

Specifics: tomorrow I will think about how to catch a position on the fly on FORTS. In fact, what I need most of all is to know the real opening price of a position that has cleared (reopened at the clearing price).

The position on FORTS is gained by the sum of trades on one (or more orders). On clearing there is a technical trade without a ticket, we need to figure out how to determine the POSITION_PRICE_OPEN price that was before clearing.

//+------------------------------------------------------------------+
//| Expert Get position price function                               |
//+------------------------------------------------------------------+
double GetPositionPrice( const string aSymbol )
{
  double price_in = 0;
  double volume_in = 0;
  
  if ( PositionSelect( aSymbol ) )
  {
    ulong pos_id = ulong( PositionGetInteger( POSITION_IDENTIFIER ) );
    
    if ( pos_id > 0 )
    {
      if ( HistorySelectByPosition( 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 )
          {
            ENUM_DEAL_ENTRY deal_entry = ENUM_DEAL_ENTRY( HistoryDealGetInteger( deal_ticket, DEAL_ENTRY ) );
              
            if ( deal_entry == DEAL_ENTRY_IN )
            {
              double price = HistoryDealGetDouble( deal_ticket, DEAL_PRICE );
              double volume = HistoryDealGetDouble( deal_ticket, DEAL_VOLUME );
                                
              price_in += price * volume;
              volume_in += volume;  
            }
          }
        }
        if ( volume_in > 0 ) return( NormalizeDouble( price_in / volume_in, _Digits ) );
      }
      else
      {
        Print( "GetPositionPrice: Невозможно получить историю позиции по символу ", aSymbol );
      }
    }
    else
    {
      Print( "GetPositionPrice: Невозможно определить идентификатор позиции по символу ", aSymbol );
    }
  }
  return( 0 );
}
 
Михаил:

Great! I'll bolt it on tomorrow.

You have saved me a lot of time. Thank you. (chuckles)

 
Fry_Антон:

great! I'll attach it tomorrow.

You have saved me a lot of time. Thank you.

Memo:

This function is ONLY for incoming trades!

(i.e. there was no position reduction).

If you need both, then add toDEAL_ENTRY_OUT function

 
Михаил:

Memo:

This function is for incoming trades ONLY!

(i.e. no decrease in position)

If you need both, then add to theDEAL_ENTRY_OUT function

that I understood right away. It's the principle itself that's important here: the ID search in the history and it's essentially the full answer to the question above.


Frankly speaking, I do not understand the developers' logic, why they decided to design a clearing technical deal in such a "clumsy" way.

Both graphical objects on charts, and position properties in history, and moreover, properties of an open position (profitability) - everything is misleading not only for a simple code in an EA, but for any trader in general.

 
kond777:
And what about the Exchange penalties for exceeding 2,000 transactions? Suppose I have 50 EAs and 2 000 transactions have passed. What do I do next, receive monetary fines from the Exchange?

You will not learn the answer to your question.

In order not to receive fines, it is necessary to stop the work of the expert (you and I discussed this a long time ago).

If our miracle-programmer says that it is necessary to stop, he thereby admits that he is

admitting to being ....., who doesn't know anything about programming

experts for stock trading....

 
Михаил:

You will not learn the answer to your question.

In order not to receive fines, it is necessary to stop the work of the expert (you and I discussed this a long time ago).

If our miracle-programmer says that it is necessary to stop, he thereby admits that he is

admitting to being ....., who doesn't know anything about programming

Expert Advisors for stock trading....

In my opinion,Dmitry Fedoseev gives the impression of a knowledgeable person, I believe he will probably be able to offer a solution to this problem.
 
Михаил:

Yes, because you are advising a person what is good for MT4 and is completely "futile" in MT5!

It's obvious from your messages that you have no idea how MT5 works.

And it's not for you to judge whether the expert programming principle is shameful or not!

I don't see you as an authority at all, but as a cheeky, cocky boy!

Are you jealous? And rightly so, it's better to be a young puppy than an old bird of paradise.
 
Алексей Тарабанов:
Jealous? You're right - better to be a young puppy than an old bird of paradise.
There's more gas in the puddle...