Skip to content

Commit 7915de1

Browse files
committed
Removing OHLC_RSI for the moment, and focusing on a Random Trading Strategy
1 parent 012108a commit 7915de1

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

scripts/arguments/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ json='{
55
"STRATEGY": {
66
"UUID": "",
77
"TRADING_VARIABLES": {
8-
"STRATEGY": "OHLC_RSI",
8+
"STRATEGY": "RandomStrategy",
99
"STOP_DISTANCE_IN_PIPS": 1,
1010
"LIMIT_DISTANCE_IN_PIPS": 1,
1111
"TRADING_SIZE": 1

scripts/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ fi
2323
json='{
2424
"RUN_ID": "UNIQUE_IDENTIFIER",
2525
"SYMBOLS": "EURUSD",
26-
"LAST_MONTHS": 1,
26+
"LAST_MONTHS": 2,
2727
"STRATEGY": {
2828
"UUID": "",
2929
"TRADING_VARIABLES": {
30-
"STRATEGY": "OHLC_RSI",
30+
"STRATEGY": "RandomStrategy",
3131
"STOP_DISTANCE_IN_PIPS": "1.5",
3232
"LIMIT_DISTANCE_IN_PIPS": "1.5",
33-
"TRADING_SIZE": "0.01"
33+
"TRADING_SIZE": "1"
3434
},
3535
"OHLC_VARIABLES": [
3636
{

source/operations.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <vector>
1111
#include <memory>
1212
#include <optional>
13+
#include <stdexcept>
1314
#include <string>
1415
#include <utility>
1516
#include <iomanip>
@@ -18,6 +19,7 @@
1819
#include <boost/decimal.hpp>
1920
#include "tradeManager.hpp"
2021
#include "models/symbolScale.hpp"
22+
#include "strategies/strategy.hpp"
2123
#include "strategies/randomStrategy.hpp"
2224

2325
namespace {
@@ -76,13 +78,24 @@ void reviewStopAndLimit(TradeManager& tradeManager, const PriceData& tick) {
7678
}
7779
}
7880

81+
// Adding a new strategy means adding one branch here; nothing else in
82+
// Operations needs to know about the concrete type.
83+
std::unique_ptr<IStrategy>
84+
selectStrategy(const trading_definitions::Configuration& config) {
85+
const auto& name = config.STRATEGY.TRADING_VARIABLES.STRATEGY;
86+
if (name == "RandomStrategy") {
87+
return std::make_unique<RandomStrategy>(config.STRATEGY);
88+
}
89+
throw std::runtime_error("Unknown strategy: '" + name + "'");
90+
}
91+
7992
} // namespace
8093

8194
void Operations::run(const std::vector<PriceData>& ticks,
8295
const trading_definitions::Configuration& config) {
8396

8497
auto tradeManager = std::make_unique<TradeManager>();
85-
RandomStrategy strategy(config.STRATEGY);
98+
auto strategy = selectStrategy(config);
8699

87100
const auto& tradingVars = config.STRATEGY.TRADING_VARIABLES;
88101

@@ -99,7 +112,7 @@ void Operations::run(const std::vector<PriceData>& ticks,
99112
// only open a trade if there is zero
100113
if (openTrades == 0) {
101114
// optional is false
102-
if (auto signal = strategy.decide(tick)) {
115+
if (auto signal = strategy->decide(tick)) {
103116
tradeManager->openTrade(tick,
104117
tradingVars.TRADING_SIZE,
105118
*signal,
@@ -112,7 +125,7 @@ void Operations::run(const std::vector<PriceData>& ticks,
112125
// (e.g. trailing stops, partial closes). The default
113126
// RandomStrategy implementation is a no-op now that exits are
114127
// handled by reviewStopAndLimit above.
115-
strategy.during(tickIndex, tick, *tradeManager);
128+
strategy->during(tickIndex, tick, *tradeManager);
116129

117130
++tickIndex;
118131
}

tests/jsonParser.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ - (void)testValidJsonParsing {
3030
"STRATEGY": {
3131
"UUID": "",
3232
"TRADING_VARIABLES": {
33-
"STRATEGY": "OHLC_RSI",
33+
"STRATEGY": "RandomStrategy",
3434
"STOP_DISTANCE_IN_PIPS": "1",
3535
"LIMIT_DISTANCE_IN_PIPS": "1",
3636
"TRADING_SIZE": "1"

0 commit comments

Comments
 (0)