Skip to content

Commit e6121f7

Browse files
committed
Updated for RangeBars ver. 3.00
1 parent bd957ab commit e6121f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1793
-1313
lines changed

Experts/RangeBars_ExampleEA.mq5

Lines changed: 33 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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
@@ -20,22 +22,17 @@
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
//+------------------------------------------------------------------+
3334
int 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
//+------------------------------------------------------------------+
5249
void 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+
7369
void 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
}

Experts/RangeBars_ExampleEA2.mq5

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#property copyright "Copyright 2017-18, AZ-iNVEST"
2-
#property link "http://www.az-invest.eu"
3-
#property version "1.10"
1+
#property copyright "Copyright 2017-2020, Level Up Software"
2+
#property link "https://www.az-invest.eu"
3+
#property version "1.11"
44
#property description "Example EA: Trading based on RangeBars SuperTrend signals."
55
#property description "One trade at a time. Each trade has TP & SL"
66

@@ -39,7 +39,7 @@ ulong currentTicket;
3939
// the RangeBars indicator attached.
4040
//
4141

42-
//#define SHOW_INDICATOR_INPUTS
42+
#define SHOW_INDICATOR_INPUTS
4343

4444
//
4545
// You need to include the RangeBars.mqh header file
@@ -48,23 +48,18 @@ ulong currentTicket;
4848
#include <AZ-INVEST/SDK/RangeBars.mqh>
4949
//
5050
// To use the RangeBars indicator in your EA you need do instantiate the indicator class (RangeBars)
51-
// and call the Init() method in your EA's OnInit() function.
52-
// Don't forget to release the indicator when you're done by calling the Deinit() method.
53-
// Example shown in OnInit & OnDeinit functions below:
51+
// and call the Init() and Deinit() methods in your EA's OnInit() and OnDeinit() functions.
52+
// Example shown below
5453
//
5554

56-
RangeBars * rangeBars;
55+
RangeBars rangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true);
5756
CMarketOrder * marketOrder;
5857

