Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

Experts

Exp_XPeriodCandle_X2 - expert for MetaTrader 5

Nikolay Kositsin | English Русский 中文 Deutsch

Views:
240
Rating:
votes: 8
Published:
2018.07.09 13:59
\MQL5\Include\\MQL5\Indicators\

Trend-following trading system Exp_XPeriodCandle_X2 is based on the signals of two indicators XPeriodCandle. The first indicator determines the direction of the slow trend based on the color of the indicator's last candlestick closed. The second indicator determines the moment for opening a trade, when the candlestick color changes. The signal is formed when a bar is closing if two conditions are met:

  1. Signals of the fast and slow trend match;
  2. Direction of the fast trend has changed.


Input parameters of the Expert Advisor

//+-------------------------------------------------+
//| Input parameters of the EA indicator            |
//+-------------------------------------------------+
sinput string Trade="Trade Management";    //+============== TRADE MANAGEMENT ==============+  
input double MM=0.1;              //Share of a deposit in a deal
input MarginMode MMMode=LOT;      //Lot value detection method
input uint    StopLoss_=1000;     //Stop Loss in points
input uint    TakeProfit_=2000;   //Take Profit in points
sinput string MustTrade="Trade Permissions";    //+============== TRADE PERMISSIONS ==============+  
input int    Deviation_=10;       //Max price deviation in points
input bool   BuyPosOpen=true;     //Permission to enter long positions
input bool   SellPosOpen=true;    //Permission to enter short positions
//+-------------------------------------------------+
//| Input parameters of the filter indicator        |
//+-------------------------------------------------+
sinput string Filter="SLOW TREND PARAMETERS";            //+============== TREND PARAMETERS ==============+  
input ENUM_TIMEFRAMES TimeFrame=PERIOD_H6;                     //1 Chart period for the trend
input uint Cperiod=5;                                          // Calculation period for candlesticks
input Smooth_Method MA_SMethod=MODE_JJMA;                      // Averaging method
input int MA_Length=3;                                         // smoothing depth                    
input int MA_Phase=100;                                        // smoothing parameter,
3//---- for JJMA within the range of -100 ... +100 it influences the quality of the transition process;
//---- for VIDIA it is a CMO period, for AMA it is a slow average period
input uint SignalBar=1;                                        // bar number to receive the entry signal
input bool   BuyPosClose=true;                                 // Permission to close long positions by trend
input bool   SellPosClose=true;                                // Permission to close short positions by trend
//+-------------------------------------------------+
//| Input parameters of the entry indicator         |
//+-------------------------------------------------+
sinput string Input="ENTRY PARAMETERS";                         //+=============== ENTRY PARAMETERS ===============+  
input ENUM_TIMEFRAMES TimeFrame_=PERIOD_M30;                   //2 Chart period for entry 
input uint Cperiod_=5;                                         // Calculation period for candlesticks
input Smooth_Method MA_SMethod_=MODE_JJMA;                     // Averaging method
input int MA_Length_=3;                                        // smoothing depth                    
input int MA_Phase_=100;                                       // smoothing parameter,
3//---- for JJMA within the range of -100 ... +100 it influences the quality of the transition process;
//---- for VIDIA it is a CMO period, for AMA it is a slow average period
input uint SignalBar_=1;                                       // bar number to receive an entry signal
input bool   BuyPosClose_=false;                               // Permission to close long positions by signal
input bool   SellPosClose_=false;                              // Permission to close short positions by signal
//+-------------------------------------------------+

String parameters with text in the code of input parameters are only for better visualization of the input parametera window of the expert.

Indicators XPeriodCandle_HTF in the EA are only designed for a more convenient visualization of trends in the Strategy Tester; and they do not work in any other modes.

For the generated EA to operate correctly, the compiled files of indicators XPeriodCandle.ex5 and XPeriodCandle_HTF.ex5 must be in the <terminal_data_directory>\MQL5\Indicators folder.

Note that the TradeAlgorithms.mqh library file allows using Expert Advisors with brokers who offer nonzero spread and the option of setting Stop Loss and Take Profit together with position opening.

Default Expert Advisor's input parameters have been used during the tests shown below. Stop Loss and Take Profit have not been used during the tests.

Testing results on XAUUSD for the year 2016, slow trend on Daily, entry by fast trend on H1:

Fig 1. Examples of deals on the chart

Fig 1. Examples of deals on the chart


Fig. 2. Testing results chart

Fig. 2. Testing results chart

Translated from Russian by MetaQuotes Software Corp.
Original code: https://www.mql5.com/ru/code/21144

XPeriodCandle_main XPeriodCandle_main

Indicator XPeriodCandle in the main chart.

XPeriodCandleRange_HTF XPeriodCandleRange_HTF

Indicator XPeriodCandleRange with the timeframe selection option available in the input parameters

XPeriodCandle_main_HTF XPeriodCandle_main_HTF

Indicator XPeriodCandle_main with the timeframe selection option available in its input parameters.

AbsolutelyNoLagLwma_Digit_Cloud_HTF AbsolutelyNoLagLwma_Digit_Cloud_HTF

Indicator AbsolutelyNoLagLwma_Digit_Cloud with the timeframe selection option available in its input parameters.