From 91e99e93cc2cb3ed5fcd7cec707e14dba80ef71f Mon Sep 17 00:00:00 2001 From: 9nix6 Date: Tue, 15 May 2018 19:27:24 +0200 Subject: [PATCH] Update to version 2.04 --- Experts/RangeBars_ExampleEA.mq5 | 6 +- Experts/RangeBars_ExampleEA2.mq5 | 6 +- Include/AZ-INVEST/SDK/CommonSettings.mqh | Bin 10014 -> 12394 bytes Include/AZ-INVEST/SDK/RangeBarIndicator.mqh | 32 ++-- Include/AZ-INVEST/SDK/RangeBarSettings.mqh | 133 +++++++++------- Include/AZ-INVEST/SDK/RangeBars.mqh | 96 +++++++++--- Indicators/RangeBars/RangeBars_ATR.mq5 | 144 ++++++++++++++++++ .../RangeBars/RangeBars_KeltnerChannel.mq5 | Bin 0 -> 19052 bytes 8 files changed, 326 insertions(+), 91 deletions(-) create mode 100644 Indicators/RangeBars/RangeBars_ATR.mq5 create mode 100644 Indicators/RangeBars/RangeBars_KeltnerChannel.mq5 diff --git a/Experts/RangeBars_ExampleEA.mq5 b/Experts/RangeBars_ExampleEA.mq5 index 02222d3..89f9494 100644 --- a/Experts/RangeBars_ExampleEA.mq5 +++ b/Experts/RangeBars_ExampleEA.mq5 @@ -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); diff --git a/Experts/RangeBars_ExampleEA2.mq5 b/Experts/RangeBars_ExampleEA2.mq5 index 012476d..162945e 100644 --- a/Experts/RangeBars_ExampleEA2.mq5 +++ b/Experts/RangeBars_ExampleEA2.mq5 @@ -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); diff --git a/Include/AZ-INVEST/SDK/CommonSettings.mqh b/Include/AZ-INVEST/SDK/CommonSettings.mqh index 33fcdbfa470462fadfe75cfd655759d40e2c09f4..78656e0744a2a53b16dd6fcbc5761bf2c642d135 100644 GIT binary patch delta 1268 zcmb7@&ubGw6vtl=(OSB!*;per>W+aPL|T)~CL4-}TI#8du_{s!s)D7Jg0u!ah?L$+ zPr^I<gO_ zJ+(7Oi?l$?bemRjuTU3NN)e6GbN88|N=dKkV8vamz6QGNo_DavB350+eT6Rnb8dm= zcCf|Y0!wJHO7mE8gKpuHmcv&6lR%T-JzmhPJDljv;EJe!Z+yDI-zKIfI`oL1p~C~( zMq(4yHuZQnsqy*b^of9!m#}Ic-#?+JxPtHaeeoD?CfD&iIWo(GGiCl>oOJYK@<}@N z-c2btrBG~8&7C@R=S0PCDi=WO0j&#-8`RL0 zw<-qA2JBVEAf0JOncuS+(5BzBr74?plFv1x+~?Z?Z98i5Ly*Z1&yUJeZDqZc4XjYP z6WGAY!m1i+C(Ghw11D6zk9M*&bh4zKtaGw~6DptAPL{;U#M&qu8uj;0ufU(D#^M_O zIlpveT!%&mQ`eLSrW!Q@a$w}OTFuBx)(uPVnE4%>dM$5VlzdAwYWaK~(A?8@K--`q z_NSAKN|^SML4ifu#=^$LG9;Dd15*W4#MziQ3z)c=NSk21Fp&Z2teBWsd&q!hD$0Pkh@lv)3#b;vo?Iwg%N`6A2bwzB dROB$ouFYzqzt}gY$$ntnET&$ 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)) diff --git a/Include/AZ-INVEST/SDK/RangeBarSettings.mqh b/Include/AZ-INVEST/SDK/RangeBarSettings.mqh index c53dcc4..51ff6be 100644 --- a/Include/AZ-INVEST/SDK/RangeBarSettings.mqh +++ b/Include/AZ-INVEST/SDK/RangeBarSettings.mqh @@ -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 } diff --git a/Include/AZ-INVEST/SDK/RangeBars.mqh b/Include/AZ-INVEST/SDK/RangeBars.mqh index 8e5e853..a34a0fc 100644 --- a/Include/AZ-INVEST/SDK/RangeBars.mqh +++ b/Include/AZ-INVEST/SDK/RangeBars.mqh @@ -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; +} diff --git a/Indicators/RangeBars/RangeBars_ATR.mq5 b/Indicators/RangeBars/RangeBars_ATR.mq5 new file mode 100644 index 0000000..ba03213 --- /dev/null +++ b/Indicators/RangeBars/RangeBars_ATR.mq5 @@ -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 +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;iNmn>rTV#QeZbEb z)nRp3^{R9IUTU88>ZI!Ej{CFfPW7t#TlI(%S(qI##U zTiw%VS=V3c*-Q016E5#`|Anr*YU_pXbG6J4AD~0?kNUgRJa06|%YemEXaUbo^_e)) z(G@(o6mJfy7wY>e++Ef1nHT+O4J6j8J{PV?wgE$M)=61zyo0HiTc<2@MKLrkHbi0bfPESzV4i;r+v_4*J;Bb;?vU{ml_3L9l>e~ zJ230$%5bFhwdS}|&mXF->Z@u~dig{3Oe0?C*_B3s)ij@|L-QrGk7OTc;zi&}FIWKD zmRrq&thL!Xtt~ACsg&kC3-Wj=o-S0A+k(NvbGaWa>)V?^9ajBXGHmJZN*eHEXhly- z80BM-_JVxI9r=#Cx^n%BGarbP9ceY1b*$d5$0ZA(E%q>br^QAe2+y}edDVo6=Hgc_ zHD|j4qt2g{_Lk;3(yUF0Epg{c&yM<>8^)#P$aXfeRoyS}>b_>h=CSFnuE8Cfy3!pU zZ<_g1I7lhZH!EAqSIC`!Z$~9yx^lm=3q}3*M*FU}(4!{`iq;w7DyddM6mp#l31@xNVAeZLNdbfs-2r zK0cGQ@^#j^Vt(a7kXa)Q+e1ZLSJLA%wXiO?B(-Vq#8VkWleUen`x@}+20JIVf`|CU zx)zR>DzOrJF%4!!ayH5^Td2Mk4z|J(fu&KX`SGT_bBnFxT+)WwSk9{WGp*$uOUo>F zjT-&muo`fE(x1D@!4i+6K7JUBG49R3#TcH~wU{zzUFWZ7DTdL4qFt=|Ao!now-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