This commit is contained in:
Ichinga Samuel
2024-10-28 17:12:52 +01:00
parent 780d664741
commit 5f6d3666ee
4 changed files with 34 additions and 7 deletions
@@ -613,12 +613,16 @@ class BackTestEngine:
async def get_rates_from_pos(self, *, symbol: str, timeframe: TimeFrame, start_pos: int, count: int) -> np.ndarray:
if self.use_terminal:
# Todo: Optimize this!!!
now = datetime.now(tz=UTC).timestamp()
b_now = self.cursor.time
diff = ceil((now - b_now) / timeframe.seconds)
start_pos = int(diff + start_pos)
# print('hehk', start_pos, count)
res = await self.mt5.copy_rates_from_pos(symbol, timeframe, start_pos, count)
# now = datetime.now(tz=UTC).timestamp()
# b_now = self.cursor.time
# diff = ceil((now - b_now) / timeframe.seconds)
# start_pos = int(diff + start_pos)
# # print('hehk', start_pos, count)
# res = await self.mt5.copy_rates_from_pos(symbol, timeframe, start_pos, count)
current_time = self.cursor.time if start_pos == 0 else self.cursor.time - start_pos * timeframe.seconds
start = current_time - count * timeframe.seconds
start = datetime.fromtimestamp(start, tz=UTC)
rates = self.mt5.copy_rates_from(symbol, timeframe, start, count)
return res
rates = self.rates[symbol][timeframe]
-1
View File
@@ -52,7 +52,6 @@ class EventManager:
await self.backtest_engine.tracker()
self.backtest_engine.next()
self.condition.notify_all()
# print(f"Time: {self.backtest_engine.cursor.time}")
if self.backtest_engine.cursor.time % 3600 == 0:
print(datetime.strftime(self.backtest_engine.cursor.time, "%Y-%m-%d %H:%M:%S"))
if self.backtest_engine.stop_testing:
+24
View File
@@ -0,0 +1,24 @@
import logging
from aiomql.lib.bot import Bot
from aiomql.core import Config
from aiomql.contrib.strategies import FingerTrap, Chaos
from aiomql.contrib.symbols import ForexSymbol
async def test_bot():
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
syms = ['Volatility 75 Index', 'Volatility 100 Index', 'Volatility 50 Index']
symbols = [ForexSymbol(name=sym) for sym in syms]
stgs = [Chaos(symbol=symbol, name='test_chaos') for symbol in symbols]
bot = Bot()
assert bot.config.shutdown is False
bot.executor.timeout = 30
bot.add_strategies(strategies=stgs)
await bot.initialize()
assert bot.executor.no_of_running_strategies == 3
assert len(bot.executor.coroutines) == 1
assert len(bot.executor.coroutine_threads) == 1
assert len(bot.executor.tasks) == 5
assert bot.config.shutdown is True