Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1134

 
Hello, could you please tell me how to do this? How do I spell the condition correctly: *if there is a new hour*?
 
MrBrooklin:

Hello!

Help me out here. I have a question about the trading signal module "Time filter".

The thing is, I have generated an EA using this module and set it to allow only one hour of trading per day. It mainly trades that way, but there are days when my Expert Advisor opens positions at whatever hour it wants. I have tried the "Time filter" trading signal module in various combinations with other trading signal modules (e.g., Stochastic, WPR, etc.) but the same thing happens. Moreover, if you set 2 consecutive hours of work allowed, there are no problems, it works fine.

What can it be related to? Maybe there is an error in the code of a trading signal module "Time filter"? Since I'm not an expert in programming, I'm asking you to help me figure it out or give me a hint, maybe I am doing something wrong.

Sincerely, Vladimir.


Here is a simple example on the picture. On one day, it opens at 7 o'clock; on another day, it opens at 5 o'clock; on the third day, it opens at 7 o'clock again.


Can you attach an mq5 Expert Advisor to this post and specify the tester parameters (two screenshots: Settings and Parameters tabs)?

 
Snajper007:
Hello, Could you please tell me. How do I correctly spell the condition: *if there is a new hour*?

Do you mean the time (e.g. the clock showed 15-00) or do you mean a new bar was born on the H1 timeframe?

 

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Vladimir Karputov, 2019.10.14 12:04

Can you attach an mq5 Expert Advisor to a message and specify the tester's parameters (two screenshots: Settings and Parameters tabs)?


Not to be unfounded, for example, right now I generated in MQL5 Wizard the first available module of AMA trading signals and a time filter.

//+------------------------------------------------------------------+
//|                                                          AMA.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\SignalAMA.mqh>
#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            ="AMA";                  // Document name
ulong                    Expert_MagicNumber      =8503;                   //
bool                     Expert_EveryTick        =false;                  //
//--- inputs for main signal
input int                Signal_ThresholdOpen    =10;                     // Signal threshold value to open [0...100]
input int                Signal_ThresholdClose   =10;                     // Signal threshold value to close [0...100]
input double             Signal_PriceLevel       =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_AMA_PeriodMA     =10;                     // Adaptive Moving Average(1,1,...) Period of averaging
input int                Signal_AMA_PeriodFast   =2;                      // Adaptive Moving Average(1,1,...) Period of fast EMA
input int                Signal_AMA_PeriodSlow   =30;                     // Adaptive Moving Average(1,1,...) Period of slow EMA
input int                Signal_AMA_Shift        =0;                      // Adaptive Moving Average(1,1,...) Time shift
input ENUM_APPLIED_PRICE Signal_AMA_Applied      =PRICE_CLOSE;            // Adaptive Moving Average(1,1,...) Prices series
input double             Signal_AMA_Weight       =1.0;                    // Adaptive Moving Average(1,1,...) Weight [0...1.0]
input int                Signal_ITF_GoodHourOfDay=-1;                     // IntradayTimeFilter(-1,...) Good hour
input int                Signal_ITF_BadHoursOfDay=16777087;               // 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 CSignalAMA
   CSignalAMA *filter0=new CSignalAMA;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
   filter0.PeriodMA(Signal_AMA_PeriodMA);
   filter0.PeriodFast(Signal_AMA_PeriodFast);
   filter0.PeriodSlow(Signal_AMA_PeriodSlow);
   filter0.Shift(Signal_AMA_Shift);
   filter0.Applied(Signal_AMA_Applied);
   filter0.Weight(Signal_AMA_Weight);
//--- Creating filter CSignalITF
   CSignalITF *filter1=new CSignalITF;
   if(filter1==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter1");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter1);
//--- Set filter parameters
   filter1.GoodHourOfDay(Signal_ITF_GoodHourOfDay);
   filter1.BadHoursOfDay(Signal_ITF_BadHoursOfDay);
   filter1.GoodDayOfWeek(Signal_ITF_GoodDayOfWeek);
   filter1.BadDaysOfWeek(Signal_ITF_BadDaysOfWeek);
   filter1.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();
  }
//+------------------------------------------------------------------+

Screenshot of "Settings"


Screenshot of "Settings".

Screenshot ofthe incorrect of the time filter (positions are opened on different days at 7, 12 and 7 o'clock)


 
MrBrooklin:

So as not to be unfounded, for example, right now I generated in MQL5 Wizard the first available module of AMA trading signals and a time filter.

Screenshot of "Settings"


Screenshot of "Settings".

Screenshot of the incorrect operation of the time filter (opening positions on different days at 7, 12 and 7 o'clock)


1. Picture with a chart - when taking a screenshot, do it with "Crosshair" tool - it is unclear which year it is.

2. When working with the pending orders - remember that the pending order can trigger at a completely different time (hour and minutes) relative to the time of setting.

3. When using signal modules, reset the parameters to default values and check the work on the market - without any pending orders (if point 2 is not clear).

 

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Vladimir Karputov, 2019.10.14 13:28

1. Chart picture - when making a screnshot do it together with "Crosshair" tool - otherwise it is not clear which year.

2. When working with pending orders - remember that a pending order can trigger at a completely different time (hour and minutes) in relation to the time of placing.

3. When using signal modules, reset the parameters to default values and check the work on the market - without the pending orders (this is if point 2 is not clear).


1. About the crosshair - understandable. In the screenshot the year is 2019 and the month is October.

2. I do not quite understand about the pending order. How do you know that the EA has a pending order and does not open a position at the beginning of the hour? Can you be more specific?

3. The Expert Advisor works fine with default values of signal modules. Can we modify the parameter values?

Sincerely, Vladimir.

 

***

1. Regarding the crosshairs, it is clear. In the screenshot, the year is 2019 and the month is October.

***

Thanks for the clarification.

***

2. I do not quite understand about the pending order. How did you determine that the EA has set a pending order and not open a position immediately at the start of the hour? Can you be more specific?

***

In the visual tester, just look at the "History" tab

History tab

***

3. With the default values of the signal modules, the Expert Advisor works fine. Is it not possible to change the values of the parameters?

***

Of course you can, but only if you understand what you are doing and if you understand what parameter is responsible for what.

 
Vladimir Karputov:

Do you mean the time (e.g. the clock showed 15-00) or do you mean a new bar was born on the H1 timeframe?

I mean the clock showed 15-00.
 
Snajper007:
I mean, the clock showed 15-00.

And with what degree of certainty do you want the result?

Just an example: You want to see the time on the clock as 3pm. And you wait for it. But at that time there was no tick or there was no connection to the server. And then you got the ticks, but the time is 15 hours 00 minutes and 36 seconds. What will you do?

 
Vladimir Karputov:

And with what degree of certainty do you want the result?

Just an example: You want to see the time on the clock as 3pm. And you wait for it. But at that time there was no tick or there was no connection to the server. And then you got the ticks, but the time is 15 hours 00 minutes and 36 seconds. What will you do?

Can you make it possible to check not exactly 15-00, but the beginning of the hour? In other words, the first minute would already show that the previous hour had ended and the new hour had started.
Reason: