Skip to content

Commit

Permalink
WIP. Testing RSI over IndicatorTfDummy over Indi_TickProvider. RSI re…
Browse files Browse the repository at this point in the history
…turns values. It's good!
  • Loading branch information
nseam committed Mar 2, 2023
1 parent 478b640 commit 30d6f7f
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 153 deletions.
15 changes: 3 additions & 12 deletions DateTime.extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class datetime {

public:
datetime() { dt = 0; }
datetime(const long& _time) { dt = _time; }
datetime(const int64& _time) { dt = _time; }
// datetime(const int& _time);
bool operator==(const int _time) const = delete;
bool operator==(const datetime& _time) const { return dt == _time; }
bool operator<(const int _time) const = delete;
bool operator>(const int _time) const = delete;
bool operator<(const datetime& _time) const { return dt < _time; }
bool operator>(const datetime& _time) const { return dt > _time; }
operator long() const { return dt; }
operator int64() const { return dt; }
};

extern int CopyTime(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count,
Expand All @@ -71,16 +71,7 @@ extern datetime TimeGMT(MqlDateTime& dt_struct);
extern datetime TimeTradeServer();
extern datetime TimeTradeServer(MqlDateTime& dt_struct);
extern datetime StringToTime(const string& value);
string TimeToString(datetime value, int mode = TIME_DATE | TIME_MINUTES) {
/*
auto now = std::chrono::time_point();
auto in_time_t = std::chrono::system_clock::to_time_t(now);
*/
std::stringstream ss;
ss << __FUNCTION__ << " is not yet implemented!";
// ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %X");
return ss.str();
}
extern string TimeToString(datetime value, int mode = TIME_DATE | TIME_MINUTES);

template <char... T>
datetime operator"" _D();
Expand Down
1 change: 1 addition & 0 deletions DictBase.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class DictBase {
_current_id = 0;
_mode = DictModeUnknown;
_flags = 0;
overflow_listener = nullptr;
}

/**
Expand Down
1 change: 1 addition & 0 deletions Indicator/Indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Indicator : public IndicatorData {
: IndicatorData(IndicatorDataParams::GetInstance()) {
iparams.SetIndicatorType(_itype);
iparams.SetShift(_shift);
SetName(_name);
Init();
}

Expand Down
2 changes: 1 addition & 1 deletion Indicator/IndicatorCandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class IndicatorCandle : public Indicator<TS> {
/**
* Class constructor.
*/
IndicatorCandle(const TS& _icparams, const IndicatorDataParams& _idparams, IndicatorBase* _indi_src = NULL,
IndicatorCandle(const TS& _icparams, const IndicatorDataParams& _idparams, IndicatorData* _indi_src = NULL,
int _indi_mode = 0)
: Indicator<TS>(_icparams, _idparams, _indi_src, _indi_mode), history(INDI_CANDLE_HISTORY_SIZE) {
Init();
Expand Down
24 changes: 5 additions & 19 deletions Indicator/IndicatorTf.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,20 @@ class IndicatorTf : public IndicatorCandle<TFP, double, ItemsHistoryTfCandleProv

/**
* Class constructor with timeframe enum.
*
* @todo
*/
/*
IndicatorTf(unsigned int _spc) {
THIS_ATTR iparams.SetSecsPerCandle(_spc);
Init();
}

/**
* Class constructor with timeframe enum.
*/
IndicatorTf(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) {
THIS_ATTR iparams.SetSecsPerCandle(ChartTf::TfToSeconds(_tf));
tf = _tf;
Init();
}

/**
* Class constructor with timeframe index.
*/
IndicatorTf(ENUM_TIMEFRAMES_INDEX _tfi = (ENUM_TIMEFRAMES_INDEX)0) {
THIS_ATTR iparams.SetSecsPerCandle(ChartTf::TfToSeconds(ChartTf::IndexToTf(_tfi)));
tf = ChartTf::IndexToTf(_tfi);
Init();
}
*/

/**
* Class constructor with parameters.
*/
IndicatorTf(TFP& _icparams, const IndicatorDataParams& _idparams) { Init(); }
IndicatorTf(TFP& _icparams, const IndicatorDataParams& _idparams) : IndicatorCandle(_icparams, _idparams) { Init(); }

/**
* Gets indicator's time-frame.
Expand Down
22 changes: 17 additions & 5 deletions Indicator/IndicatorTf.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@
/* Structure for IndicatorTf class parameters. */
struct IndicatorTfParams : IndicatorParams {
ChartTf tf;
unsigned int spc; // Seconds per candle.

/*
@todo
unsigned int spc; // Seconds per candle.
*/

// Struct constructor.
IndicatorTfParams(string _name = "", unsigned int _spc = 60) : IndicatorParams(_name), spc(_spc) {}
IndicatorTfParams(string _name, ENUM_TIMEFRAMES _tf) : IndicatorParams(_name), tf(_tf) {}

// Getters.
unsigned int GetSecsPerCandle() { return spc; }
// Setters.
void SetSecsPerCandle(unsigned int _spc) { spc = _spc; }
unsigned int GetSecsPerCandle() { return tf.GetInSeconds(); }

/*
@todo
// Setters.
void SetSecsPerCandle(unsigned int _spc) { spc = _spc; }
*/

// Copy constructor.
IndicatorTfParams(const IndicatorTfParams &_params, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) {
THIS_REF = _params;
Expand Down
17 changes: 12 additions & 5 deletions Indicator/tests/classes/IndicatorTfDummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,31 @@
#endif

// Includes.
#include "../../../Platform.define.h"
#include "../../IndicatorTf.h"
#include "../../IndicatorTf.struct.h"

// Params for dummy candle-based indicator.
struct IndicatorTfDummyParams : IndicatorTfParams {
IndicatorTfDummyParams(unsigned int _spc = 60) : IndicatorTfParams("IndicatorTf", _spc) {}
IndicatorTfDummyParams(ENUM_TIMEFRAMES _tf = PLATFORM_WRONG_TIMEFRAME) : IndicatorTfParams("IndicatorTf", _tf) {}
};

/**
* Dummy candle-based indicator.
*/
class IndicatorTfDummy : public IndicatorTf<IndicatorTfDummyParams> {
public:
IndicatorTfDummy(unsigned int _spc) : IndicatorTf(_spc) {}
IndicatorTfDummy(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : IndicatorTf(_tf) {}
IndicatorTfDummy(ENUM_TIMEFRAMES_INDEX _tfi = (ENUM_TIMEFRAMES_INDEX)0) : IndicatorTf(_tfi) {}
/*
@todo
string GetName() override { return "IndicatorTfDummy(" + IntegerToString(iparams.spc) + ")"; }
IndicatorTfDummy(unsigned int _spc) : IndicatorTf(_spc) {}
*/

IndicatorTfDummy(ENUM_TIMEFRAMES _tf) : IndicatorTf(IndicatorTfDummyParams(_tf), IndicatorDataParams()) {}
IndicatorTfDummy(ENUM_TIMEFRAMES_INDEX _tfi)
: IndicatorTf(IndicatorTfDummyParams(ChartTf::IndexToTf(_tfi)), IndicatorDataParams()) {}

string GetName() override { return "IndicatorTfDummy(" + iparams.tf.GetString() + ")"; }

void OnDataSourceEntry(IndicatorDataEntry& entry) override {
// When overriding OnDataSourceEntry() we have to remember to call parent
Expand Down
5 changes: 4 additions & 1 deletion Indicators/Tick/Indi_TickProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class Indi_TickProvider : public IndicatorTick<Indi_TickProviderParams, double,
/**
* Initializes the class.
*/
void Init() { current_index = 0; }
void Init() {
current_index = 0;
SetName("Indi_TickProvider");
}

string GetName() override { return "Indi_TickProvider"; }

Expand Down
30 changes: 30 additions & 0 deletions Platform.define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 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 <http://www.gnu.org/licenses/>.
*
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Defines.
#define PLATFORM_WRONG_SYMBOL ""
#define PLATFORM_WRONG_TIMEFRAME ((ENUM_TIMEFRAMES)INT_MAX)
58 changes: 29 additions & 29 deletions Platform.extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ extern int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos,
extern int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count,
ARRAY_REF(double, close_array));

extern unsigned long PositionGetTicket(int _index);
extern unsigned int64 PositionGetTicket(int _index);

extern long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id);
extern int64 PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id);

extern double PositionGetDouble(ENUM_POSITION_PROPERTY_DOUBLE property_id);

extern string PositionGetString(ENUM_POSITION_PROPERTY_STRING property_id);

extern int HistoryDealsTotal();

extern unsigned long HistoryDealGetTicket(int index);
extern unsigned int64 HistoryDealGetTicket(int index);

extern long HistoryDealGetInteger(unsigned long ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id);
extern int64 HistoryDealGetInteger(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id);

extern double HistoryDealGetDouble(unsigned long ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id);
extern double HistoryDealGetDouble(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id);

extern string HistoryDealGetString(unsigned long ticket_number, ENUM_DEAL_PROPERTY_STRING property_id);
extern string HistoryDealGetString(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_STRING property_id);

extern bool OrderSelect(int index);

Expand All @@ -95,25 +95,25 @@ extern bool OrderSend(const MqlTradeRequest& request, MqlTradeResult& result);

extern bool OrderCheck(const MqlTradeRequest& request, MqlTradeCheckResult& result);

extern unsigned long OrderGetTicket(int index);
extern unsigned int64 OrderGetTicket(int index);

extern unsigned long HistoryOrderGetTicket(int index);
extern unsigned int64 HistoryOrderGetTicket(int index);

extern bool HistorySelectByPosition(long position_id);
extern bool HistorySelectByPosition(int64 position_id);

extern bool HistoryDealSelect(unsigned long ticket);
extern bool HistoryDealSelect(unsigned int64 ticket);

extern long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id);
extern int64 OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id);

extern long HistoryOrderGetInteger(unsigned long ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id);
extern int64 HistoryOrderGetInteger(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id);

extern double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE property_id);

extern double HistoryOrderGetDouble(unsigned long ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id);
extern double HistoryOrderGetDouble(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id);

string OrderGetString(ENUM_ORDER_PROPERTY_STRING property_id);

string HistoryOrderGetString(unsigned long ticket_number, ENUM_ORDER_PROPERTY_STRING property_id);
string HistoryOrderGetString(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_STRING property_id);

extern int PositionsTotal();

Expand All @@ -124,49 +124,49 @@ extern int HistoryOrdersTotal();
extern int OrdersTotal();

extern int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count,
ARRAY_REF(long, arr));
ARRAY_REF(int64, arr));

