Skip to content

Commit

Permalink
WIP. Fixing C++ errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Nov 10, 2022
1 parent 5f225c4 commit 0a6aade
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 341 deletions.
620 changes: 287 additions & 333 deletions BasicTrade.mqh

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#include "Platform.h"
#endif

// Forward declarations.
class Serializer;

// Includes.
#include "Chart.enum.h"
#include "Serializer/Serializer.h"
#include "Serializer/SerializerNode.enum.h"
#include "Terminal.define.h"
#include "Serializer/Serializer.h"

/* Defines struct for chart timeframe. */
struct ChartTf {
Expand Down Expand Up @@ -256,7 +257,7 @@ struct ChartTf {
* _tf ENUM_TIMEFRAMES Specify timeframe enum.
*/
static ENUM_TIMEFRAMES_INDEX TfToIndex(ENUM_TIMEFRAMES _tf) {
_tf = (_tf == 0 || _tf == PERIOD_CURRENT) ? (ENUM_TIMEFRAMES)_Period : _tf;
_tf = (_tf == 0 || _tf == PERIOD_CURRENT) ? (ENUM_TIMEFRAMES)Platform::Period() : _tf;
for (int i = 0; i < ArraySize(TIMEFRAMES_LIST); i++) {
if (TIMEFRAMES_LIST[i] == _tf) {
return (ENUM_TIMEFRAMES_INDEX)i;
Expand Down
2 changes: 1 addition & 1 deletion Flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
template <typename T>
struct Flags {
// Bit-based value.
unsigned T value;
T value;

/**
* Constructor.
Expand Down
1 change: 1 addition & 0 deletions Indicator/Indicator.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ enum ENUM_INDICATOR_TYPE {
INDI_TEMA, // Triple Exponential Moving Average
INDI_TF, // Timeframe
INDI_TICK, // Tick
INDI_TICK_RANDOM, // Random Tick.
INDI_TMA_TRUE, // Triangular Moving Average True
INDI_TRIX, // Triple Exponential Moving Averages Oscillator
INDI_ULTIMATE_OSCILLATOR, // Ultimate Oscillator
Expand Down
103 changes: 103 additions & 0 deletions Indicators/Tick/Indi_TickRandom.mqh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//+------------------------------------------------------------------+
//| 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/>.
*
*/

/**
* @file
* Random (mainly for C++ testing) tick-based indicator.
*/

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

// Includes.
#include "../../Chart.struct.static.h"
#include "../../Indicator/IndicatorTick.h"
#include "../../Indicator/IndicatorTick.provider.h"

// Structs.
// Params for MT patform's tick-based indicator.
struct Indi_TickRandomParams : IndicatorParams {
Indi_TickRandomParams() : IndicatorParams(INDI_TICK_RANDOM) {}
};

// MT platform's tick-based indicator.
class Indi_TickRandom : public IndicatorTick<Indi_TickRandomParams, double, ItemsHistoryTickProvider<double>> {
public:
Indi_TickRandom(Indi_TickRandomParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN,
IndicatorData *_indi_src = NULL, int _indi_src_mode = 0)
: IndicatorTick(_p.symbol, _p,
IndicatorDataParams::GetInstance(2, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode),
_indi_src) {
Init();
}
Indi_TickRandom(string _symbol, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL,
int _indi_src_mode = 0, string _name = "")
: IndicatorTick(_symbol, Indi_TickRandomParams(),
IndicatorDataParams(2, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), _indi_src) {
Init();
}

/**
* Initializes the class.
*/
void Init() {}

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

/**
* Returns possible data source types. It is a bit mask of ENUM_INDI_SUITABLE_DS_TYPE.
*/
unsigned int GetSuitableDataSourceTypes() override { return INDI_SUITABLE_DS_TYPE_EXPECT_NONE; }

/**
* Returns possible data source modes. It is a bit mask of ENUM_IDATA_SOURCE_TYPE.
*/
unsigned int GetPossibleDataModes() override { return IDATA_BUILTIN; }

/**
* Returns the indicator's struct entry for the given shift.
*/
IndicatorDataEntry GetEntry(int _index = 0) override {
IndicatorDataEntry _default;
return _default;
}

/**
* Fetches historic ticks for a given time range.
*/
virtual bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB<double>, _out_ticks)) {
// No history.
return false;
}

void OnTick(int _global_tick_index) override {
float _ask = 1.0f + (1.0f / 32767 * MathRand());
float _bid = 1.0f + (1.0f / 32767 * MathRand());
TickAB<double> _tick(, _bid);
IndicatorDataEntry _entry(TickToEntry(_time, _tick));
EmitEntry(_entry);
// Appending tick into the history.
AppendEntry(_entry);
}
};
17 changes: 15 additions & 2 deletions Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@

#include "Flags.h"
#include "Indicator/IndicatorData.h"
#include "Indicator/tests/classes/IndicatorTfDummy.h"
#include "Std.h"

#ifdef __MQLBUILD__
#include "Indicator/tests/classes/IndicatorTfDummy.h"
#include "Indicators/Tick/Indi_TickMt.mqh"
#define PLATFORM_DEFAULT_INDICATOR_TICK Indi_TickMt
#else
#error "Platform not supported!
#include "Indicators/Tick/Indi_TickRandom.mqh"
#define PLATFORM_DEFAULT_INDICATOR_TICK Indi_TickRandom
#endif
#include "SymbolInfo.struct.static.h"

Expand Down Expand Up @@ -311,6 +312,18 @@ class Platform {
}
return _result;
}

/**
* Returns currently selected period for platform.
*/
static ENUM_TIMEFRAMES Period() {
#ifdef __MQL__
return Period();
#else
// @fixit Should fetch selected period from somewhere.
return PERIOD_M15;
#endif
}
};

bool Platform::initialized = false;
Expand Down
3 changes: 2 additions & 1 deletion Storage/ValueStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ void ArrayInitialize(ValueStorage<C> &_storage, C _value) {
* ValueStorage-compatible wrapper for ArrayCopy.
*/
template <typename C, typename D>
int ArrayCopy(D &_target[], ValueStorage<C> &_source, int _dst_start = 0, int _src_start = 0, int count = WHOLE_ARRAY) {
int ArrayCopy(ARRAY_REF(D, _target), ValueStorage<C> &_source, int _dst_start = 0, int _src_start = 0,
int count = WHOLE_ARRAY) {
if (count == WHOLE_ARRAY) {
count = ArraySize(_source);
}
Expand Down
2 changes: 1 addition & 1 deletion Strategy.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ struct StgParams {
struct Stg_Params {
string symbol;
ENUM_TIMEFRAMES tf;
Stg_Params() : symbol(_Symbol), tf((ENUM_TIMEFRAMES)_Period) {}
Stg_Params() : symbol(_Symbol), tf((ENUM_TIMEFRAMES)Period()) {}
};

/* Structure for strategy's process results. */
Expand Down
3 changes: 2 additions & 1 deletion SymbolInfo.struct.static.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#endif

#include "MQL5.mqh"
#include "Math.h"
#include "Order.enum.h"
#include "Std.h"
#include "Tick/Tick.struct.h"
Expand Down Expand Up @@ -128,7 +129,7 @@ struct SymbolInfoStatic {
*/
static double GetPipValue(string _symbol) {
unsigned int _pdigits = GetPipDigits(_symbol);
return 1.0 / MathPow(10, _pdigits);
return 1.0 / MathPow(10, (int)_pdigits);
}

/**
Expand Down

0 comments on commit 0a6aade

Please sign in to comment.