A trading system using the XAng_Zad_C trend-following indicator with the possibility to set a fixed trading time interval and change the volume of a forthcoming trade depending on the results of the previous trades.
A trade decision is made when the indicator cloud changes its color.
It is possible to specify trading time in input parameters to trade in the specified time interval:
input bool TimeTrade=true; //Allow trading in the specified interval input HOURS StartH=ENUM_HOUR_0; //Trading start (hours) input MINUTS StartM=ENUM_MINUT_0; //Trading start (minutes) input HOURS EndH=ENUM_HOUR_23; //Trading end (hours) input MINUTS EndM=ENUM_MINUT_59;Â //Trading end (minutes)
Two variables for hours and minutes are provided for each of trading start and trading end times.
Default settings enable the Expert Advisor to trade the whole trading session from 0:00, while all positions are closed at 23:59.
If the start time in the EA’s settings is later than the specified trading end time, the EA will close the opened positions at the specified time next day.
The block of input EA variables is added for managing volumes of opened positions:
input uint    BuyTotalMMTriger=5; //the number of the last Buy deals to calculate stop loss input uint    BuyLossMMTriger=3;  //the number of losing Buy deals to reduce MM input uint    SellTotalMMTriger=5;//the number of the last Sell deals to calculate stop loss input uint    SellLossMMTriger=3; //the number of losing Sell deals to reduce MM input double  SmallMM_=0.01;      //Share of a deposit in a deal in case of loss input double  MM=0.1;            //Share of a deposit in a deal during normal trading input MarginMode MMMode=LOT;      //Lot value calculation method
In case of such inputs and when selecting from the last five trades, three of which are loss-making in a single direction, the EA opens the next trade in the same direction having the volume of 0.01 lot. If there are less than three loss-making trades out of the last five ones, the position volume is 0.1.
This Expert Advisor requires the compiled indicator file XAng_Zad.ex5 in order to run. It should be available under <terminal_data_folder>\MQL5\Indicators.
The EA default input parameters were used in tests below. Stop Loss and Take Profit were not used in testing.
Fig. 1. Examples of deals on the chart. Trading only in the time intervals set in the inputs is disabled.
Testing results for GBPJPY H4 over the year 2017:
Fig. 2. Test results chart
Fig. 3. Examples of deals on the chart. Trading only in the time intervals set in the inputs is enabled.