What exactly do you want to get? Do you want the time of the last trade(type of trade "out of the market")? Or do you need to know the time of closing a position in the trading history?
You need to know the time of last closed position in the trading history.
The code I wrote will work in MQL5, although I hooked the libraryfxsaber works code mt4, but still, the question remains, can't I make theOrderCloseTime() functionin MQL5? However, I'd better give it up. I have more of a question for developers. I don't have to answer. I've read the history in the branch. I have not understood many things so far, perhaps I will reconsider my views on the MQL5 language in time.
I need to know the time of the last closed position in the trading history.
The code I wrote will work in MQL5, although I've hooked up thefxsaber library, the mt4 code still works, but the question remains, can't I make the OrderCloseTime() function in MQL5? However, I'd better give it up. I have more of a question for developers. I don't have to answer. I've read the history in the branch. I have not understood many things so far, perhaps I will reconsider my views on the MQL5 language in time.
It's quite simple. You just have to read it first, then draw conclusions :)
I need to know the time of the last closed position in the trading history.
The code I wrote will work in MQL5, although I've hooked up thefxsaber library, the mt4 code still works, but the question remains, can't I make the OrderCloseTime() function in MQL5? However, I'd better give it up. I have more of a question for developers. I don't have to answer. I've read the history in the branch. I do not understand many things yet, maybe I will reconsider my views on MQL5 language in time.
Use a very simple method (especially since in 99% of hedge accounts the deal type is "exit from market" - this is the closing of the position).
Online capture transactionTRADE_TRANSACTION_DEAL_ADD- add transaction to history, check that it was a BUY or SELL trade, check that it was an "exit from market" tradeDEAL_ENTRY_OUT
//+------------------------------------------------------------------+//| TradeTransaction function |//+------------------------------------------------------------------+voidOnTradeTransaction(constMqlTradeTransaction &trans,
constMqlTradeRequest &request,
constMqlTradeResult &result)
{
//--- get transaction type as enumeration valueENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in historyif(type==TRADE_TRANSACTION_DEAL_ADD)
{
long deal_ticket =0;
long deal_order =0;
long deal_time =0;
long deal_time_msc =0;
long deal_type =-1;
long deal_entry =-1;
long deal_magic =0;
long deal_reason =-1;
long deal_position_id =0;
double deal_volume =0.0;
double deal_price =0.0;
double deal_commission =0.0;
double deal_swap =0.0;
double deal_profit =0.0;
string deal_symbol ="";
string deal_comment ="";
string deal_external_id ="";
if(HistoryDealSelect(trans.deal))
{
deal_ticket =HistoryDealGetInteger(trans.deal,DEAL_TICKET);
deal_order =HistoryDealGetInteger(trans.deal,DEAL_ORDER);
deal_time =HistoryDealGetInteger(trans.deal,DEAL_TIME);
deal_time_msc =HistoryDealGetInteger(trans.deal,DEAL_TIME_MSC);
deal_type =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
deal_entry =HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
deal_magic =HistoryDealGetInteger(trans.deal,DEAL_MAGIC);
deal_reason =HistoryDealGetInteger(trans.deal,DEAL_REASON);
deal_position_id =HistoryDealGetInteger(trans.deal,DEAL_POSITION_ID);
deal_volume =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
deal_price =HistoryDealGetDouble(trans.deal,DEAL_PRICE);
deal_commission =HistoryDealGetDouble(trans.deal,DEAL_COMMISSION);
deal_swap =HistoryDealGetDouble(trans.deal,DEAL_SWAP);
deal_profit =HistoryDealGetDouble(trans.deal,DEAL_PROFIT);
deal_symbol =HistoryDealGetString(trans.deal,DEAL_SYMBOL);
deal_comment =HistoryDealGetString(trans.deal,DEAL_COMMENT);
deal_external_id =HistoryDealGetString(trans.deal,DEAL_EXTERNAL_ID);
}
elsereturn;
ENUM_DEAL_ENTRY enum_deal_entry=(ENUM_DEAL_ENTRY)deal_entry;
if(deal_symbol==ИМЯ ВАШЕГО СИМВОЛА && deal_magic==НОМЕР ВАШЕГО MAGIC)
{
if(deal_type==DEAL_TYPE_BUY || deal_type==DEAL_TYPE_SELL)
{
if(deal_entry==DEAL_ENTRY_OUT)
{
*** ***
}
}
}
}
}
Generated a simple Expert Advisor using VQL5 Wizard, the code is given below. Help me to understand why function "Expiration of pending orders (in bars)" does not work, translated as "Expiration of pending orders (in bars)". I set any Signal_Expiration values from 1 to 1000, but the pending order still exists only within one bar. I also attach parameter settings.
For testing, I am using a demo account in the Metatrader 5 terminal, build 2136.
Sincerely, Vladimir.
//+------------------------------------------------------------------+//| EA_MasterMQL5.mq5 |//| Copyright 2019, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2019, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"//+------------------------------------------------------------------+//| Include |//+------------------------------------------------------------------+#include <Expert\Expert.mqh>
//--- available signals#include <Expert\Signal\SignalITF.mqh>
//--- available trailing#include <Expert\Trailing\TrailingNone.mqh>
//--- available money management#include <Expert\Money\MoneyFixedRisk.mqh>
//+------------------------------------------------------------------+//| Inputs |//+------------------------------------------------------------------+//--- inputs for expertinputstring Expert_Title ="EA_MB_MasterMQL5"; // Document nameulong Expert_MagicNumber =1473; //bool Expert_EveryTick =false; ////--- inputs for main signalinputint Signal_ThresholdOpen =0; // Signal threshold value to open [0...100]inputint Signal_ThresholdClose =0; // Signal threshold value to close [0...100]inputdouble Signal_PriceLevel =0.0; // Price level to execute a dealinputdouble Signal_StopLevel =50.0; // Stop Loss level (in points)inputdouble Signal_TakeLevel =50.0; // Take Profit level (in points)inputint Signal_Expiration =4; // Expiration of pending orders (in bars)inputint Signal_ITF_GoodHourOfDay=-1; // IntradayTimeFilter(-1,...) Good hourinputint Signal_ITF_BadHoursOfDay=8389119; // IntradayTimeFilter(-1,...) Bad hours (bit-map)inputint Signal_ITF_GoodDayOfWeek=-1; // IntradayTimeFilter(-1,...) Good day of weekinputint Signal_ITF_BadDaysOfWeek=0; // IntradayTimeFilter(-1,...) Bad days of week (bit-map)inputdouble Signal_ITF_Weight =1.0; // IntradayTimeFilter(-1,...) Weight [0...1.0]//--- inputs for moneyinputdouble Money_FixRisk_Percent =10.0; // Risk percentage//+------------------------------------------------------------------+//| Global expert object |//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+//| Initialization function of the expert |//+------------------------------------------------------------------+intOnInit()
{
//--- Initializing expertif(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
{
//--- failedprintf(__FUNCTION__+": error initializing expert");
ExtExpert.Deinit();
return(INIT_FAILED);
}
//--- Creating signal
CExpertSignal *signal=new CExpertSignal;
if(signal==NULL)
{
//--- failedprintf(__FUNCTION__+": error creating signal");
ExtExpert.Deinit();
return(INIT_FAILED);
}
//---
ExtExpert.InitSignal(signal);
signal.ThresholdOpen(Signal_ThresholdOpen);
signal.ThresholdClose(Signal_ThresholdClose);
signal.PriceLevel(Signal_PriceLevel);
signal.StopLevel(Signal_StopLevel);
signal.TakeLevel(Signal_TakeLevel);
signal.Expiration(Signal_Expiration);
//--- Creating filter CSignalITF
CSignalITF *filter0=new CSignalITF;
if(filter0==NULL)
{
//--- failedprintf(__FUNCTION__+": error creating filter0");
ExtExpert.Deinit();
return(INIT_FAILED);
}
signal.AddFilter(filter0);
//--- Set filter parameters
filter0.GoodHourOfDay(Signal_ITF_GoodHourOfDay);
filter0.BadHoursOfDay(Signal_ITF_BadHoursOfDay);
filter0.GoodDayOfWeek(Signal_ITF_GoodDayOfWeek);
filter0.BadDaysOfWeek(Signal_ITF_BadDaysOfWeek);
filter0.Weight(Signal_ITF_Weight);
//--- Creation of trailing object
CTrailingNone *trailing=new CTrailingNone;
if(trailing==NULL)
{
//--- failedprintf(__FUNCTION__+": error creating trailing");
ExtExpert.Deinit();
return(INIT_FAILED);
}
//--- Add trailing to expert (will be deleted automatically))if(!ExtExpert.InitTrailing(trailing))
{
//--- failedprintf(__FUNCTION__+": error initializing trailing");
ExtExpert.Deinit();
return(INIT_FAILED);
}
//--- Set trailing parameters//--- Creation of money object
CMoneyFixedRisk *money=new CMoneyFixedRisk;
if(money==NULL)
{
//--- failedprintf(__FUNCTION__+": error creating money");
ExtExpert.Deinit();
return(INIT_FAILED);
}
//--- Add money to expert (will be deleted automatically))if(!ExtExpert.InitMoney(money))
{
//--- failedprintf(__FUNCTION__+": error initializing money");
ExtExpert.Deinit();
return(INIT_FAILED);
}
//--- Set money parameters
money.Percent(Money_FixRisk_Percent);
//--- Check all trading objects parametersif(!ExtExpert.ValidationSettings())
{
//--- failed
ExtExpert.Deinit();
return(INIT_FAILED);
}
//--- Tuning of all necessary indicatorsif(!ExtExpert.InitIndicators())
{
//--- failedprintf(__FUNCTION__+": error initializing indicators");
ExtExpert.Deinit();
return(INIT_FAILED);
}
//--- okreturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Deinitialization function of the expert |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
ExtExpert.Deinit();
}
//+------------------------------------------------------------------+//| "Tick" event handler function |//+------------------------------------------------------------------+voidOnTick()
{
ExtExpert.OnTick();
}
//+------------------------------------------------------------------+//| "Trade" event handler function |//+------------------------------------------------------------------+voidOnTrade()
{
ExtExpert.OnTrade();
}
//+------------------------------------------------------------------+//| "Timer" event handler function |//+------------------------------------------------------------------+voidOnTimer()
{
ExtExpert.OnTimer();
}
//+------------------------------------------------------------------+
2019.09.09 18:03:27.865 Terminal MetaTrader 5 x64 build 2138 started (MetaQuotes Software Corp.)

