diff --git a/BasicTrade.mqh b/BasicTrade.mqh deleted file mode 100644 index b59ad5622..000000000 --- a/BasicTrade.mqh +++ /dev/null @@ -1,478 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * @file - * Provides basic trade functionality. - */ - -// Class dependencies. -#ifdef __MQL5__ -class CTrade; -#endif - -//--- -#define CUR 0 -#define PREV 1 -#define FAR 2 -//--- -#define ERR_ORDER_SELECT ERR_USER_ERROR_FIRST + 102 -#define ERR_INVALID_ORDER_TYPE ERR_USER_ERROR_FIRST + 103 -#define ERR_INVALID_SYMBOL_NAME ERR_USER_ERROR_FIRST + 104 -#define ERR_INVALID_EXPIRATION_TIME ERR_USER_ERROR_FIRST + 105 -//--- -#define TRADE_PAUSE_SHORT 500 -#define TRADE_PAUSE_LONG 5000 -#define OPEN_METHODS 8 - -#ifdef __MQL4__ -//+------------------------------------------------------------------+ -//| ENUM_APPLIED_VOLUME | -//+------------------------------------------------------------------+ -enum ENUM_APPLIED_VOLUME { - VOLUME_TICK, - VOLUME_REAL -}; -#endif - -//+------------------------------------------------------------------+ -#ifdef __MQL4__ -#define TFS 9 -const ENUM_TIMEFRAMES tf[TFS] = { - PERIOD_M1,PERIOD_M5,PERIOD_M15, - PERIOD_M30,PERIOD_H1,PERIOD_H4, - PERIOD_D1,PERIOD_W1,PERIOD_MN1 -}; -#endif - -//+------------------------------------------------------------------+ -#ifdef __MQL5__ - -#define TFS 21 -const ENUM_TIMEFRAMES tf[TFS] = { - PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6, - PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M20,PERIOD_M30,PERIOD_H1, - PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12, - PERIOD_D1,PERIOD_W1,PERIOD_MN1 -}; -#endif -//+------------------------------------------------------------------+ -//| TPositionCount | -//+------------------------------------------------------------------+ -struct TPositionCount { - int buy_count; - int sell_count; -}; -//+------------------------------------------------------------------+ -//| TDealTime | -//+------------------------------------------------------------------+ -struct TDealTime -{ - datetime buy_time; - datetime sell_time; -}; -//+------------------------------------------------------------------+ -//| ENUN_OPEN_METHOD | -//+------------------------------------------------------------------+ -enum ENUM_OPEN_METHOD -{ - OPEN_METHOD_ONE=-1,// One Of Methods - OPEN_METHOD_SUM=0,// Sum Of Methods - OPEN_METHOD1=1, // Method #1 (1) - OPEN_METHOD2=2, // Method #2 (2) - OPEN_METHOD3=4, // Method #3 (4) - OPEN_METHOD4=8, // Method #4 (8) - OPEN_METHOD5=16, // Method #5 (16) - OPEN_METHOD6=32, // Method #6 (32) - OPEN_METHOD7=64, // Method #7 (64) - OPEN_METHOD8=128 // Method #8 (128) -}; -//+------------------------------------------------------------------+ -//| GetOpenMethod | -//+------------------------------------------------------------------+ -int GetOpenMethod(const int open_method,const int one_of_methods,const int sum_of_methods) -{ - int result=open_method; - - if(open_method==OPEN_METHOD_ONE) - result=-one_of_methods; - - if(open_method==OPEN_METHOD_SUM) - result=sum_of_methods; - - return(result); -} -//+------------------------------------------------------------------+ -//| ENUM_TRADE_DIRECTION | -//+------------------------------------------------------------------+ -enum ENUM_TRADE_DIRECTION -{ - TRADE_NONE=-1, //None - TRADE_BUY=0, //Buy - TRADE_SELL=1, //Sell - TRADE_BOTH=2 //Both -}; -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -enum ENUM_RUN_MODE -{ - RUN_OPTIMIZATION, - RUN_VISUAL, - RUN_TESTER, - RUN_LIVE -}; -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -ENUM_RUN_MODE GetRunMode(void) -{ - if(MQLInfoInteger(MQL_OPTIMIZATION)) - return(RUN_OPTIMIZATION); - if(MQLInfoInteger(MQL_VISUAL_MODE)) - return(RUN_VISUAL); - if(MQLInfoInteger(MQL_TESTER)) - return(RUN_TESTER); - return(RUN_LIVE); -} -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -string BoolToString(const bool _value) -{ - if(_value) - return("yes"); - return("no"); -} -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -string TimeframeToString(const ENUM_TIMEFRAMES _tf) -{ - return(StringSubstr(EnumToString(_tf),7)); -} -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -string OpenMethodToString(const ENUM_OPEN_METHOD _open_method, - const int one_of_methods, - const int sum_of_methods) -{ - string result=""; - switch(_open_method) - { - case OPEN_METHOD_ONE: result="One Of Methods ("+IntegerToString(one_of_methods)+")"; break; - case OPEN_METHOD_SUM: result="Sum Of Methods ("+IntegerToString(sum_of_methods)+")"; break; - default: result=StringSubstr(EnumToString(_open_method),5); break; - } - return(result); -} - -//+------------------------------------------------------------------+ -//| CBasicTrade | -//+------------------------------------------------------------------+ -class CBasicTrade -{ - private: - int m_last_error; - - protected: - //+------------------------------------------------------------------+ - double NormalizeVolume(const double _volume) - { - double lot_min=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN); - double lot_max=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX); - double lot_step=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP); - //--- - double lot_value=_volume; - if(lot_value<=lot_min)lot_value=lot_min; - else if(lot_value>=lot_max)lot_value=lot_max; - else lot_value=round(lot_value/lot_step)*lot_step; - //--- - return(NormalizeDouble(lot_value,2)); - } - - //+------------------------------------------------------------------+ - int TimeframeToIndex(ENUM_TIMEFRAMES _tf) - { - if(_tf==0 || _tf==PERIOD_CURRENT) - _tf=(ENUM_TIMEFRAMES)_Period; - int total=ArraySize(tf); - for(int i=0;i0) - { - ResetLastError(); - - if(IsTradeContextBusy()) - { - Sleep(TRADE_PAUSE_SHORT); - attempts--; - continue; - } - - RefreshRates(); - - //--- check the free margin - if(AccountFreeMarginCheck(_symbol,_type,_volume)<=0 || _LastError==ERR_NOT_ENOUGH_MONEY) - { - m_last_error=ERR_NOT_ENOUGH_MONEY; - return(false); - } - - //--- - double price=0.0; - if(_type==OP_BUY) - price=NormalizeDouble(SymbolInfoDouble(_symbol,SYMBOL_ASK),_digits); - if(_type==OP_SELL) - price=NormalizeDouble(SymbolInfoDouble(_symbol,SYMBOL_BID),_digits); - - //--- - int slippage=(int)SymbolInfoInteger(_symbol,SYMBOL_SPREAD); - - //--- - double volume=NormalizeVolume(_volume); - - //--- - int ticket=OrderSend(_symbol,_type,volume,price,slippage,0,0,_comment,_magic,0,clrNONE); - if(ticket>0) - { - if(_stop_loss>0 || _take_profit>0) - { - - if(OrderSelect(ticket,SELECT_BY_TICKET)) - { - - //--- - double order_open_price=NormalizeDouble(OrderOpenPrice(),_digits); - double order_stop_loss=NormalizeDouble(OrderStopLoss(),_digits); - double order_take_profit=NormalizeDouble(OrderTakeProfit(),_digits); - - double sl=0.0; - double tp=0.0; - - //--- - attempts=5; - while(attempts>0) - { - ResetLastError(); - RefreshRates(); - //--- - double _bid = SymbolInfoDouble(_symbol, SYMBOL_BID); - double _ask = SymbolInfoDouble(_symbol, SYMBOL_ASK); - - if(IsTradeContextBusy()) - { - attempts--; - Sleep(TRADE_PAUSE_SHORT); - continue; - } - - //--- - int stop_level=(int)SymbolInfoInteger(_symbol,SYMBOL_TRADE_STOPS_LEVEL); - int spread=(int)SymbolInfoInteger(_symbol,SYMBOL_SPREAD); - stop_level=fmax(stop_level,spread); - - //--- - if(OrderType()==OP_BUY) - { - if(_stop_loss==-1.0) sl=order_stop_loss; - else if(_stop_loss==0.0) sl=0.0; - else sl=NormalizeDouble(fmin(order_open_price-_stop_loss*_coef_point*_point,_bid-stop_level*_point),_digits); - - if(_take_profit==-1.0) tp=order_take_profit; - else if(_take_profit==0.0) tp=0.0; - else tp=NormalizeDouble(fmax(order_open_price+_take_profit*_coef_point*_point,_bid+stop_level*_point),_digits); - } - - if(OrderType()==OP_SELL) - { - if(_stop_loss==-1.0) sl=order_stop_loss; - else if(_stop_loss==0.0) sl=0.0; - else sl=NormalizeDouble(fmax(order_open_price+_stop_loss*_coef_point*_point,_ask+stop_level*_point),_digits); - - if(_take_profit==-1.0) tp=order_take_profit; - else if(_take_profit==0.0) tp=0.0; - else tp=NormalizeDouble(fmin(order_open_price-_take_profit*_coef_point*_point,_ask-stop_level*_point),_digits); - } - - if(sl==order_stop_loss && tp==order_take_profit) - return(true); - - //--- - ResetLastError(); - if(OrderModify(ticket,order_open_price,sl,tp,0,clrNONE)) - { - return(true); - } - else - { - //ENUM_ERROR_LEVEL level=PrintError(_LastError); - //if(level==LEVEL_ERROR) - { - Sleep(TRADE_PAUSE_LONG); - return(false); - } - } - - //--- - Sleep(TRADE_PAUSE_SHORT); - attempts--; - }// end while - - } - - Sleep(TRADE_PAUSE_SHORT); - return(true); //position opened - } - else - { - //ENUM_ERROR_LEVEL level=PrintError(_LastError); - //if(level==LEVEL_ERROR) - { - Sleep(TRADE_PAUSE_LONG); - break; - } - }// end else - - Sleep(TRADE_PAUSE_SHORT); - attempts--; - } - } -#endif - - //--- -#ifdef __MQL5__ - - ENUM_ORDER_TYPE order_type=-1; - double price=0.0; - double sl=0.0; - double tp=0.0; - double _ask=SymbolInfoDouble(_symbol,SYMBOL_ASK); - double _bid=SymbolInfoDouble(_symbol,SYMBOL_BID); - int stop_level=(int)SymbolInfoInteger(_symbol,SYMBOL_TRADE_STOPS_LEVEL); - if(_type==TRADE_BUY) { - order_type=ORDER_TYPE_BUY; - price=_ask; - - if(_stop_loss>0) - sl=NormalizeDouble(fmin(price-_stop_loss*_coef_point*_point,_bid-stop_level*_point),_digits); - - if(_take_profit>0) - tp=NormalizeDouble(fmax(price+_take_profit*_coef_point*_point,_bid+stop_level*_point),_digits); - - } - if(_type==TRADE_SELL) { - order_type=ORDER_TYPE_SELL; - price=_bid; - - if(_stop_loss>0) - sl=NormalizeDouble(fmax(price+_stop_loss*_coef_point*_point,_ask+stop_level*_point),_digits); - - if(_take_profit>0) - tp=NormalizeDouble(fmin(price-_take_profit*_coef_point*_point,_ask-stop_level*_point),_digits); - } - - double volume=NormalizeVolume(_volume); - - #ifdef CTrade - // @todo: To test. - CTrade trade; - if (!trade) { - return (false); - } - trade.SetDeviationInPoints(SymbolInfoInteger(_symbol, SYMBOL_SPREAD)); - trade.SetExpertMagicNumber(_magic); - - //--- - trade.SetTypeFilling(GetTypeFilling(_symbol)); - bool result=trade.PositionOpen(_symbol,order_type,volume,price,sl,tp,_comment); - if (!result) { - m_last_error=(int)trade.ResultRetcode(); - } - #else - return (false); - #endif -#endif - - return (true); - } - - //+------------------------------------------------------------------+ - int GetLastError() - { - return(m_last_error); - } -}; diff --git a/EA.mqh b/EA.mqh index dd302787c..b914b1bf7 100644 --- a/EA.mqh +++ b/EA.mqh @@ -758,7 +758,7 @@ class EA : public Taskable { bool StrategyAdd(ENUM_TIMEFRAMES _tf, long _magic_no = 0, int _type = 0) { bool _result = true; _magic_no = _magic_no > 0 ? _magic_no : rand(); - Ref _strat = ((SClass *)NULL).Init(_tf); + Ref _strat = ((SClass *)NULL).Init(_tf, THIS_PTR); _strat.Ptr().Set(STRAT_PARAM_ID, _magic_no); _strat.Ptr().Set(TRADE_PARAM_MAGIC_NO, _magic_no); _strat.Ptr().Set(STRAT_PARAM_LOG_LEVEL, diff --git a/SVG.mqh b/SVG.mqh deleted file mode 100644 index d209ec40f..000000000 --- a/SVG.mqh +++ /dev/null @@ -1,66 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#property copyright "" -#property link "" - -class SVG { - datetime x,y,t; - datetime tdiff; - int filehandle; - -public: - - SVG(string filename) - { - string svg="0) { - x=TimeHour(Time[i])*TimeMinute(Time[i]); - tdiff=(Time[0]-Time[i]); - y=(Time[Bars-1]-Time[i])/-100; - FileWrite(filehandle,t++,High[i]); - - } - - } - else Print("File open failed, error ",GetLastError()); - - } - - -}; diff --git a/Stats.mqh b/Stats.mqh deleted file mode 100644 index d0315ca48..000000000 --- a/Stats.mqh +++ /dev/null @@ -1,96 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -// Includes. -#include "Dict.mqh" - -// Enums. -enum ENUM_STATS_TYPE { STATS_CALC_AVG, STATS_CALC_MIN, STATS_CALC_MED, STATS_CALC_MAX }; - -/** - * Class to calculate minimum, average and maximum values. - */ -template -class Stats { - public: - double data[]; - double avg, min, max; - datetime period_start, period_end; - int max_buff; - - /** - * Implements class constructor. - * - * @param long _periods Flags to determine periods to calculate. - */ - Stats(int _max_buff = 1000) : max_buff(_max_buff) {} - - /** - * Implements class destructor. - */ - ~Stats() {} - - /** - * Parse the new value. - */ - void Add(double _value, datetime _dt = 0) { - period_start = fmin(_dt, period_start); - period_end = fmax(_dt, period_end); - _dt = _dt > 0 ? _dt : TimeCurrent(); - // avg = (_value + last) / 2; - } - - /** - * Get statistics per period. - * - * @param ENUM_STATS_TYPE _type Specify type of calculation. - */ - double GetStats(ENUM_STATS_TYPE _type = STATS_CALC_AVG) { - // @todo - return WRONG_VALUE; - } - - /** - * Gets total count. - * - * @return - * Returns total count of all values. - */ - int GetCount() { - // return data.GetCount(); - return WRONG_VALUE; - } - - /** - * Get average count per period. - * - * @param ENUM_TIMEFRAMES _period Specify type of calculation. - * - * @return - * Returns average count per period. When PERIOD_CURRENT, returns total number. - */ - int GetCount(ENUM_TIMEFRAMES _period) { - double _psecs = PeriodSeconds(_period); - // ...data - return WRONG_VALUE; - } -}; diff --git a/Strategy.mqh b/Strategy.mqh index ececc162d..ef9c0d563 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -449,7 +449,7 @@ class Strategy : public Taskable { */ void SetId(long _id) { sparams.id = _id; - ((Object *)GetPointer(this)).SetId(_id); + ((Object *)THIS_PTR).SetId(_id); } /** diff --git a/Ticker.mqh b/Ticker.mqh deleted file mode 100644 index 51a36c26a..000000000 --- a/Ticker.mqh +++ /dev/null @@ -1,202 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -// Prevents processing this includes file for the second time. -#ifndef TICKER_MQH -#define TICKER_MQH - -// Forward declaration. -class Chart; - -// Includes. -#include "Chart.mqh" -#include "Log.mqh" -#include "SymbolInfo.mqh" -//#include "Market.mqh" - -// Define an assert macros. -#define PROCESS_METHOD(method, no) ((method & (1 << no)) == 1 << no) - -/** - * Class to provide methods handling ticks. - */ -class Ticker { - // Structs. - struct TTick { - datetime dt; - double bid, ask; - double vol; - }; - - protected: - unsigned long total_added, total_ignored, total_processed, total_saved; - // Struct variables. - MqlTick data[]; - // Class variables. - SymbolInfo *symbol; - Ref logger; - - public: - // Public variables. - int index; - - /** - * Class constructor. - */ - Ticker(SymbolInfo *_symbol = NULL, Log *_logger = NULL, int size = 1000) - : symbol(Object::IsValid(_symbol) ? _symbol : new SymbolInfo), - logger(Object::IsValid(_logger) ? _logger : new Log), - total_added(0), - total_ignored(0), - total_processed(0), - total_saved(0), - index(-1) { - ArrayResize(data, size, size); - } - - /** - * Class deconstructor. - */ - ~Ticker() { Object::Delete(symbol); } - - Log *Logger() { return logger.Ptr(); } - - /* Getters */ - - /** - * Get number of added ticks. - */ - unsigned long GetTotalAdded() { return total_added; } - - /** - * Get number of ignored ticks. - */ - unsigned long GetTotalIgnored() { return total_ignored; } - - /** - * Get number of parsed ticks. - */ - unsigned long GetTotalProcessed() { return total_processed; } - - /** - * Get number of saved ticks. - */ - unsigned long GetTotalSaved() { return total_saved; } - - /* Other methods */ - - /** - * Processes tick. - * - * @param - * _method Ignore method (0-15). - * _tf Timeframe to use. - * @return - * Returns true when tick should be parsed, otherwise ignored. - */ - bool Process(Chart *_chart, unsigned int _method) { - total_processed++; - if (_method == 0 || total_processed == 1) { - return true; - } - double _last_bid = symbol.GetLastBid(); - double _bid = symbol.GetBid(); - bool _res = _last_bid != _bid; - if (PROCESS_METHOD(_method, 0)) _res &= (_chart.GetOpen() == _bid); // 1 - if (PROCESS_METHOD(_method, 1)) _res &= (_chart.GetBarTime() == TimeCurrent()); // 2 - if (PROCESS_METHOD(_method, 2)) _res &= (_bid >= _chart.GetHigh()) || (_bid <= _chart.GetLow()); // 4 - if (!_res) { - total_ignored++; - } - return _res; - } - - /** - * Append a new tick to an array. - */ - bool Add(const MqlTick &_tick) { - if (index++ >= ArraySize(data) - 1) { - if (ArrayResize(data, index + 100, 1000) < 0) { - Logger().Error(StringFormat("Cannot resize array (index: %d)!", index), __FUNCTION__); - return false; - } - } - data[index] = _tick; - total_added++; - return true; - } - bool Add() { - MqlTick _tick = this PTR_DEREF symbol.GetTick(); - return Add(_tick); - } - - /** - * Empties the tick array. - */ - void Reset() { - total_added = 0; - index = 0; - } - - /** - * Save ticks into CSV file. - */ - bool SaveToCSV(string filename = NULL, bool verbose = true) { - ResetLastError(); - datetime _dt = index > 0 ? data[index].time : TimeCurrent(); - filename = filename != NULL - ? filename - : StringFormat("%s_%s_ticks.csv", symbol.GetSymbol(), DateTimeStatic::TimeToStr(_dt, TIME_DATE)); - int _handle = FileOpen(filename, FILE_WRITE | FILE_CSV, ","); - if (_handle != INVALID_HANDLE) { - total_saved = 0; - FileWrite(_handle, "Datatime", "Bid", "Ask", "Volume"); - for (int i = 0; i < index; i++) { - if (data[i].time > 0) { - FileWrite(_handle, DateTimeStatic::TimeToStr(data[i].time, TIME_DATE | TIME_MINUTES | TIME_SECONDS), - data[i].bid, data[i].ask, data[i].volume); - total_saved++; - } - } - FileClose(_handle); - if (verbose) { - Logger().Info(StringFormat("%s: %d ticks written to '%s' file.", __FUNCTION__, total_saved, filename)); - } - return true; - } else { - if (verbose) { - Logger().Error(StringFormat("%s: Cannot open file for writting, error: %s", __FUNCTION__, GetLastError())); - } - return false; - } - } - - /** - * Returns textual representation of the Market class. - */ - string ToString() { - return StringFormat("Processed: %d; Ignored: %d; Added: %d; Saved: %d;", GetTotalProcessed(), GetTotalIgnored(), - GetTotalAdded(), GetTotalSaved()); - } -}; - -#endif // TICKER_MQH diff --git a/tests/CompileTest.mq5 b/tests/CompileTest.mq5 index b08488613..5b895bf0e 100644 --- a/tests/CompileTest.mq5 +++ b/tests/CompileTest.mq5 @@ -41,7 +41,6 @@ #include "../Account/AccountMt.h" #include "../Array.mqh" #include "../Task/TaskAction.h" -//#include "../BasicTrade.mqh" // @removeme #include "../Buffer.mqh" #include "../BufferFXT.mqh" #include "../BufferStruct.mqh" @@ -91,7 +90,6 @@ #include "../Report.mqh" #include "../Storage/Objects.h" #include "../Storage/ObjectsCache.h" -// #include "../SVG.mqh" // @removeme #include "../Serializer.mqh" #include "../SerializerBinary.mqh" #include "../SerializerConversions.h" @@ -107,7 +105,6 @@ #include "../Session.mqh" #include "../SetFile.mqh" #include "../Socket.mqh" -#include "../Stats.mqh" #include "../Std.h" #include "../Storage/Singleton.h" #include "../Strategy.mqh" @@ -126,7 +123,6 @@ // #include "../Tester.mqh" // @removeme #include "../Storage/ValueStorage.h" #include "../Tests.mqh" -#include "../Ticker.mqh" #include "../Timer.mqh" #include "../Trade.mqh" #include "../Util.h" diff --git a/tests/MathTest.mq5 b/tests/MathTest.mq5 index 72027cb4f..7f985b4ee 100644 --- a/tests/MathTest.mq5 +++ b/tests/MathTest.mq5 @@ -21,7 +21,7 @@ /** * @file - * Test functionality of Ticker class. + * Test functionality of Math class. */ // Includes. diff --git a/tests/StatsTest.mq4 b/tests/StatsTest.mq4 deleted file mode 100644 index 233cbd73a..000000000 --- a/tests/StatsTest.mq4 +++ /dev/null @@ -1,28 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Stats class. - */ - -// Includes -#include "StatsTest.mq5" diff --git a/tests/StatsTest.mq5 b/tests/StatsTest.mq5 deleted file mode 100644 index 94080673b..000000000 --- a/tests/StatsTest.mq5 +++ /dev/null @@ -1,74 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Stats class. - */ - -// Includes -#include "../Stats.mqh" - -// Variables. -Stats *stats_price; -Stats *stats_spread; - -/** - * Implements OnInit(). - */ -int OnInit() { - stats_price = new Stats(); - stats_spread = new Stats(); - return (INIT_SUCCEEDED); -} - -/** - * Implements OnTick(). - */ -void OnTick() { - stats_price.Add(SymbolInfoDouble(_Symbol, SYMBOL_ASK)); - stats_spread.Add((int) SymbolInfoInteger(_Symbol, SYMBOL_SPREAD)); -} - -/** - * Implements OnDeinit(). - */ -void OnDeinit(const int reason) { - PrintFormat("Total ticks : %d", stats_price.GetCount()); - PrintFormat("Ticks per min : %d", stats_price.GetCount(PERIOD_M1)); - PrintFormat("Ticks per hour : %d", stats_price.GetCount(PERIOD_H1)); - PrintFormat("Price (minimum) : %g", stats_price.GetStats(STATS_CALC_MIN)); - PrintFormat("Price (average) : %g", stats_price.GetStats(STATS_CALC_AVG)); - PrintFormat("Price (median) : %g", stats_price.GetStats(STATS_CALC_MED)); - PrintFormat("Price (maximum) : %g", stats_price.GetStats(STATS_CALC_MAX)); - PrintFormat("Spread (average) : %g", stats_spread.GetStats(STATS_CALC_AVG)); - //PrintFormat("Price (avg/hour) : %g", stats_price.GetStats(STATS_CALC_AVG, OBJ_PERIOD_H1)); // can be removed - //PrintFormat("Price (avg/???) : %g", stats_price.GetStats(STATS_CALC_MIN, OBJ_PERIOD_H1 | OBJ_PERIOD_H4)); // can be removed - CleanUp(); -} - -/** - * Deletes created objects to free allocated memory. - */ -void CleanUp() { - delete stats_price; - delete stats_spread; -} diff --git a/tests/TickerTest.mq4 b/tests/TickerTest.mq4 deleted file mode 100644 index 10b8413fd..000000000 --- a/tests/TickerTest.mq4 +++ /dev/null @@ -1,28 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Ticker class. - */ - -// Includes. -#include "TickerTest.mq5" diff --git a/tests/TickerTest.mq5 b/tests/TickerTest.mq5 deleted file mode 100644 index db13e2964..000000000 --- a/tests/TickerTest.mq5 +++ /dev/null @@ -1,138 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Ticker class. - */ - -// Includes. -#include "../Test.mqh" -#include "../Ticker.mqh" - -// Global variables. -Chart *chart; -SymbolInfo *symbol; -unsigned long total_ticks; -Ticker *ticker_csv; -Ticker *ticker01; -Ticker *ticker02; -Ticker *ticker03; -Ticker *ticker04; -Ticker *ticker05; -Ticker *ticker06; -Ticker *ticker07; -Ticker *ticker08; - -/** - * Implements initialization function. - */ -int OnInit() { - // Initialize instances. - // SymbolInfo symbol = new SymbolInfo(); - chart = new Chart(); - symbol = (SymbolInfo *)chart; - - // Print market details. - Print("SYMBOL: ", symbol.ToString()); - Print("CHART: ", chart.ToString()); - - // Initialize Ticker instances. - ticker_csv = new Ticker(symbol); - ticker01 = new Ticker(symbol); - ticker02 = new Ticker(symbol); - ticker03 = new Ticker(symbol); - ticker04 = new Ticker(symbol); - ticker05 = new Ticker(symbol); - ticker06 = new Ticker(symbol); - ticker07 = new Ticker(symbol); - ticker08 = new Ticker(symbol); - - // Test adding ticks using local scope class. - Ticker *ticker_test = new Ticker(); - assertTrueOrFail(ticker_test.GetTotalAdded() == 0, "Incorrect number of ticks added"); - assertTrueOrFail(ticker_test.GetTotalIgnored() == 0, "Incorrect number of ticks ignored"); - assertTrueOrFail(ticker_test.GetTotalProcessed() == 0, "Incorrect number of ticks processed"); - assertTrueOrFail(ticker_test.GetTotalSaved() == 0, "Incorrect number of ticks saved"); - ticker_test.Add(); - assertTrueOrFail(ticker_test.GetTotalAdded() == 1, "Incorrect number of ticks added"); - ticker_test.Add(); - assertTrueOrFail(ticker_test.GetTotalAdded() == 2, "Incorrect number of ticks added"); - ticker_test.Reset(); - assertTrueOrFail(ticker_test.GetTotalAdded() == 0, "Incorrect number of ticks after reset"); - ticker_test.Add(); - assertTrueOrFail(ticker_test.GetTotalAdded() == 1, "Incorrect number of ticks added"); - delete ticker_test; - - return (INIT_SUCCEEDED); -} - -/** - * Implements OnTick(). - */ -void OnTick() { - total_ticks++; - - // Process the ticks using different methods. - ticker01.Process(chart, 1); - ticker02.Process(chart, 2); - ticker03.Process(chart, 3); - ticker04.Process(chart, 4); - ticker05.Process(chart, 5); - ticker06.Process(chart, 6); - ticker07.Process(chart, 7); - ticker08.Process(chart, 8); - ticker_csv.Add(); -} - -/** - * Implements deinitialization function. - */ -void OnDeinit(const int reason) { - // Save ticks into CSV. - ticker_csv.SaveToCSV(StringFormat("ticks_%s.csv", _Symbol)); - // @fixme - // assertTrueOrExit(ticker_csv.GetTotalSaved() == ticker_csv.GetTotalAdded(), "Incorrect number of ticks added"); - - // Print final details. - Print("TICKER01: ", ticker01.ToString()); - Print("TICKER02: ", ticker02.ToString()); - Print("TICKER03: ", ticker03.ToString()); - Print("TICKER04: ", ticker04.ToString()); - Print("TICKER05: ", ticker05.ToString()); - Print("TICKER06: ", ticker06.ToString()); - Print("TICKER07: ", ticker07.ToString()); - Print("TICKER08: ", ticker08.ToString()); - Print("TICKER CSV: ", ticker_csv.ToString()); - - // Deinitialize objects. - delete chart; - delete symbol; - delete ticker_csv; - delete ticker01; - delete ticker02; - delete ticker03; - delete ticker04; - delete ticker05; - delete ticker06; - delete ticker07; - delete ticker08; -} diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 14a5d00e6..0249c73ec 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -198,15 +198,6 @@ services: BT_DAYS: 1-4 BT_MONTHS: 1 OPT_VERBOSE: 1 - StatsTest: - command: run_backtest -e StatsTest.mq4 - image: ea31337/ea-tester:EURUSD-2019-DS - volumes: - - ../:/opt/src - environment: - BT_DAYS: 1-4 - BT_MONTHS: 1 - OPT_VERBOSE: 1 StrategyTest: command: run_backtest -e StrategyTest.mq4 image: ea31337/ea-tester:EURUSD-2019-DS @@ -248,15 +239,6 @@ services: image: ea31337/ea-tester:latest volumes: - ../:/opt/src - TickerTest: - command: run_backtest -e TickerTest.mq4 - image: ea31337/ea-tester:EURUSD-2019-DS - volumes: - - ../:/opt/src - environment: - BT_DAYS: 1-4 - BT_MONTHS: 1 - OPT_VERBOSE: 1 TimerTest: command: run_backtest -s TimerTest.mq4 image: ea31337/ea-tester:latest