Update to version 2.04
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#property copyright "Copyright 2017, AZ-iNVEST"
|
||||
#property copyright "Copyright 2017-18, AZ-iNVEST"
|
||||
#property link "http://www.az-invest.eu"
|
||||
#property version "2.05"
|
||||
#property version "2.06"
|
||||
#property description "Example EA showing the way to use the RangeBars class defined in RangeBars.mqh"
|
||||
|
||||
//
|
||||
@@ -32,7 +32,7 @@ RangeBars * rangeBars;
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
rangeBars = new RangeBars();
|
||||
rangeBars = new RangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true);
|
||||
if(rangeBars == NULL)
|
||||
return(INIT_FAILED);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#property copyright "Copyright 2017, AZ-iNVEST"
|
||||
#property copyright "Copyright 2017-18, AZ-iNVEST"
|
||||
#property link "http://www.az-invest.eu"
|
||||
#property version "1.00"
|
||||
#property version "1.10"
|
||||
#property description "Example EA: Trading based on RangeBars SuperTrend signals."
|
||||
#property description "One trade at a time. Each trade has TP & SL"
|
||||
|
||||
@@ -61,7 +61,7 @@ CMarketOrder * marketOrder;
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
rangeBars = new RangeBars();
|
||||
rangeBars = new RangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true);
|
||||
if(rangeBars == NULL)
|
||||
return(INIT_FAILED);
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,9 @@
|
||||
#property copyright "Copyright 2017, AZ-iNVEST"
|
||||
#property link "http://www.az-invest.eu"
|
||||
#property version "2.02"
|
||||
|
||||
input bool UseOnRangeBarChart = true; // Use this indicator on RangeBar chart
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBars.mqh>
|
||||
|
||||
class RangeBarIndicator
|
||||
@@ -68,7 +71,7 @@ class RangeBarIndicator
|
||||
|
||||
RangeBarIndicator::RangeBarIndicator(void)
|
||||
{
|
||||
rangeBars = new RangeBars();
|
||||
rangeBars = new RangeBars(UseOnRangeBarChart);
|
||||
if(rangeBars != NULL)
|
||||
rangeBars.Init();
|
||||
|
||||
@@ -99,6 +102,7 @@ bool RangeBarIndicator::CheckStatus(void)
|
||||
|
||||
bool RangeBarIndicator::NeedsReload(void)
|
||||
{
|
||||
|
||||
if(rangeBars.Reload())
|
||||
{
|
||||
Print("Chart settings changed - reloading indicator with new settings");
|
||||
@@ -117,8 +121,6 @@ bool RangeBarIndicator::OnCalculate(const int _rates_total,const int _prev_calcu
|
||||
Canvas_IsNewBar(_Time);
|
||||
Canvas_RatesTotalChangedBy(_rates_total);
|
||||
IsNewBar = rangeBars.IsNewBar();
|
||||
|
||||
firstRun = false;
|
||||
}
|
||||
|
||||
if(!CheckStatus())
|
||||
@@ -126,10 +128,12 @@ bool RangeBarIndicator::OnCalculate(const int _rates_total,const int _prev_calcu
|
||||
if(rangeBars != NULL)
|
||||
delete rangeBars;
|
||||
|
||||
rangeBars = new RangeBars();
|
||||
rangeBars = new RangeBars(UseOnRangeBarChart);
|
||||
if(rangeBars != NULL)
|
||||
rangeBars.Init();
|
||||
|
||||
Print("CheckStatus block failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -145,14 +149,24 @@ bool RangeBarIndicator::OnCalculate(const int _rates_total,const int _prev_calcu
|
||||
ArraySetAsSeries(this.Sell_volume,false);
|
||||
ArraySetAsSeries(this.BuySell_volume,false);
|
||||
|
||||
bool needsReload = (NeedsReload() || (!this.dataReady));
|
||||
|
||||
if(needsReload)
|
||||
if(firstRun)
|
||||
{
|
||||
GetOLHC(0,_rates_total);
|
||||
firstRun = false;
|
||||
NeedsReload();
|
||||
}
|
||||
|
||||
if(NeedsReload() || !this.dataReady)
|
||||
{
|
||||
GetOLHC(0,_rates_total);
|
||||
this.prev_calculated = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(NeedsReload() || !this.dataReady)
|
||||
{
|
||||
Print("NeedsReload/DataReady block failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if(needsReload || IsNewBar || canvasIsNewTime || (change != 0))
|
||||
|
||||
@@ -15,53 +15,60 @@ input int atrPercentage = 10; // Use p
|
||||
ENUM_TICK_PRICE_TYPE plotPrice = tickBid; // Build chart using
|
||||
input int showNumberOfDays = 14; // Show history for number of days
|
||||
input ENUM_BOOL resetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
|
||||
input double TopBottomPaddingPercentage = 0.30; // Use padding top/bottom (0.0 - 1.0)
|
||||
input ENUM_PIVOT_POINTS showPivots = ppNone; // Show pivot levels
|
||||
input ENUM_PIVOT_TYPE pivotPointCalculationType = ppHLC3; // Pivot point calculation method
|
||||
input color RColor = clrDodgerBlue; // Resistance line color
|
||||
input color PColor = clrGold; // Pivot line color
|
||||
input color SColor = clrFireBrick; // Support line color
|
||||
input color PDHColor = clrHotPink; // Previous day's high
|
||||
input color PDLColor = clrLightSkyBlue; // Previous day's low
|
||||
input color PDCColor = clrGainsboro; // Previous day's close
|
||||
input ENUM_BOOL showNextBarLevels = true; // Show current bar's close projections
|
||||
input color HighThresholdIndicatorColor = clrLime; // Bullish bar projection color
|
||||
input color LowThresholdIndicatorColor = clrRed; // Bearish bar projection color
|
||||
input ENUM_BOOL showCurrentBarOpenTime = true; // Display chart info and current bar's open time
|
||||
input color InfoTextColor = clrWhite; // Current bar's open time info color
|
||||
input ENUM_BOOL UseSoundSignalOnNewBar = false; // Play sound on new bar
|
||||
input ENUM_BOOL OnlySignalReversalBars = false; // Only signal reversals
|
||||
input ENUM_BOOL UseAlertWindow = false; // Display Alert window with new bar info
|
||||
input ENUM_BOOL SendPushNotifications = false; // Send new bar info push notification to smartphone
|
||||
input string SoundFileBull = "news.wav"; // Use sound file for bullish bar close
|
||||
input string SoundFileBear = "timeout.wav"; // Use sound file for bearish bar close
|
||||
input ENUM_BOOL MA1on = false; // Show first MA
|
||||
input int MA1period = 20; // 1st MA period
|
||||
input ENUM_MA_METHOD_EXT MA1method = _MODE_SMA; // 1st MA method
|
||||
input ENUM_APPLIED_PRICE MA1applyTo = PRICE_CLOSE; // 1st MA apply to
|
||||
input int MA1shift = 0; // 1st MA shift
|
||||
input ENUM_BOOL MA2on = false; // Show second MA
|
||||
input int MA2period = 50; // 2nd MA period
|
||||
input ENUM_MA_METHOD_EXT MA2method = _MODE_EMA; // 2nd MA method
|
||||
input ENUM_APPLIED_PRICE MA2applyTo = PRICE_CLOSE; // 2nd MA apply to
|
||||
input int MA2shift = 0; // 2nd MA shift
|
||||
input ENUM_BOOL MA3on = false; // Show third MA
|
||||
input int MA3period = 20; // 3rd MA period
|
||||
input ENUM_MA_METHOD_EXT MA3method = _VWAP_TICKVOL; // 3rd MA method
|
||||
input ENUM_APPLIED_PRICE MA3applyTo = PRICE_CLOSE; // 3rd MA apply to
|
||||
input int MA3shift = 0; // 3rd MA shift
|
||||
input ENUM_CHANNEL_TYPE ShowChannel = None; // Show Channel
|
||||
input string Channel_Settings = "-------------------"; // Channel settings
|
||||
input int DonchianPeriod = 20; // Donchian Channel period
|
||||
input ENUM_APPLIED_PRICE BBapplyTo = PRICE_CLOSE; // Bollinger Bands apply to
|
||||
input int BollingerBandsPeriod = 20; // Bollinger Bands period
|
||||
input double BollingerBandsDeviations = 2.0; // Bollinger Bands deviations
|
||||
input int SuperTrendPeriod = 10; // Super Trend period
|
||||
input double SuperTrendMultiplier=1.7; // Super Trend multiplier
|
||||
input string Misc_Settings = "-------------------"; // Misc settings
|
||||
input ENUM_BOOL DisplayAsBarChart = false; // Display as bar chart
|
||||
input ENUM_BOOL UsedInEA = false; // Indicator used in EA via iCustom()
|
||||
|
||||
#ifndef USE_CUSTOM_SYMBOL
|
||||
input double TopBottomPaddingPercentage = 0.30; // Use padding top/bottom (0.0 - 1.0)
|
||||
input ENUM_PIVOT_POINTS showPivots = ppNone; // Show pivot levels
|
||||
input ENUM_PIVOT_TYPE pivotPointCalculationType = ppHLC3; // Pivot point calculation method
|
||||
input color RColor = clrDodgerBlue; // Resistance line color
|
||||
input color PColor = clrGold; // Pivot line color
|
||||
input color SColor = clrFireBrick; // Support line color
|
||||
input color PDHColor = clrHotPink; // Previous day's high
|
||||
input color PDLColor = clrLightSkyBlue; // Previous day's low
|
||||
input color PDCColor = clrGainsboro; // Previous day's close
|
||||
input ENUM_BOOL showNextBarLevels = true; // Show current bar's close projections
|
||||
input color HighThresholdIndicatorColor = clrLime; // Bullish bar projection color
|
||||
input color LowThresholdIndicatorColor = clrRed; // Bearish bar projection color
|
||||
input ENUM_BOOL showCurrentBarOpenTime = true; // Display chart info and current bar's open time
|
||||
input color InfoTextColor = clrWhite; // Current bar's open time info color
|
||||
|
||||
input ENUM_BOOL NewBarAlert = false; // Alert on new a bar
|
||||
input ENUM_BOOL ReversalBarAlert = false; // Alert on reversal bar
|
||||
input ENUM_BOOL MaCrossAlert = false; // Alert on MA crossover
|
||||
input ENUM_BOOL UseAlertWindow = false; // Display alert in Alert Window
|
||||
input ENUM_BOOL UseSound = false; // Play sound on alert
|
||||
input ENUM_BOOL UsePushNotifications = false; // Send alert via push notification to a smartphone
|
||||
|
||||
input string SoundFileBull = "news.wav"; // Use sound file for bullish bar close
|
||||
input string SoundFileBear = "timeout.wav"; // Use sound file for bearish bar close
|
||||
input ENUM_BOOL MA1on = false; // Show first MA
|
||||
input int MA1period = 20; // 1st MA period
|
||||
input ENUM_MA_METHOD_EXT MA1method = _MODE_SMA; // 1st MA method
|
||||
input ENUM_APPLIED_PRICE MA1applyTo = PRICE_CLOSE; // 1st MA apply to
|
||||
input int MA1shift = 0; // 1st MA shift
|
||||
input ENUM_BOOL MA2on = false; // Show second MA
|
||||
input int MA2period = 50; // 2nd MA period
|
||||
input ENUM_MA_METHOD_EXT MA2method = _MODE_EMA; // 2nd MA method
|
||||
input ENUM_APPLIED_PRICE MA2applyTo = PRICE_CLOSE; // 2nd MA apply to
|
||||
input int MA2shift = 0; // 2nd MA shift
|
||||
input ENUM_BOOL MA3on = false; // Show third MA
|
||||
input int MA3period = 20; // 3rd MA period
|
||||
input ENUM_MA_METHOD_EXT MA3method = _VWAP_TICKVOL; // 3rd MA method
|
||||
input ENUM_APPLIED_PRICE MA3applyTo = PRICE_CLOSE; // 3rd MA apply to
|
||||
input int MA3shift = 0; // 3rd MA shift
|
||||
input ENUM_CHANNEL_TYPE ShowChannel = None; // Show Channel
|
||||
input string Channel_Settings = "-------------------"; // Channel settings
|
||||
input int DonchianPeriod = 20; // Donchian Channel period
|
||||
input ENUM_APPLIED_PRICE BBapplyTo = PRICE_CLOSE; // Bollinger Bands apply to
|
||||
input int BollingerBandsPeriod = 20; // Bollinger Bands period
|
||||
input double BollingerBandsDeviations = 2.0; // Bollinger Bands deviations
|
||||
input int SuperTrendPeriod = 10; // Super Trend period
|
||||
input double SuperTrendMultiplier=1.7; // Super Trend multiplier
|
||||
input string Misc_Settings = "-------------------"; // Misc settings
|
||||
input ENUM_BOOL DisplayAsBarChart = false; // Display as bar chart
|
||||
input ENUM_BOOL ShiftObj = false; // Shift objects with chart
|
||||
input ENUM_BOOL UsedInEA = false; // Indicator used in EA via iCustom()
|
||||
#endif
|
||||
#else
|
||||
|
||||
//
|
||||
@@ -82,13 +89,18 @@ input ENUM_BOOL UsedInEA = false; // Indic
|
||||
color LowThresholdIndicatorColor = clrNONE;
|
||||
ENUM_BOOL showCurrentBarOpenTime = false;
|
||||
color InfoTextColor = clrNONE;
|
||||
ENUM_BOOL UseSoundSignalOnNewBar = false;
|
||||
ENUM_BOOL OnlySignalReversalBars = false;
|
||||
ENUM_BOOL UseAlertWindow = false;
|
||||
ENUM_BOOL SendPushNotifications = false;
|
||||
|
||||
ENUM_BOOL NewBarAlert = false;
|
||||
ENUM_BOOL ReversalBarAlert = false;
|
||||
ENUM_BOOL MaCrossAlert = false;
|
||||
ENUM_BOOL UseAlertWindow = false;
|
||||
ENUM_BOOL UseSound = false;
|
||||
ENUM_BOOL UsePushNotifications = false;
|
||||
|
||||
string SoundFileBull = "";
|
||||
string SoundFileBear = "";
|
||||
ENUM_BOOL DisplayAsBarChart = true;
|
||||
ENUM_BOOL ShiftObj = false;
|
||||
ENUM_BOOL UsedInEA = true; // This should always be set to TRUE for EAs & Indicators
|
||||
|
||||
//
|
||||
@@ -172,10 +184,11 @@ void RangeBarSettings::Save(void)
|
||||
//
|
||||
// Store chart type identifier
|
||||
//
|
||||
|
||||
/*
|
||||
handle = FileOpen(this.chartTypeFileName,FILE_SHARE_READ|FILE_WRITE|FILE_ANSI);
|
||||
FileWriteString(handle,CUSTOM_CHART_NAME);
|
||||
FileClose(handle);
|
||||
*/
|
||||
}
|
||||
|
||||
void RangeBarSettings::Delete(void)
|
||||
@@ -261,7 +274,8 @@ void RangeBarSettings::Set(void)
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
#ifndef USE_CUSTOM_SYMBOL
|
||||
chartIndicatorSettings.MA1on = MA1on;
|
||||
chartIndicatorSettings.MA1period = MA1period;
|
||||
chartIndicatorSettings.MA1method = MA1method;
|
||||
@@ -290,6 +304,7 @@ void RangeBarSettings::Set(void)
|
||||
chartIndicatorSettings.BollingerBandsDeviations = BollingerBandsDeviations;
|
||||
chartIndicatorSettings.SuperTrendPeriod = SuperTrendPeriod;
|
||||
chartIndicatorSettings.SuperTrendMultiplier = SuperTrendMultiplier;
|
||||
chartIndicatorSettings.ShiftObj = ShiftObj;
|
||||
chartIndicatorSettings.UsedInEA = UsedInEA;
|
||||
|
||||
//
|
||||
@@ -310,14 +325,18 @@ void RangeBarSettings::Set(void)
|
||||
alertInfoSettings.LowThresholdIndicatorColor = LowThresholdIndicatorColor;
|
||||
alertInfoSettings.showCurrentBarOpenTime = showCurrentBarOpenTime;
|
||||
alertInfoSettings.InfoTextColor = InfoTextColor;
|
||||
alertInfoSettings.UseSoundSignalOnNewBar = UseSoundSignalOnNewBar;
|
||||
alertInfoSettings.OnlySignalReversalBars = OnlySignalReversalBars;
|
||||
alertInfoSettings.UseAlertWindow = UseAlertWindow;
|
||||
alertInfoSettings.SendPushNotifications = SendPushNotifications;
|
||||
|
||||
alertInfoSettings.NewBarAlert = NewBarAlert;
|
||||
alertInfoSettings.ReversalBarAlert = ReversalBarAlert;
|
||||
alertInfoSettings.MaCrossAlert = MaCrossAlert ;
|
||||
alertInfoSettings.UseAlertWindow = UseAlertWindow;
|
||||
alertInfoSettings.UseSound = UseSound;
|
||||
alertInfoSettings.UsePushNotifications = UsePushNotifications;
|
||||
|
||||
alertInfoSettings.SoundFileBull = SoundFileBull;
|
||||
alertInfoSettings.SoundFileBear = SoundFileBear;
|
||||
alertInfoSettings.DisplayAsBarChart = DisplayAsBarChart;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#property copyright "Copyright 2017, AZ-iNVEST"
|
||||
#property link "http://www.az-invest.eu"
|
||||
|
||||
//#define RANGEBAR_INDICATOR_NAME "RangeBars\\RangeBarsOverlay204"
|
||||
#define RANGEBAR_INDICATOR_NAME "Market\\Range Bars Charting"
|
||||
//#define RANGEBAR_INDICATOR_NAME "RangeBars\\RangeBarsOverlay203"
|
||||
|
||||
#define RANGEBAR_OPEN 00
|
||||
#define RANGEBAR_HIGH 01
|
||||
@@ -41,10 +41,12 @@ class RangeBars
|
||||
|
||||
int rangeBarsHandle;
|
||||
string rangeBarsSymbol;
|
||||
bool usedByIndicatorOnRangeBarChart;
|
||||
|
||||
public:
|
||||
|
||||
RangeBars();
|
||||
RangeBars(bool isUsedByIndicatorOnRangeBarChart);
|
||||
RangeBars(string symbol);
|
||||
~RangeBars(void);
|
||||
|
||||
@@ -67,7 +69,7 @@ class RangeBars
|
||||
private:
|
||||
|
||||
bool GetChannel(double &HighArray[], double &MidArray[], double &LowArray[], int start, int count);
|
||||
|
||||
int GetIndicatorHandle(void);
|
||||
};
|
||||
|
||||
RangeBars::RangeBars(void)
|
||||
@@ -76,6 +78,15 @@ RangeBars::RangeBars(void)
|
||||
rangeBarSettings = new RangeBarSettings();
|
||||
rangeBarsHandle = INVALID_HANDLE;
|
||||
rangeBarsSymbol = _Symbol;
|
||||
usedByIndicatorOnRangeBarChart = false;
|
||||
}
|
||||
|
||||
RangeBars::RangeBars(bool isUsedByIndicatorOnRangeBarChart)
|
||||
{
|
||||
rangeBarSettings = new RangeBarSettings();
|
||||
rangeBarsHandle = INVALID_HANDLE;
|
||||
rangeBarsSymbol = _Symbol;
|
||||
usedByIndicatorOnRangeBarChart = isUsedByIndicatorOnRangeBarChart;
|
||||
}
|
||||
|
||||
RangeBars::RangeBars(string symbol)
|
||||
@@ -84,6 +95,7 @@ RangeBars::RangeBars(string symbol)
|
||||
rangeBarSettings = new RangeBarSettings();
|
||||
rangeBarsHandle = INVALID_HANDLE;
|
||||
rangeBarsSymbol = symbol;
|
||||
usedByIndicatorOnRangeBarChart = false;
|
||||
}
|
||||
|
||||
RangeBars::~RangeBars(void)
|
||||
@@ -100,6 +112,15 @@ int RangeBars::Init()
|
||||
{
|
||||
if(!MQLInfoInteger((int)MQL5_TESTING))
|
||||
{
|
||||
if(usedByIndicatorOnRangeBarChart)
|
||||
{
|
||||
//
|
||||
// Indicator on RangeBar chart uses the values of the RangeBar chart for calculations
|
||||
//
|
||||
rangeBarsHandle = GetIndicatorHandle();
|
||||
return rangeBarsHandle;
|
||||
}
|
||||
|
||||
if(!rangeBarSettings.Load())
|
||||
{
|
||||
if(rangeBarsHandle != INVALID_HANDLE)
|
||||
@@ -121,17 +142,28 @@ int RangeBars::Init()
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef SHOW_INDICATOR_INPUTS
|
||||
if(usedByIndicatorOnRangeBarChart)
|
||||
{
|
||||
//
|
||||
// Load settings from EA inputs
|
||||
//
|
||||
rangeBarSettings.Load();
|
||||
#else
|
||||
//
|
||||
// Save indicator inputs for use by EA attached to same chart.
|
||||
//
|
||||
rangeBarSettings.Save();
|
||||
#endif
|
||||
// Indicator on RangeBar chart uses the values of the RangeBar chart for calculations
|
||||
//
|
||||
rangeBarsHandle = GetIndicatorHandle();
|
||||
return rangeBarsHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef SHOW_INDICATOR_INPUTS
|
||||
//
|
||||
// Load settings from EA inputs
|
||||
//
|
||||
rangeBarSettings.Load();
|
||||
#else
|
||||
//
|
||||
// Save indicator inputs for use by EA attached to same chart.
|
||||
//
|
||||
rangeBarSettings.Save();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
RANGEBAR_SETTINGS s = rangeBarSettings.GetRangeBarSettings();
|
||||
@@ -161,10 +193,12 @@ int RangeBars::Init()
|
||||
LowThresholdIndicatorColor,
|
||||
showCurrentBarOpenTime,
|
||||
InfoTextColor,
|
||||
UseSoundSignalOnNewBar,
|
||||
OnlySignalReversalBars,
|
||||
NewBarAlert,
|
||||
ReversalBarAlert,
|
||||
MaCrossAlert,
|
||||
UseAlertWindow,
|
||||
SendPushNotifications,
|
||||
UseSound,
|
||||
UsePushNotifications,
|
||||
SoundFileBull,
|
||||
SoundFileBear,
|
||||
cis.MA1on,
|
||||
@@ -192,6 +226,7 @@ int RangeBars::Init()
|
||||
cis.SuperTrendMultiplier,
|
||||
"",
|
||||
DisplayAsBarChart,
|
||||
ShiftObj,
|
||||
UsedInEA);
|
||||
|
||||
|
||||
@@ -233,10 +268,13 @@ void RangeBars::Deinit()
|
||||
if(rangeBarsHandle == INVALID_HANDLE)
|
||||
return;
|
||||
|
||||
if(IndicatorRelease(rangeBarsHandle))
|
||||
Print("RangeBar indicator handle released");
|
||||
else
|
||||
Print("Failed to release RangeBar indicator handle");
|
||||
if(!usedByIndicatorOnRangeBarChart)
|
||||
{
|
||||
if(IndicatorRelease(rangeBarsHandle))
|
||||
Print("RangeBar indicator handle released");
|
||||
else
|
||||
Print("Failed to release RangeBar indicator handle");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -535,3 +573,23 @@ bool RangeBars::GetChannel(double &HighArray[], double &MidArray[], double &LowA
|
||||
#endif
|
||||
}
|
||||
|
||||
int RangeBars::GetIndicatorHandle(void)
|
||||
{
|
||||
int i = ChartIndicatorsTotal(0,0);
|
||||
int j=0;
|
||||
string iName;
|
||||
|
||||
while(j < i)
|
||||
{
|
||||
iName = ChartIndicatorName(0,0,j);
|
||||
if(StringFind(iName,CUSTOM_CHART_NAME) != -1)
|
||||
{
|
||||
Print("Using handle of "+iName);
|
||||
return ChartIndicatorGet(0,0,iName);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
||||
Print("Failed getting handle of "+CUSTOM_CHART_NAME);
|
||||
return INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ATR.mq5 |
|
||||
//| Copyright 2009-2017, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009-2017, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property description "Average True Range"
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 DodgerBlue
|
||||
#property indicator_label1 "ATR"
|
||||
//--- input parameters
|
||||
input int InpAtrPeriod=14; // ATR period
|
||||
//--- indicator buffers
|
||||
double ExtATRBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
//--- global variable
|
||||
int ExtPeriodATR;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator rangeBarsIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(InpAtrPeriod<=0)
|
||||
{
|
||||
ExtPeriodATR=14;
|
||||
printf("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",InpAtrPeriod,ExtPeriodATR);
|
||||
}
|
||||
else ExtPeriodATR=InpAtrPeriod;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpAtrPeriod);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name="ATR("+string(ExtPeriodATR)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- initialization done
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Average True Range |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
//
|
||||
// Make the following modifications in the code below:
|
||||
//
|
||||
// rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated
|
||||
//
|
||||
// rangeBarsIndicator.Open[] should be used instead of open[]
|
||||
// rangeBarsIndicator.Low[] should be used instead of low[]
|
||||
// rangeBarsIndicator.High[] should be used instead of high[]
|
||||
// rangeBarsIndicator.Close[] should be used instead of close[]
|
||||
//
|
||||
// rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed
|
||||
//
|
||||
// rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time.
|
||||
// (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[]
|
||||
// rangeBarsIndicator.Real_volume[] should be used instead of Volume[]
|
||||
// (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used
|
||||
//
|
||||
// rangeBarsIndicator.Price[] should be used instead of Price[]
|
||||
// (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used
|
||||
//
|
||||
|
||||
int _prev_calculated = rangeBarsIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int i,limit;
|
||||
//--- check for bars count
|
||||
if(rates_total<=ExtPeriodATR)
|
||||
return(0); // not enough bars for calculation
|
||||
//--- preliminary calculations
|
||||
if(_prev_calculated==0)
|
||||
{
|
||||
ExtTRBuffer[0]=0.0;
|
||||
ExtATRBuffer[0]=0.0;
|
||||
//--- filling out the array of True Range values for each period
|
||||
for(i=1;i<rates_total && !IsStopped();i++)
|
||||
ExtTRBuffer[i]=MathMax(rangeBarsIndicator.High[i],rangeBarsIndicator.Close[i-1])-MathMin(rangeBarsIndicator.Low[i],rangeBarsIndicator.Close[i-1]);
|
||||
//--- first AtrPeriod values of the indicator are not calculated
|
||||
double firstValue=0.0;
|
||||
for(i=1;i<=ExtPeriodATR;i++)
|
||||
{
|
||||
ExtATRBuffer[i]=0.0;
|
||||
firstValue+=ExtTRBuffer[i];
|
||||
}
|
||||
//--- calculating the first value of the indicator
|
||||
firstValue/=ExtPeriodATR;
|
||||
ExtATRBuffer[ExtPeriodATR]=firstValue;
|
||||
limit=ExtPeriodATR+1;
|
||||
}
|
||||
else limit=_prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(i=limit;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtTRBuffer[i]=MathMax(rangeBarsIndicator.High[i],rangeBarsIndicator.Close[i-1])-MathMin(rangeBarsIndicator.Low[i],rangeBarsIndicator.Close[i-1]);
|
||||
ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-ExtPeriodATR])/ExtPeriodATR;
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Reference in New Issue
Block a user