2019.09.09 18:03:27.866 Terminal Windows 10 (build 18362) x64, IE 11, UAC, Intel Core i7-3770K @ 3.50GHz, Memory: 20544 / 24520 Mb, Disk: 145 / 237 Gb, GMT+2
2019.09.09 18:03:27.866 Terminal C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
The usual view of my ME:
I close it after work, nothing depends on how I close it.
The next time I open the ME, it looks like this:
View - Toolbars you can set everything up.
Everything repeats after shutting down.
2019.09.09 18:03:27.865 Terminal MetaTrader 5 x64 build 2138 started (MetaQuotes Software Corp.)
2019.09.09 18:03:27.866 Terminal Windows 10 (build 18362) x64, IE 11, UAC, Intel Core i7-3770K @ 3.50GHz, Memory: 20544 / 24520 Mb, Disk: 145 / 237 Gb, GMT+2
2019.09.09 18:03:27.866 Terminal C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
The usual view of my ME:
I close it after work, nothing depends on how I close it.
The next time I open the ME, it looks like this:
View - Toolbars you can set everything up.
Everything repeats after shutting down.
Now press F12
2019.09.09 18:03:27.865 Terminal MetaTrader 5 x64 build 2138 started (MetaQuotes Software Corp.)
2019.09.09 18:03:27.866 Terminal Windows 10 (build 18362) x64, IE 11, UAC, Intel Core i7-3770K @ 3.50GHz, Memory: 20544 / 24520 Mb, Disk: 145 / 237 Gb, GMT+2
2019.09.09 18:03:27.866 Terminal C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
The usual view of my ME:
I close it after work, nothing depends on how I close it.
The next time I open the ME, it looks like this:
View - Toolbars you can set everything up.
After switching off, everything repeats itself.
Try to open the Data Folder there go to \config, close the terminal and MetaEditor, delete the metaeditor.ini file
Now press F12
This worked.
Thank you very much.
Try opening the Data Folder there go to \config, close the terminal and MetaEditor, delete the metaeditor.ini file
F12 worked, so nothing else is required.
Thanks for the help.
F12 has worked, so nothing else is required.
Thanks for all your help.
Wow. I didn't know about F12 (expand to full screen) for MetaEditor 5!
What exactly do you want to get? Do you want the time of the last trade(type of trade "out of the market")? Or do you need to know the time of closing a position in the trading history?
You need to know the time of last closed position in the trading history.
The code I wrote will work in MQL5, although I hooked the libraryfxsaber works code mt4, but still, the question remains, can't I make theOrderCloseTime() functionin MQL5? However, I'd better give it up. I have more of a question for developers. I don't have to answer. I've read the history in the branch. I have not understood many things so far, perhaps I will reconsider my views on the MQL5 language in time.
I need to know the time of the last closed position in the trading history.
The code I wrote will work in MQL5, although I've hooked up thefxsaber library, the mt4 code still works, but the question remains, can't I make the OrderCloseTime() function in MQL5? However, I'd better give it up. I have more of a question for developers. I don't have to answer. I've read the history in the branch. I have not understood many things so far, perhaps I will reconsider my views on the MQL5 language in time.
It's quite simple. You just have to read it first, then draw conclusions :)
I need to know the time of the last closed position in the trading history.
The code I wrote will work in MQL5, although I've hooked up thefxsaber library, the mt4 code still works, but the question remains, can't I make the OrderCloseTime() function in MQL5? However, I'd better give it up. I have more of a question for developers. I don't have to answer. I've read the history in the branch. I do not understand many things yet, maybe I will reconsider my views on MQL5 language in time.
Use a very simple method (especially since in 99% of hedge accounts the deal type is "exit from market" - this is the closing of the position).
Online capture transactionTRADE_TRANSACTION_DEAL_ADD- add transaction to history, check that it was a BUY or SELL trade, check that it was an "exit from market" tradeDEAL_ENTRY_OUT
Forum on Trading, Automated Trading Systems and Strategy Tests
Questions from beginners MQL5 MT5 MetaTrader 5
MrBrooklin, 2019.09.09 09:50
Good day everyone and great profits!
Generated a simple Expert Advisor using VQL5 Wizard, the code is given below. Help me to understand why function "Expiration of pending orders (in bars)" does not work, translated as "Expiration of pending orders (in bars)". I set any Signal_Expiration values from 1 to 1000, but the pending order still exists only within one bar. I also attach parameter settings.
For testing, I am using a demo account in the Metatrader 5 terminal, build 2136.
Sincerely, Vladimir.