So what if some regime is not supported? Why should that make it prohibit you from trading?
Especially if "does not support Stop Limit order setting mode"? This is the trouble with not being able to trade at all.
© DESTRUCTION IN THE HEAD
It's written at the beginning:
IMPORTANT: In order not to "stretch" the topic, if you have any comments,
or have questions, createa separate topicin this section(I will not answer here).
P / S for the especially "gifted" :
In this function, you need to check the parameters that
you will use in your EA. Here is an example:
.......................
Continued:
Frequently used and useful functions:
The CheckError() function itself (not all return codes in the example)
.........................................................................
Explanation of the return codes:
string GetRetCode( const uint code ) { string retcode; switch( code ) { case TRADE_RETCODE_REQUOTE: retcode = "Реквота"; break; case TRADE_RETCODE_REJECT: retcode = "Запрос отвергнут"; break; case TRADE_RETCODE_CANCEL: retcode = "Запрос отменен трейдером"; break; case TRADE_RETCODE_PLACED: retcode = "Ордер размещен"; break; case TRADE_RETCODE_DONE: retcode = "Заявка выполнена"; break; case TRADE_RETCODE_DONE_PARTIAL: retcode = "Заявка выполнена частично"; break; case TRADE_RETCODE_ERROR: retcode = "Ошибка обработки запроса"; break; case TRADE_RETCODE_TIMEOUT: retcode = "Запрос отменен по истечению времени"; break; case TRADE_RETCODE_INVALID: retcode = "Неправильный запрос"; break; case TRADE_RETCODE_INVALID_VOLUME: retcode = "Неправильный объем в запросе"; break; case TRADE_RETCODE_INVALID_PRICE: retcode = "Неправильная цена в запросе"; break; case TRADE_RETCODE_INVALID_STOPS: retcode = "Неправильные стопы в запросе"; break; case TRADE_RETCODE_TRADE_DISABLED: retcode = "Торговля запрещена"; break; case TRADE_RETCODE_MARKET_CLOSED: retcode = "Рынок закрыт"; break; case TRADE_RETCODE_NO_MONEY: retcode = "Нет достаточных денежных средств для выполнения запроса"; break; case TRADE_RETCODE_PRICE_CHANGED: retcode = "Цены изменились"; break; case TRADE_RETCODE_PRICE_OFF: retcode = "Отсутствуют котировки для обработки запроса"; break; case TRADE_RETCODE_INVALID_EXPIRATION: retcode = "Неверная дата истечения ордера в запросе"; break; case TRADE_RETCODE_ORDER_CHANGED: retcode = "Состояние ордера изменилось"; break; case TRADE_RETCODE_TOO_MANY_REQUESTS: retcode = "Слишком частые запросы"; break; case TRADE_RETCODE_NO_CHANGES: retcode = "В запросе нет изменений"; break; case TRADE_RETCODE_SERVER_DISABLES_AT: retcode = "Автотрейдинг запрещен сервером"; break; case TRADE_RETCODE_CLIENT_DISABLES_AT: retcode = "Автотрейдинг запрещен клиентским терминалом"; break; case TRADE_RETCODE_LOCKED: retcode = "Запрос заблокирован для обработки"; break; case TRADE_RETCODE_FROZEN: retcode = "Ордер или позиция заморожены"; break; case TRADE_RETCODE_INVALID_FILL: retcode = "Указан неподдерживаемый тип исполнения ордера по остатку"; break; case TRADE_RETCODE_CONNECTION: retcode = "Нет соединения с торговым сервером"; break; case TRADE_RETCODE_ONLY_REAL: retcode = "Операция разрешена только для реальных счетов"; break; case TRADE_RETCODE_LIMIT_ORDERS: retcode = "Достигнут лимит на количество отложенных ордеров"; break; case TRADE_RETCODE_LIMIT_VOLUME: retcode = "Достигнут лимит на объем ордеров и позиций для данного символа"; break; case TRADE_RETCODE_INVALID_ORDER: retcode = "Неверный или запрещённый тип ордера"; break; case TRADE_RETCODE_POSITION_CLOSED: retcode = "Позиция с указанным POSITION_IDENTIFIER уже закрыта"; break; default: retcode = "Нет кода возврата."; break; } return( retcode ); }
Recommendation:
When designing advisors for FORTS, I do not recommend using the Tick event, but
it is better to use the BookEvent event
Examples:
Adding a Tick:
(Use ONLY in OnInit() )
if ( !MarketBookAdd( _Symbol ) ) { MessageBox( "Не добавлен стакан фьючерса " + _Symbol + "!", "Ошибка", MB_OK | MB_ICONHAND ); return( INIT_FAILED ); }
Removing a subscription to a glass:
void OnDeinit( const int reason ) { MarketBookRelease( _Symbol ); }
Get the best ASK and BID and their volumes from the tumbler of prices:
double sell_price, buy_price; long sell_volume, buy_volume; //+------------------------------------------------------------------+ //| Expert Get Stakan values function | //+------------------------------------------------------------------+ bool GetStakanValues( const string aSymbol, double &sell_price, double &buy_price, long &sell_volume, long &buy_volume ) { MqlBookInfo book_price[]; buy_price = 0; sell_price = DBL_MAX; buy_volume = 0; sell_volume = 0; //--- Get stakan if ( MarketBookGet( aSymbol, book_price ) )//getBook ) { int size = ArraySize( book_price ); //--- if ( size > 0 ) { double a_min_price = SymbolInfoDouble( aSymbol, SYMBOL_SESSION_PRICE_LIMIT_MIN ); double a_max_price = SymbolInfoDouble( aSymbol, SYMBOL_SESSION_PRICE_LIMIT_MAX ); //--- for( int i = 0; i < size; i++ ) { if ( book_price[i].type == BOOK_TYPE_SELL ) { if ( book_price[i].price < sell_price ) { sell_price = book_price[i].price; sell_volume = book_price[i].volume; } } else if ( book_price[i].type == BOOK_TYPE_BUY ) //First buy - exit { buy_price = book_price[i].price; buy_volume = book_price[i].volume; break; } } if ( ( buy_price <= a_max_price ) && ( buy_price >= a_min_price ) && ( sell_price <= a_max_price ) && ( sell_price >= a_min_price ) ) { if ( sell_price == DBL_MAX ) sell_price = 0; //--- if ( ( sell_price > 0 ) && ( buy_price > 0 ) ) { return( true ); } } } } //--- if ( sell_price == DBL_MAX ) sell_price = 0; //--- return( false); }
Function call:
Checkingif ( a_symbol == _Symbol ) is MUST, it ensures that it is your price stack that has changed.
//+------------------------------------------------------------------+ //| Expert On Book event function | //+------------------------------------------------------------------+ void OnBookEvent( const string &a_symbol ) { if ( a_symbol == _Symbol ) { if ( GetStakanValues( _Symbol, sell_price, buy_price, sell_volume, buy_volume ) ) { //you code } } }
THANK YOU!!!)
Special features:
Formulas for calculating and awarding points for ineffective and faulty
transactions in the attachment.
P/S Both rules and points are changed often enough :(
Frequently used and useful functions:
The SetStDayTime() function returns the start time of the trading day (at the time of request).
Function GetExgangeFee() returns exchange commission and number of transactions for the trading day (at the time of request):
//+------------------------------------------------------------------+ //| Tr_fee.mq5 | //| Copyright 2015, Mikalas | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Mikalas" #property link "https://www.mql5.com" #property version "1.00" // input long TrPoint = 1; //Балл за транзакцию input long DealPoint = 40; //Балл за сделку // datetime start_day_time; // //+------------------------------------------------------------------+ //| Expert Set start day time function | //+------------------------------------------------------------------+ datetime SetStDayTime() { MqlDateTime dt_str; TimeTradeServer( dt_str ); //--- if ( ( dt_str.day_of_week == 0 ) || ( dt_str.day_of_week == 6 ) ) return( datetime( 0 ) ); //--- string time_str = IntegerToString( dt_str.year ) + "." + IntegerToString( dt_str.mon ) + "." + IntegerToString( dt_str.day ) + " 19:00:00"; ulong cur_day = ulong( StringToTime( time_str ) ); if ( ( dt_str.hour >= 19 ) && ( dt_str.hour <= 23 ) ) { return( StringToTime( time_str ) ); } else { ulong one_day = 24 * 60 * 60; //--- if ( dt_str.day_of_week == 1 ) { cur_day -= one_day * 3; } else { cur_day -= one_day; } return( datetime( cur_day ) ); } return( datetime( 0 ) ); } //+------------------------------------------------------------------+ //| Expert calc deals fee function | //+------------------------------------------------------------------+ double GetExgangeFee( const datetime start_time, long& deals ) { double all_fee = 0.0; ulong deal_ticket; deals = 0; //--- if ( HistorySelect( start_time, TimeTradeServer() ) ) { int deals_total = HistoryDealsTotal(); //--- if ( deals_total > 0 ) { for ( uint i = 0; i < uint( deals_total ); i++ ) { deal_ticket = HistoryDealGetTicket( i ); //--- if ( deal_ticket > 0 ) { ulong order_ticket = ulong( HistoryDealGetInteger( deal_ticket, DEAL_ORDER ) ); if ( order_ticket > 0 ) { deals++; all_fee += HistoryDealGetDouble( deal_ticket, DEAL_COMMISSION ); } } } return( MathAbs( all_fee ) ); } } return( 0 ); } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { long a_deals; start_day_time = SetStDayTime(); //--- if ( ulong( start_day_time ) == 0 ) { MessageBox( "Не установлено время начала торгового дня!", "Ошибка", MB_OK | MB_ICONHAND ); return( INIT_FAILED ); } Print( "Exgange Fee = ", GetExgangeFee( start_day_time, a_deals ), "; Deals = ", a_deals ); return( INIT_SUCCEEDED ); }
Frequently used and useful functions:
The SetStDayTime() function returns the start time of the trading day (at the time of request).
Function GetExgangeFee() returns exchange commission and number of transactions for the trading day (at the time of request):
This is an unprecedented contender for the title of "Hindu Coder - 2015".
SetStDayTime() is solved with two lines. But of course you don't need to...
Michael, thank you for your features!
The invention of some bicycles by me is cancelled )
I have to.
And how do you do that?
You have to work with the numerical representation of time.
datetime a=TimeTradeServer();
The start time of the day:
datetime r=(a/86400)*86400
The time at 19:00 today:
datetime r=(a/86400)*86400+19*3600;
If the time at 19:00 today is greater than the current time, then we need yesterday's 19:00:
if(r>a)r-=86400;
Here, if we need to skip the weekend, we check the day of the week, if Sunday, subtract 86400*2, if Saturday, subtract 86400 (to get Friday).
It goes something like this.
Then, for display, if needed, convert to a string:
TimeToStr(r)
And the high year?
Now, translate your thoughts into concrete code.
Rewrite my function in your own way, and as you said in TWO lines!
What about leap year? Everything will be all right.
Just do it yourself, I don't want to understand your code completely, in case I'll miss something, what a joy you'll have.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good afternoon!
Here I will post recommendations, bugs, features and frequently used functions on the FORTS futures market
IMPORTANT: In order not to "stretch" the topic, if there are any comments,
or have questions - create a separate topic in this section (I will not answer here).
Recommendation :
The MQL5 standard library is "sharpened" for the FOREX market, so for
developments of experts for FORTS I recommend to write everything yourself.
Frequently used and useful features:
The function of checking the trading parameters of the broker's server.
In this function, it is necessary to check those parameters that
You will use in your advisor. Here is an example:
(use ONLY in OnInit() )
Usage example:
Getting the number of days left until the expiration of the instrument:
Getting the "net" position price, excluding clearings:
Creating a global terminal variable for counting transactions:
( Use ONLY in OnInit() )
Protected write to the global variable of the terminal (transaction counter):
If the parameter up_down = true, then we increase the global variable of the terminal,
and vice versa.
Checking funds with automatic reduction of the volume, in case of shortage of money:
Placing a market / limit order with the OrderSend() command
if price = ''0" - market order:
Deleting an order with the OrderSend() command
Placing a pending order with the OrderSend() command
Modifying a pending order with the OrderSend() command
Setting a pending order with the OrderSendAsync() command
When using this command, the ticket is not obtained as a result of this
functions, but in the OnTradeTransaction() function. In the OrderSendAsync() function, we
get the number of the request to place an order:
ulong order_ticket = 0;
Getting a ticket by request number:
Handling errors (return codes) of the OrderSend() and OrderSendAsync() functions
the CheckError() function is added to the implementation of order sending. Example:
The CheckError() function itself ( not all return codes in the example )
See continuation
Peculiarities:
When buying more than ONE contract with a LIMIT order with ORDER_FILLING_IOC execution,
an order in the history can be stored as ORDER_STATE_CANCELED if the order is filled with the first volume,
and the second failed.
Example:
Buying 3 contracts with a LIMIT order with ORDER_FILLING_IOC execution,
there is the following situation:
1. If we bought all three contracts, then the order in the history has the state = ORDER_STATE_FILLED
2. If we did not buy anything, then in the history state = ORDER_STATE_CANCELED
3. If we bought the first two contracts (28449), but did not buy 1 contract (28450), then the state in the history = ORDER_STATE_CANCELED
4. If we did not buy the first two contracts (28449), but bought 1 (28450), then in the history state = ORDER_STATE_PARTIAL
======= End of example ===================
The number of inefficient transactions (an inefficient transaction is a transaction that did not lead to a transaction.
Placement, modification and deletion of an order) on the futures market FORTS is limited to 2000 per full trading session
from 19-00 of the current day to 18-45 of the next day. For exceeding - a fine of the Exchange
http://moex.com/n8725
Bugs:
1. If a failure occurs on the MT5 server of the broker or on the exchange, then the command
delete(modify) EXISTING order server returns:
error 10013 = TRADE_RETCODE_INVALID = Invalid request ( Invalid request )
2. Sometimes, also on failure, when trying to place a pending or limit order, an error occurs - " The instrument is not currently available "
(that's not a typo, that's the message)
There is no return code for the trade server in the documentation!