diff --git a/Experts/2MA_Cross.mq5 b/Experts/2MA_Cross.mq5 index f418770..e4f4636 100644 --- a/Experts/2MA_Cross.mq5 +++ b/Experts/2MA_Cross.mq5 @@ -1,6 +1,6 @@ -#property copyright "Copyright 2017-2019, Artur Zas" +#property copyright "Copyright 2017-2020, Artur Zas" #property link "https://www.az-invest.eu" -#property version "1.10" +#property version "1.11" // // Uncomment only ONE of the 3 directives listed below and recompile @@ -22,15 +22,15 @@ #ifdef EA_ON_RANGE_BARS #include - RangeBars customBars = RangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + RangeBars *customBars = NULL; #endif #ifdef EA_ON_RENKO #include - MedianRenko customBars = MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + MedianRenko *customBars = NULL; #endif #ifdef EA_ON_XTICK_CHART #include - TickChart customBars = TickChart(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + TickChart *customBars = NULL; #endif #include @@ -65,8 +65,8 @@ int numberOfBars = 3; // EA variables -CMarketOrder *marketOrder; -CTimeControl timeControl; +CMarketOrder *marketOrder = NULL; +CTimeControl *timeControl = NULL; ulong currentTicket; ENUM_POSITION_TYPE currentPositionType; @@ -91,6 +91,19 @@ ENUM_POSITION_TYPE validation; //+------------------------------------------------------------------+ int OnInit() { + if(customBars == NULL) + { + #ifdef EA_ON_RANGE_BARS + customBars = new RangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + #endif + #ifdef EA_ON_RENKO + customBars = new MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + #endif + #ifdef EA_ON_XTICK_CHART + customBars = new TickChart(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + #endif + } + customBars.Init(); if(customBars.GetHandle() == INVALID_HANDLE) return(INIT_FAILED); @@ -111,6 +124,11 @@ int OnInit() marketOrder = new CMarketOrder(params); + if(timeControl == NULL) + { + timeControl = new CTimeControl(); + } + timeControl.SetValidTraingHours(Start,End); return(INIT_SUCCEEDED); @@ -121,9 +139,30 @@ int OnInit() void OnDeinit(const int reason) { customBars.Deinit(); + + // delete TimeControl class + + if(timeControl != NULL) + { + delete timeControl; + timeControl = NULL; + } + // delete MarketOrder class + if(marketOrder != NULL) + { delete marketOrder; + marketOrder = NULL; + } + + // delete MedianRenko class + + if(customBars != NULL) + { + delete customBars; + customBars = NULL; + } Comment(""); } @@ -132,7 +171,7 @@ void OnDeinit(const int reason) //+------------------------------------------------------------------+ void OnTick() { - if(marketOrder == NULL) + if(marketOrder == NULL || customBars == NULL || timeControl == NULL) return; if(customBars.IsNewBar()) diff --git a/Experts/ExampleEA.mq5 b/Experts/ExampleEA.mq5 index c9cd39e..f7f4afb 100644 --- a/Experts/ExampleEA.mq5 +++ b/Experts/ExampleEA.mq5 @@ -1,12 +1,12 @@ // -// Copyright 2017-2019, Artur Zas +// Copyright 2017-2020, Artur Zas // https://www.az-invest.eu // https://www.mql5.com/en/users/arturz // -#property copyright "Copyright 2017-2019, Artur Zas" +#property copyright "Copyright 2017-2020, Artur Zas" #property link "https://www.mql5.com/en/users/arturz" -#property version "3.00" +#property version "3.01" #property description "Example EA showing the way to use the MedianRenko class defined in MedianRenko.mqh" // @@ -31,13 +31,16 @@ // Example shown in OnInit & OnDeinit functions below: // -MedianRenko medianRenko = MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); +MedianRenko *medianRenko = NULL; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { + if(medianRenko == NULL) + medianRenko = new MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + medianRenko.Init(); if(medianRenko.GetHandle() == INVALID_HANDLE) return(INIT_FAILED); @@ -54,6 +57,16 @@ int OnInit() void OnDeinit(const int reason) { medianRenko.Deinit(); + + // + // delete MedianRenko class + // + + if(medianRenko != NULL) + { + delete medianRenko; + medianRenko = NULL; + } // // your custom code goes here... diff --git a/Experts/ExampleEA3.mq5 b/Experts/ExampleEA3.mq5 index 7060be1..73b68eb 100644 --- a/Experts/ExampleEA3.mq5 +++ b/Experts/ExampleEA3.mq5 @@ -1,12 +1,12 @@ // -// Copyright 2017-2019, Artur Zas +// Copyright 2017-2020, Artur Zas // https://www.az-invest.eu // https://www.mql5.com/en/users/arturz // -#property copyright "Copyright 2017-2019, AZ-iNVEST" -#property link "http://www.az-invest.eu" -#property version "1.10" +#property copyright "Copyright 2017-2020, Artur Zas" +#property link "https://www.az-invest.eu" +#property version "1.11" #property description "Example EA showing the way to use the MedianRenko class defined in MedianRenko.mqh" #property description "as well as external indicators attached to the RenkoCharts" @@ -34,17 +34,20 @@ input int InpRSIPeriod=14; // RSI Period // Example shown in OnInit & OnDeinit functions below: // -MedianRenko medianRenko = MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); -int RsiHandle = -1; +MedianRenko *medianRenko = NULL; +int RsiHandle = -1; -double RsiBuffer[]; // This array will store the RSI values for the renko chart -MqlRates RenkoRatesInfoArray[]; // This array will store the MqlRates data for renkos +double RsiBuffer[]; // This array will store the RSI values for the renko chart +MqlRates RenkoRatesInfoArray[]; // This array will store the MqlRates data for renkos //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { + if(medianRenko == NULL) + medianRenko = new MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + medianRenko.Init(); if(medianRenko.GetHandle() == INVALID_HANDLE) return(INIT_FAILED); @@ -58,6 +61,16 @@ void OnDeinit(const int reason) { medianRenko.Deinit(); + // + // delete MedianRenko class + // + + if(medianRenko != NULL) + { + delete medianRenko; + medianRenko = NULL; + } + // // your custom code goes here... // diff --git a/Experts/PriceMA_Cross.mq5 b/Experts/PriceMA_Cross.mq5 index fb1e0f9..ae3f727 100644 --- a/Experts/PriceMA_Cross.mq5 +++ b/Experts/PriceMA_Cross.mq5 @@ -22,15 +22,15 @@ #ifdef EA_ON_RANGE_BARS #include - RangeBars customBars = RangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + RangeBars *customBars = NULL; #endif #ifdef EA_ON_RENKO #include - MedianRenko customBars = MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + MedianRenko *customBars = NULL; #endif #ifdef EA_ON_XTICK_CHART #include - TickChart customBars = TickChart(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + TickChart *customBars = NULL; #endif #include @@ -64,7 +64,7 @@ int numberOfBars = 4; // EA variables CMarketOrder *marketOrder; -CTimeControl timeControl; +CTimeControl *timeControl; ulong currentTicket; ENUM_POSITION_TYPE currentPositionType; @@ -89,6 +89,19 @@ ENUM_POSITION_TYPE validation; //+------------------------------------------------------------------+ int OnInit() { + if(customBars == NULL) + { + #ifdef EA_ON_RANGE_BARS + customBars = new RangeBars(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + #endif + #ifdef EA_ON_RENKO + customBars = new MedianRenko(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + #endif + #ifdef EA_ON_XTICK_CHART + customBars = new TickChart(MQLInfoInteger((int)MQL5_TESTING) ? false : true); + #endif + } + customBars.Init(); signal = POSITION_TYPE_NONE; @@ -107,6 +120,11 @@ int OnInit() marketOrder = new CMarketOrder(params); + if(timeControl == NULL) + { + timeControl = new CTimeControl(); + } + timeControl.SetValidTraingHours(Start,End); return(INIT_SUCCEEDED); @@ -117,9 +135,30 @@ int OnInit() void OnDeinit(const int reason) { customBars.Deinit(); + + // delete TimeControl class + + if(timeControl != NULL) + { + delete timeControl; + timeControl = NULL; + } + // delete MarketOrder class + if(marketOrder != NULL) + { delete marketOrder; + marketOrder = NULL; + } + + // delete MedianRenko class + + if(customBars != NULL) + { + delete customBars; + customBars = NULL; + } Comment(""); }