Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1122

 

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:

A tuned ME

I close it after work, nothing depends on how I close it.
The next time I open the ME, it looks like this:

Unconfigured ME

View - Toolbars you can set everything up.

Everything repeats after shutting down.


Build
 
User_mt5:

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

 
User_mt5:

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

 
Artyom Trishkin:

Now press F12

This worked.

Thank you very much.

 
Vladimir Karputov:

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.

 
User_mt5:

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!

 
Vladimir Karputov:

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.

 
Pul-Adgi Mo-UlStan:

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 :)

 
Pul-Adgi Mo-UlStan:

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                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- get transaction type as enumeration value
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in history
   if(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);
        }
      else
         return;
      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)
              {
               *** ***
              }
           }
        }
     }
  }
 

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.

//+------------------------------------------------------------------+
//|                                                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 expert
input string Expert_Title            ="EA_MB_MasterMQL5"; // Document name
ulong        Expert_MagicNumber      =1473;               //
bool         Expert_EveryTick        =false;              //
//--- inputs for main signal
input int    Signal_ThresholdOpen    =0;                 // Signal threshold value to open [0...100]
input int    Signal_ThresholdClose   =0;                 // Signal threshold value to close [0...100]
input double Signal_PriceLevel       =0.0;                // Price level to execute a deal
input double Signal_StopLevel        =50.0;               // Stop Loss level (in points)
input double Signal_TakeLevel        =50.0;               // Take Profit level (in points)
input int    Signal_Expiration       =4;                  // Expiration of pending orders (in bars)
input int    Signal_ITF_GoodHourOfDay=-1;                 // IntradayTimeFilter(-1,...) Good hour
input int    Signal_ITF_BadHoursOfDay=8389119;            // IntradayTimeFilter(-1,...) Bad hours (bit-map)
input int    Signal_ITF_GoodDayOfWeek=-1;                 // IntradayTimeFilter(-1,...) Good day of week
input int    Signal_ITF_BadDaysOfWeek=0;                  // IntradayTimeFilter(-1,...) Bad days of week (bit-map)
input double Signal_ITF_Weight       =1.0;                // IntradayTimeFilter(-1,...) Weight [0...1.0]
//--- inputs for money
input double Money_FixRisk_Percent   =10.0;               // Risk percentage
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__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)
     {
      //--- failed
      printf(__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)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set trailing parameters
//--- Creation of money object
   CMoneyFixedRisk *money=new CMoneyFixedRisk;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set money parameters
   money.Percent(Money_FixRisk_Percent);
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
   ExtExpert.OnTrade();
  }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+

Reason: