Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_sirius-master/strategy/trade_signal.py
5932 views
1
from strategy.calculate_utils import calculate_ma
2
from utils.settings import settings
3
4
fast_ma_step = int(settings()['TRADE']['fast_ma_step'])
5
slow_ma_step = int(settings()['TRADE']['slow_ma_step'])
6
trend_ma_step = int(settings()['TRADE']['trend_ma_step'])
7
8
9
def break_from_down(candles, name_first, name_second):
10
return candles[0][name_first] < candles[0][name_second] and \
11
candles[-1][name_first] > candles[-1][name_second]
12
13
14
def break_from_up(candles, name_first, name_second):
15
return candles[0][name_first] > candles[0][name_second] and \
16
candles[-1][name_first] < candles[-1][name_second]
17
18
19
def get_trade_signal(candles):
20
min_time_frame_minutes = 30
21
signal = ''
22
23
if len(candles) < min_time_frame_minutes:
24
return signal
25
26
calculate_ma(candles, fast_ma_step, 'price', 'fast_ma')
27
calculate_ma(candles, slow_ma_step, 'price', 'slow_ma')
28
calculate_ma(candles, trend_ma_step, 'price', 'trend_ma')
29
30
if break_from_down(candles, 'fast_ma', 'slow_ma') and break_from_down(candles, 'fast_ma', 'trend_ma'):
31
signal = 'buy'
32
if break_from_up(candles, 'fast_ma', 'slow_ma') and break_from_up(candles, 'fast_ma', 'trend_ma'):
33
signal = 'sell'
34
35
return signal
36
37
38
39