extern int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count,
ARRAY_REF(long, arr));
ARRAY_REF(int64, arr));

extern int ChartID();

extern bool OrderCalcMargin(ENUM_ORDER_TYPE _action, string _symbol, double _volume, double _price, double& _margin);

extern double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE property_id);

extern long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id);
extern int64 AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id);

extern string AccountInfoInteger(ENUM_ACCOUNT_INFO_STRING property_id);

extern string Symbol();

extern string ObjectName(long _chart_id, int _pos, int _sub_window = -1, int _type = -1);
extern string ObjectName(int64 _chart_id, int _pos, int _sub_window = -1, int _type = -1);

extern int ObjectsTotal(long chart_id, int type = EMPTY, int window = -1);
extern int ObjectsTotal(int64 chart_id, int type = EMPTY, int window = -1);

extern bool PlotIndexSetString(int plot_index, int prop_id, string prop_value);

extern bool PlotIndexSetInteger(int plot_index, int prop_id, int prop_value);

extern bool ObjectSetInteger(long chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, long prop_value);
extern bool ObjectSetInteger(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int64 prop_value);

extern bool ObjectSetInteger(long chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int prop_modifier,
long prop_value);
extern bool ObjectSetInteger(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_INTEGER prop_id, int prop_modifier,
int64 prop_value);

extern bool ObjectSetDouble(long chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, double prop_value);
extern bool ObjectSetDouble(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, double prop_value);

extern bool ObjectSetDouble(long chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, int prop_modifier,
extern bool ObjectSetDouble(int64 chart_id, string name, ENUM_OBJECT_PROPERTY_DOUBLE prop_id, int prop_modifier,
double prop_value);

extern bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1);
extern bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1,
extern bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1);
extern bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1,
datetime _t2, double _p2);

extern bool ObjectMove(long chart_id, string name, int point_index, datetime time, double price);
extern bool ObjectMove(int64 chart_id, string name, int point_index, datetime time, double price);

extern bool ObjectDelete(long chart_id, string name);
extern bool ObjectDelete(int64 chart_id, string name);

extern int ObjectFind(long chart_id, string name);
extern int ObjectFind(int64 chart_id, string name);

#endif
Loading

0 comments on commit 30d6f7f

Please sign in to comment.