FORTS: To help beginners - page 3

 

Frequently used and useful functions:

Session limit price check:

//+------------------------------------------------------------------+
//| Expert Check price range function                                |
//+------------------------------------------------------------------+
bool CheckPriceRange( const string a_symbol, const double price )
{
  double min_price = SymbolInfoDouble( a_symbol, SYMBOL_SESSION_PRICE_LIMIT_MIN );
  double max_price = SymbolInfoDouble( a_symbol, SYMBOL_SESSION_PRICE_LIMIT_MAX );
  if ( ( price >= min_price ) && ( price <= max_price ) )
  {
    return( true );
  }
  return( false );
}
 

Frequently used and useful functions:

Redesigned GetPositionPrice() function:

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

A small edit to the function (for versatility)

instead of:

if ( volume_in > 0 )
{
  return( NormalizeDouble( price_in / volume_in, _Digits ) );
}

make it like this:

if ( volume_in > 0 )
{
  int symb_digits = int( SymbolInfoInteger( aSymbol, SYMBOL_DIGITS ) );
  return( NormalizeDouble( price_in / volume_in, symb_digits ) );
}
 
Build 1241. real account. if a pending order is set and partially executed, its state does not change to ORDER_STATE_PLACED, but remains ORDER_STATE_PARTIAL.
 

Forum on trading, automated trading systems and testing trading strategies

When is the new version of MT5 and where to find out what is expected in it

comp, 2016.03.21 08:52

If, for example, I do it myself: open a real account and put investment access to it on the forums so that everyone can see the real feed of FORTS in real time and have access to normal testing, could there be a problem? Or is it clear?

 
Hello! Is there any simple trading system template or example of an EA for FORTS, taking into account the features described in this thread? I need it to work correctly with orders on FORTS.
 

"Recommendation:

When designing EAs for FORTS, I do not recommend using the Tick event, but rather

It's better to usethe BookEvent event".

It's not explained why it's better, maybe in some cases it's better, in other cases it's better onTick. Could you be more specific?

 
Alexander:

"Recommendation:

When designing EAs for FORTS, I do not recommend using the Tick event, but rather

It's better to usethe BookEvent event".

It's not explained why it's better, maybe in some cases it's better, in other cases it's better onTick. Could you be more specific.

The author is in the ban and you won't hear an answer here for some time.

Here's what I think about it:

The Tick event only occurs when Bid, Ask, Last are changed. Also Tick event is cumulative (as developers said), for several price changes can come one Tick.

The BookEvent event arrives at any change of orders in the betting market and at executing trades. The BookEvent event comes much more frequently.

It's better to use OnTick() if you don't need to analyse the liquidity in the market.

On highly liquid symbols the BookEvent event comes very often and if there are heavy calculations or several heavy indicators in the handler, it will work as a loop.

If your Expert Advisor has other event handlers, like OnTimer, you can miss these events.I don't know about eventsOnTradeTransaction andOnTrade, perhaps, they can be skipped.

Here is some information for you:

The length of the transaction queue is 1024 items. If OnTradeTransaction() takes too long to process another transaction, the old transactions in the queue may be superseded by newer ones.

 
Sergey Chalyshev:

The author is in a ban and you won't hear back from him here for a while.

It's been a while since Michael was released from the bathhouse... Here, he's changed his maiden name.
 
Alexey Kozitsyn:
It's been a long time since Michael was released from the bathhouse... Here, he's changed his avatar.
What's his ava got to do with it? He can't write on the forum, he's banned forever.
Reason: