1- #property copyright " Copyright 2017-18, AZ-iNVEST "
2- #property link " http ://www.az-invest.eu"
3- #property version " 2.06 "
1+ #property copyright " Copyright 2017-2020, Level Up Software "
2+ #property link " https ://www.az-invest.eu"
3+ #property version " 2.07 "
44#property description " Example EA showing the way to use the RangeBars class defined in RangeBars.mqh"
55
6+ input int InpRSIPeriod = 14 ; // RSI period
7+
68//
7- // SHOW_INDICATOR_INPUTS *NEEDS* to be defined, if the EA needs to be *tested in MT5's backtester*
9+ // SHOW_INDICATOR_INPUTS *NEEDS* to be defined, if the sEA needs to be *tested in MT5's backtester*
810// -------------------------------------------------------------------------------------------------
911// Using '#define SHOW_INDICATOR_INPUTS' will show the RangeBars indicator's inputs
1012// NOT using the '#define SHOW_INDICATOR_INPUTS' statement will read the settigns a chart with
2022#include < AZ-INVEST/SDK/RangeBars.mqh>
2123//
2224// To use the RangeBars indicator in your EA you need do instantiate the indicator class (RangeBars)
23- // and call the Init() method in your EA's OnInit() function.
24- // Don't forget to release the indicator when you're done by calling the Deinit() method.
25- // Example shown in OnInit & OnDeinit functions below:
25+ // and call the Init() and Deinit() methods in your EA's OnInit() and OnDeinit() functions.
26+ // Example shown below
2627//
2728
28- RangeBars * rangeBars ;
29+ RangeBars rangeBars ( MQLInfoInteger (( int ) MQL5_TESTING ) ? false : true ) ;
2930
3031//+------------------------------------------------------------------+
3132//| Expert initialization function |
3233//+------------------------------------------------------------------+
3334int OnInit ()
3435{
35- rangeBars = new RangeBars (MQLInfoInteger ((int )MQL5_TESTING ) ? false : true );
36- if (rangeBars == NULL )
37- return (INIT_FAILED );
38-
3936 rangeBars .Init ();
4037 if (rangeBars .GetHandle () == INVALID_HANDLE )
4138 return (INIT_FAILED );
@@ -51,11 +48,7 @@ int OnInit()
5148//+------------------------------------------------------------------+
5249void OnDeinit (const int reason )
5350{
54- if (rangeBars != NULL )
55- {
56- rangeBars .Deinit ();
57- delete rangeBars ;
58- }
51+ rangeBars .Deinit ();
5952
6053 //
6154 // your custom code goes here...
@@ -70,8 +63,22 @@ void OnDeinit(const int reason)
7063//+------------------------------------------------------------------+
7164//| Expert tick function |
7265//+------------------------------------------------------------------+
66+
67+ int rsiHandle = INVALID_HANDLE ; // Handle for the external RSI indicator
68+
7369void OnTick ()
7470{
71+ //
72+ // Initialize all additional indicators here! (not in the OnInit() function).
73+ // Otherwise they will not work in the backtest.
74+ // When backtesting please select the "Daily" timeframe.
75+ //
76+
77+ if (rsiHandle == INVALID_HANDLE )
78+ {
79+ rsiHandle = iCustom (_Symbol , _Period , " RangeBars\\ RangeBars_RSI" , InpRSIPeriod , true );
80+ }
81+
7582 //
7683 // It is considered good trading & EA coding practice to perform calculations
7784 // when a new bar is fully formed.
@@ -96,7 +103,7 @@ void OnTick()
96103 double MA1 []; // array to be filled by values of the first moving average
97104 double MA2 []; // array to be filled by values of the second moving average
98105
99- if (rangeBars .GetMA1 ( MA1 ,startAtBar ,numberOfBars ) && rangeBars .GetMA2 ( MA2 ,startAtBar ,numberOfBars ))
106+ if (rangeBars .GetMA ( RANGEBAR_MA1 , MA1 , startAtBar , numberOfBars ) && rangeBars .GetMA ( RANGEBAR_MA2 , MA2 , startAtBar , numberOfBars ))
100107 {
101108 //
102109 // Values are stored in the MA1 and MA2 arrays and are now ready for use
@@ -182,64 +189,23 @@ void OnTick()
182189 }
183190
184191 //
185- // Getting Donchain channel values is done using the
186- // GetDonchian (double &HighArray[], double &MidArray[], double &LowArray[], int start, int count)
187- // method. Example below:
192+ // Getting the values of the channel indicator (Donchain, Bullinger Bands, Keltner or Super Trend) is done using
193+ // GetChannel (double &HighArray[], double &MidArray[], double &LowArray[], int start, int count)
194+ // Example below:
188195 //
189196
190- double HighArray []; // This array will store the values of the high band
191- double MidArray []; // This array will store the values of the middle band
192- double LowArray []; // This array will store the values of the low band
197+ double HighArray []; // This array will store the values of the channel's high band
198+ double MidArray []; // This array will store the values of the channel's middle band
199+ double LowArray []; // This array will store the values of the channel's low band
193200
194201 startAtBar = 1 ; // get values starting from the last completed bar.
195202 numberOfBars = 20 ; // gat a total of 20 values (for 20 bars starting from bar 1 (last completed))
196203
197- if (rangeBars .GetDonchian (HighArray ,MidArray ,LowArray ,startAtBar ,numberOfBars ))
198- {
199- //
200- // Apply your Donchian channel logic here...
201- //
202- }
203-
204- //
205- // Getting Bollinger Bands values is done using the
206- // GetBollingerBands(double &HighArray[], double &MidArray[], double &LowArray[], int start, int count)
207- // method. Example below:
208- //
209-
210- // HighArray[] array will store the values of the high band
211- // MidArray[] array will store the values of the middle band
212- // LowArray[] array will store the values of the low band
213-
214- startAtBar = 1 ; // get values starting from the last completed bar.
215- numberOfBars = 10 ; // gat a total of 10 values (for 10 bars starting from bar 1 (last completed))
216-
217- if (rangeBars .GetBollingerBands (HighArray ,MidArray ,LowArray ,startAtBar ,numberOfBars ))
204+ if (rangeBars .GetChannel (HighArray ,MidArray ,LowArray ,startAtBar ,numberOfBars ))
218205 {
219206 //
220- // Apply your Bollinger Bands logic here...
207+ // Apply your logic here...
221208 //
222209 }
223-
224- //
225- // Getting SuperTrend values is done using the
226- // GetSuperTrend(double &SuperTrendHighArray[], double &SuperTrendArray[], double &SuperTrendLowArray[], int start, int count)
227- // method. Example below:
228- //
229-
230- // HighArray[] array will store the values of the high SuperTrend line
231- // MidArray[] array will store the values of the SuperTrend value
232- // LowArray[] array will store the values of the low SuperTrend line
233-
234- startAtBar = 1 ; // get values starting from the last completed bar.
235- numberOfBars = 3 ; // gat a total of 3 values (for 3 bars starting from bar 1 (last completed))
236-
237- if (rangeBars .GetSuperTrend (HighArray ,MidArray ,LowArray ,startAtBar ,numberOfBars ))
238- {
239- //
240- // Apply your SuperTrend logic here...
241- //
242- }
243-
244210 }
245211}
0 commit comments