5958
//+------------------------------------------------------------------+
6059
//| Expert initialization function |
6160
//+------------------------------------------------------------------+
6261
int OnInit()
6362
{
64-
rangeBars = new RangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true);
65-
if(rangeBars == NULL)
66-
return(INIT_FAILED);
67-
6863
rangeBars.Init();
6964
if(rangeBars.GetHandle() == INVALID_HANDLE)
7065
return(INIT_FAILED);
@@ -93,11 +88,7 @@ int OnInit()
9388
//+------------------------------------------------------------------+
9489
void OnDeinit(const int reason)
9590
{
96-
if(rangeBars != NULL)
97-
{
98-
rangeBars.Deinit();
99-
delete rangeBars;
100-
}
91+
rangeBars.Deinit();
10192

10293
//
10394
// delete MarketOrder class
@@ -130,7 +121,7 @@ void OnTick()
130121

131122
//
132123
// Getting SuperTrend values is done using the
133-
// GetSuperTrend(double &SuperTrendHighArray[], double &SuperTrendArray[], double &SuperTrendLowArray[], int start, int count)
124+
// GetChannel(double &HighArray[], double &MidArray[], double &LowArray[], int start, int count)
134125
// method. Example below:
135126
//
136127

@@ -141,7 +132,7 @@ void OnTick()
141132
int startAtBar = 1; // get values starting from the last completed bar.
142133
int numberOfBars = 2; // gat a total of 3 values (for 3 bars starting from bar 1 (last completed))
143134

144-
if(rangeBars.GetSuperTrend(HighArray,MidArray,LowArray,startAtBar,numberOfBars))
135+
if(rangeBars.GetChannel(HighArray,MidArray,LowArray,startAtBar,numberOfBars))
145136
{
146137
//
147138
// Read signal bar's time for optional debug log
4.49 KB
Binary file not shown.
27.4 KB
Binary file not shown.
21.2 KB
Binary file not shown.
800 Bytes
Binary file not shown.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include <AZ-INVEST/SDK/CommonSettings.mqh>
2+
3+
#ifdef DEVELOPER_VERSION
4+
#define CUSTOM_CHART_NAME "RangeBars_TEST"
5+
#else
6+
#define CUSTOM_CHART_NAME "Range Bars"
7+
#endif
8+
9+
//
10+
// Tick chart specific settings
11+
//
12+
#ifdef SHOW_INDICATOR_INPUTS
13+
#ifdef MQL5_MARKET_DEMO // hardcoded values
14+
15+
int barSizeInTicks = 180; // Range bar size (in points)
16+
ENUM_BOOL atrEnabled = false; // Enable ATR based bar size calculation
17+
ENUM_TIMEFRAMES atrTimeFrame = PERIOD_D1; // Use ATR period
18+
int atrPeriod = 14; // ATR period
19+
int atrPercentage = 10; // Use percentage of ATR
20+
int showNumberOfDays = 7; // Show history for number of days
21+
ENUM_BOOL resetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
22+
23+
#else // user defined settings
24+
25+
26+
input int barSizeInTicks = 100; // Range bar size (in points)
27+
input ENUM_BOOL atrEnabled = false; // Enable ATR based bar size calculation
28+
ENUM_TIMEFRAMES atrTimeFrame = PERIOD_D1; // Use ATR period
29+
input int atrPeriod = 14; // ATR period
30+
input int atrPercentage = 10; // Use percentage of ATR
31+
32+
input int showNumberOfDays = 5; // Show history for number of days
33+
input ENUM_BOOL resetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
34+
35+
#endif
36+
#else // don't SHOW_INDICATOR_INPUTS
37+
int barSizeInTicks = 180; // Range bar size (in points)
38+
ENUM_BOOL atrEnabled = false; // Enable ATR based bar size calculation
39+
ENUM_TIMEFRAMES atrTimeFrame = PERIOD_D1; // Use ATR period
40+
int atrPeriod = 14; // ATR period
41+
int atrPercentage = 10; // Use percentage of ATR
42+
int showNumberOfDays = 7; // Show history for number of days
43+
ENUM_BOOL resetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
44+
#endif
45+
46+
//
47+
// Remaining settings are located in the include file below.
48+
// These are common for all custom charts
49+
//
50+
#include <az-invest/sdk/CustomChartSettingsBase.mqh>
51+
52+
struct RANGEBAR_SETTINGS
53+
{
54+
int barSizeInTicks;
55+
ENUM_BOOL atrEnabled;
56+
ENUM_TIMEFRAMES atrTimeFrame;
57+
int atrPeriod;
58+
int atrPercentage;
59+
int showNumberOfDays;
60+
ENUM_BOOL resetOpenOnNewTradingDay;
61+
};
62+
63+
64+
class CRangeBarCustomChartSettigns : public CCustomChartSettingsBase
65+
{
66+
protected:
67+
68+
RANGEBAR_SETTINGS settings;
69+
70+
public:
71+
72+
CRangeBarCustomChartSettigns();
73+
~CRangeBarCustomChartSettigns();
74+
75+
RANGEBAR_SETTINGS GetCustomChartSettings() { return this.settings; };
76+
77+
virtual void SetCustomChartSettings();
78+
virtual string GetSettingsFileName();
79+
virtual uint CustomChartSettingsToFile(int handle);
80+
virtual uint CustomChartSettingsFromFile(int handle);
81+
};
82+
83+
void CRangeBarCustomChartSettigns::CRangeBarCustomChartSettigns()
84+
{
85+
settingsFileName = GetSettingsFileName();
86+
}
87+
88+
void CRangeBarCustomChartSettigns::~CRangeBarCustomChartSettigns()
89+
{
90+
}
91+
92+
string CRangeBarCustomChartSettigns::GetSettingsFileName()
93+
{
94+
return CUSTOM_CHART_NAME+(string)ChartID()+".set";
95+
}
96+
97+
uint CRangeBarCustomChartSettigns::CustomChartSettingsToFile(int file_handle)
98+
{
99+
return FileWriteStruct(file_handle,this.settings);
100+
}
101+
102+
uint CRangeBarCustomChartSettigns::CustomChartSettingsFromFile(int file_handle)
103+
{
104+
return FileReadStruct(file_handle,this.settings);
105+
}
106+
107+
void CRangeBarCustomChartSettigns::SetCustomChartSettings()
108+
{
109+
settings.barSizeInTicks = barSizeInTicks;
110+
111+
settings.atrEnabled = atrEnabled;
112+
settings.atrTimeFrame = atrTimeFrame;
113+
settings.atrPeriod = atrPeriod;
114+
settings.atrPercentage = atrPercentage;
115+
settings.showNumberOfDays = showNumberOfDays;
116+
settings.resetOpenOnNewTradingDay = resetOpenOnNewTradingDay;
117+
}

0 commit comments

Comments
 (0)