-
Notifications
You must be signed in to change notification settings - Fork 17
/
GodStraNew_SMAonly.py
665 lines (609 loc) · 26.1 KB
/
GodStraNew_SMAonly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
# GodStraNew Strategy
# Author: @Mablue (Masoud Azizi)
# github: https://github.com/mablue/
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --spaces buy roi trailing sell --strategy GodStraNew
# --- Do not remove these libs ---
from freqtrade import data
from freqtrade.strategy.hyper import CategoricalParameter, DecimalParameter
from numpy.lib import math
from freqtrade.strategy.interface import IStrategy
from pandas import DataFrame
# --------------------------------
# Add your lib to import here
# TODO: talib is fast but have not more indicators
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
from functools import reduce
import numpy as np
from random import shuffle
# TODO: this gene is removed 'MAVP' cuz or error on periods
all_god_genes = {
'Overlap Studies': {
'BBANDS-0', # Bollinger Bands
'BBANDS-1', # Bollinger Bands
'BBANDS-2', # Bollinger Bands
'DEMA', # Double Exponential Moving Average
'EMA', # Exponential Moving Average
'HT_TRENDLINE', # Hilbert Transform - Instantaneous Trendline
'KAMA', # Kaufman Adaptive Moving Average
'MA', # Moving average
'MAMA-0', # MESA Adaptive Moving Average
'MAMA-1', # MESA Adaptive Moving Average
# TODO: Fix this
# 'MAVP', # Moving average with variable period
'MIDPOINT', # MidPoint over period
'MIDPRICE', # Midpoint Price over period
'SAR', # Parabolic SAR
'SAREXT', # Parabolic SAR - Extended
'SMA', # Simple Moving Average
'T3', # Triple Exponential Moving Average (T3)
'TEMA', # Triple Exponential Moving Average
'TRIMA', # Triangular Moving Average
'WMA', # Weighted Moving Average
},
'Momentum Indicators': {
'ADX', # Average Directional Movement Index
'ADXR', # Average Directional Movement Index Rating
'APO', # Absolute Price Oscillator
'AROON-0', # Aroon
'AROON-1', # Aroon
'AROONOSC', # Aroon Oscillator
'BOP', # Balance Of Power
'CCI', # Commodity Channel Index
'CMO', # Chande Momentum Oscillator
'DX', # Directional Movement Index
'MACD-0', # Moving Average Convergence/Divergence
'MACD-1', # Moving Average Convergence/Divergence
'MACD-2', # Moving Average Convergence/Divergence
'MACDEXT-0', # MACD with controllable MA type
'MACDEXT-1', # MACD with controllable MA type
'MACDEXT-2', # MACD with controllable MA type
'MACDFIX-0', # Moving Average Convergence/Divergence Fix 12/26
'MACDFIX-1', # Moving Average Convergence/Divergence Fix 12/26
'MACDFIX-2', # Moving Average Convergence/Divergence Fix 12/26
'MFI', # Money Flow Index
'MINUS_DI', # Minus Directional Indicator
'MINUS_DM', # Minus Directional Movement
'MOM', # Momentum
'PLUS_DI', # Plus Directional Indicator
'PLUS_DM', # Plus Directional Movement
'PPO', # Percentage Price Oscillator
'ROC', # Rate of change : ((price/prevPrice)-1)*100
'ROCP', # Rate of change Percentage: (price-prevPrice)/prevPrice
'ROCR', # Rate of change ratio: (price/prevPrice)
'ROCR100', # Rate of change ratio 100 scale: (price/prevPrice)*100
'RSI', # Relative Strength Index
'STOCH-0', # Stochastic
'STOCH-1', # Stochastic
'STOCHF-0', # Stochastic Fast
'STOCHF-1', # Stochastic Fast
'STOCHRSI-0', # Stochastic Relative Strength Index
'STOCHRSI-1', # Stochastic Relative Strength Index
'TRIX', # 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA
'ULTOSC', # Ultimate Oscillator
'WILLR', # Williams' %R
},
'Volume Indicators': {
'AD', # Chaikin A/D Line
'ADOSC', # Chaikin A/D Oscillator
'OBV', # On Balance Volume
},
'Volatility Indicators': {
'ATR', # Average True Range
'NATR', # Normalized Average True Range
'TRANGE', # True Range
},
'Price Transform': {
'AVGPRICE', # Average Price
'MEDPRICE', # Median Price
'TYPPRICE', # Typical Price
'WCLPRICE', # Weighted Close Price
},
'Cycle Indicators': {
'HT_DCPERIOD', # Hilbert Transform - Dominant Cycle Period
'HT_DCPHASE', # Hilbert Transform - Dominant Cycle Phase
'HT_PHASOR-0', # Hilbert Transform - Phasor Components
'HT_PHASOR-1', # Hilbert Transform - Phasor Components
'HT_SINE-0', # Hilbert Transform - SineWave
'HT_SINE-1', # Hilbert Transform - SineWave
'HT_TRENDMODE', # Hilbert Transform - Trend vs Cycle Mode
},
'Pattern Recognition': {
'CDL2CROWS', # Two Crows
'CDL3BLACKCROWS', # Three Black Crows
'CDL3INSIDE', # Three Inside Up/Down
'CDL3LINESTRIKE', # Three-Line Strike
'CDL3OUTSIDE', # Three Outside Up/Down
'CDL3STARSINSOUTH', # Three Stars In The South
'CDL3WHITESOLDIERS', # Three Advancing White Soldiers
'CDLABANDONEDBABY', # Abandoned Baby
'CDLADVANCEBLOCK', # Advance Block
'CDLBELTHOLD', # Belt-hold
'CDLBREAKAWAY', # Breakaway
'CDLCLOSINGMARUBOZU', # Closing Marubozu
'CDLCONCEALBABYSWALL', # Concealing Baby Swallow
'CDLCOUNTERATTACK', # Counterattack
'CDLDARKCLOUDCOVER', # Dark Cloud Cover
'CDLDOJI', # Doji
'CDLDOJISTAR', # Doji Star
'CDLDRAGONFLYDOJI', # Dragonfly Doji
'CDLENGULFING', # Engulfing Pattern
'CDLEVENINGDOJISTAR', # Evening Doji Star
'CDLEVENINGSTAR', # Evening Star
'CDLGAPSIDESIDEWHITE', # Up/Down-gap side-by-side white lines
'CDLGRAVESTONEDOJI', # Gravestone Doji
'CDLHAMMER', # Hammer
'CDLHANGINGMAN', # Hanging Man
'CDLHARAMI', # Harami Pattern
'CDLHARAMICROSS', # Harami Cross Pattern
'CDLHIGHWAVE', # High-Wave Candle
'CDLHIKKAKE', # Hikkake Pattern
'CDLHIKKAKEMOD', # Modified Hikkake Pattern
'CDLHOMINGPIGEON', # Homing Pigeon
'CDLIDENTICAL3CROWS', # Identical Three Crows
'CDLINNECK', # In-Neck Pattern
'CDLINVERTEDHAMMER', # Inverted Hammer
'CDLKICKING', # Kicking
'CDLKICKINGBYLENGTH', # Kicking - bull/bear determined by the longer marubozu
'CDLLADDERBOTTOM', # Ladder Bottom
'CDLLONGLEGGEDDOJI', # Long Legged Doji
'CDLLONGLINE', # Long Line Candle
'CDLMARUBOZU', # Marubozu
'CDLMATCHINGLOW', # Matching Low
'CDLMATHOLD', # Mat Hold
'CDLMORNINGDOJISTAR', # Morning Doji Star
'CDLMORNINGSTAR', # Morning Star
'CDLONNECK', # On-Neck Pattern
'CDLPIERCING', # Piercing Pattern
'CDLRICKSHAWMAN', # Rickshaw Man
'CDLRISEFALL3METHODS', # Rising/Falling Three Methods
'CDLSEPARATINGLINES', # Separating Lines
'CDLSHOOTINGSTAR', # Shooting Star
'CDLSHORTLINE', # Short Line Candle
'CDLSPINNINGTOP', # Spinning Top
'CDLSTALLEDPATTERN', # Stalled Pattern
'CDLSTICKSANDWICH', # Stick Sandwich
'CDLTAKURI', # Takuri (Dragonfly Doji with very long lower shadow)
'CDLTASUKIGAP', # Tasuki Gap
'CDLTHRUSTING', # Thrusting Pattern
'CDLTRISTAR', # Tristar Pattern
'CDLUNIQUE3RIVER', # Unique 3 River
'CDLUPSIDEGAP2CROWS', # Upside Gap Two Crows
'CDLXSIDEGAP3METHODS', # Upside/Downside Gap Three Methods
},
'Statistic Functions': {
'BETA', # Beta
'CORREL', # Pearson's Correlation Coefficient (r)
'LINEARREG', # Linear Regression
'LINEARREG_ANGLE', # Linear Regression Angle
'LINEARREG_INTERCEPT', # Linear Regression Intercept
'LINEARREG_SLOPE', # Linear Regression Slope
'STDDEV', # Standard Deviation
'TSF', # Time Series Forecast
'VAR', # Variance
}
}
god_genes = set()
########################### SETTINGS ##############################
god_genes = {'SMA'}
# god_genes |= all_god_genes['Overlap Studies']
# god_genes |= all_god_genes['Momentum Indicators']
# god_genes |= all_god_genes['Volume Indicators']
# god_genes |= all_god_genes['Volatility Indicators']
# god_genes |= all_god_genes['Price Transform']
# god_genes |= all_god_genes['Cycle Indicators']
# god_genes |= all_god_genes['Pattern Recognition']
# god_genes |= all_god_genes['Statistic Functions']
timeperiods = [5, 6, 12, 15, 50, 55, 100, 110]
operators = [
"D", # Disabled gene
">", # Indicator, bigger than cross indicator
"<", # Indicator, smaller than cross indicator
"=", # Indicator, equal with cross indicator
"C", # Indicator, crossed the cross indicator
"CA", # Indicator, crossed above the cross indicator
"CB", # Indicator, crossed below the cross indicator
">R", # Normalized indicator, bigger than real number
"=R", # Normalized indicator, equal with real number
"<R", # Normalized indicator, smaller than real number
"/>R", # Normalized indicator devided to cross indicator, bigger than real number
"/=R", # Normalized indicator devided to cross indicator, equal with real number
"/<R", # Normalized indicator devided to cross indicator, smaller than real number
"UT", # Indicator, is in UpTrend status
"DT", # Indicator, is in DownTrend status
"OT", # Indicator, is in Off trend status(RANGE)
"CUT", # Indicator, Entered to UpTrend status
"CDT", # Indicator, Entered to DownTrend status
"COT" # Indicator, Entered to Off trend status(RANGE)
]
# number of candles to check up,don,off trend.
TREND_CHECK_CANDLES = 4
DECIMALS = 1
########################### END SETTINGS ##########################
# DATAFRAME = DataFrame()
god_genes = list(god_genes)
# print('selected indicators for optimzatin: \n', god_genes)
god_genes_with_timeperiod = list()
for god_gene in god_genes:
for timeperiod in timeperiods:
god_genes_with_timeperiod.append(f'{god_gene}-{timeperiod}')
# Let give somethings to CatagoricalParam to Play with them
# When just one thing is inside catagorical lists
# TODO: its Not True Way :)
if len(god_genes) == 1:
god_genes = god_genes*2
if len(timeperiods) == 1:
timeperiods = timeperiods*2
if len(operators) == 1:
operators = operators*2
def normalize(df):
df = (df-df.min())/(df.max()-df.min())
return df
def gene_calculator(dataframe, indicator):
# Cuz Timeperiods not effect calculating CDL patterns recognations
if 'CDL' in indicator:
splited_indicator = indicator.split('-')
splited_indicator[1] = "0"
new_indicator = "-".join(splited_indicator)
# print(indicator, new_indicator)
indicator = new_indicator
gene = indicator.split("-")
gene_name = gene[0]
gene_len = len(gene)
if indicator in dataframe.keys():
# print(f"{indicator}, calculated befoure")
# print(len(dataframe.keys()))
return dataframe[indicator]
else:
result = None
# For Pattern Recognations
if gene_len == 1:
# print('gene_len == 1\t', indicator)
result = getattr(ta, gene_name)(
dataframe
)
return normalize(result)
elif gene_len == 2:
# print('gene_len == 2\t', indicator)
gene_timeperiod = int(gene[1])
result = getattr(ta, gene_name)(
dataframe,
timeperiod=gene_timeperiod,
)
return normalize(result)
# For
elif gene_len == 3:
# print('gene_len == 3\t', indicator)
gene_timeperiod = int(gene[2])
gene_index = int(gene[1])
result = getattr(ta, gene_name)(
dataframe,
timeperiod=gene_timeperiod,
).iloc[:, gene_index]
return normalize(result)
# For trend operators(MA-5-SMA-4)
elif gene_len == 4:
# print('gene_len == 4\t', indicator)
gene_timeperiod = int(gene[1])
sharp_indicator = f'{gene_name}-{gene_timeperiod}'
dataframe[sharp_indicator] = getattr(ta, gene_name)(
dataframe,
timeperiod=gene_timeperiod,
)
return normalize(ta.SMA(dataframe[sharp_indicator].fillna(0), TREND_CHECK_CANDLES))
# For trend operators(STOCH-0-4-SMA-4)
elif gene_len == 5:
# print('gene_len == 5\t', indicator)
gene_timeperiod = int(gene[2])
gene_index = int(gene[1])
sharp_indicator = f'{gene_name}-{gene_index}-{gene_timeperiod}'
dataframe[sharp_indicator] = getattr(ta, gene_name)(
dataframe,
timeperiod=gene_timeperiod,
).iloc[:, gene_index]
return normalize(ta.SMA(dataframe[sharp_indicator].fillna(0), TREND_CHECK_CANDLES))
def condition_generator(dataframe, operator, indicator, crossed_indicator, real_num):
condition = (dataframe['volume'] > 10)
# TODO : it ill callculated in populate indicators.
dataframe[indicator] = gene_calculator(dataframe, indicator)
dataframe[crossed_indicator] = gene_calculator(dataframe, crossed_indicator)
indicator_trend_sma = f"{indicator}-SMA-{TREND_CHECK_CANDLES}"
if operator in ["UT", "DT", "OT", "CUT", "CDT", "COT"]:
dataframe[indicator_trend_sma] = gene_calculator(dataframe, indicator_trend_sma)
if operator == ">":
condition = (
dataframe[indicator] > dataframe[crossed_indicator]
)
elif operator == "=":
condition = (
np.isclose(dataframe[indicator], dataframe[crossed_indicator])
)
elif operator == "<":
condition = (
dataframe[indicator] < dataframe[crossed_indicator]
)
elif operator == "C":
condition = (
(qtpylib.crossed_below(dataframe[indicator], dataframe[crossed_indicator])) |
(qtpylib.crossed_above(dataframe[indicator], dataframe[crossed_indicator]))
)
elif operator == "CA":
condition = (
qtpylib.crossed_above(dataframe[indicator], dataframe[crossed_indicator])
)
elif operator == "CB":
condition = (
qtpylib.crossed_below(
dataframe[indicator], dataframe[crossed_indicator])
)
elif operator == ">R":
condition = (
dataframe[indicator] > real_num
)
elif operator == "=R":
condition = (
np.isclose(dataframe[indicator], real_num)
)
elif operator == "<R":
condition = (
dataframe[indicator] < real_num
)
elif operator == "/>R":
condition = (
dataframe[indicator].div(dataframe[crossed_indicator]) > real_num
)
elif operator == "/=R":
condition = (
np.isclose(dataframe[indicator].div(dataframe[crossed_indicator]), real_num)
)
elif operator == "/<R":
condition = (
dataframe[indicator].div(dataframe[crossed_indicator]) < real_num
)
elif operator == "UT":
condition = (
dataframe[indicator] > dataframe[indicator_trend_sma]
)
elif operator == "DT":
condition = (
dataframe[indicator] < dataframe[indicator_trend_sma]
)
elif operator == "OT":
condition = (
np.isclose(dataframe[indicator], dataframe[indicator_trend_sma])
)
elif operator == "CUT":
condition = (
(
qtpylib.crossed_above(
dataframe[indicator],
dataframe[indicator_trend_sma]
)
) &
(
dataframe[indicator] > dataframe[indicator_trend_sma]
)
)
elif operator == "CDT":
condition = (
(
qtpylib.crossed_below(
dataframe[indicator],
dataframe[indicator_trend_sma]
)
) &
(
dataframe[indicator] < dataframe[indicator_trend_sma]
)
)
elif operator == "COT":
condition = (
(
(
qtpylib.crossed_below(
dataframe[indicator],
dataframe[indicator_trend_sma]
)
) |
(
qtpylib.crossed_above(
dataframe[indicator],
dataframe[indicator_trend_sma]
)
)
) &
(
np.isclose(
dataframe[indicator],
dataframe[indicator_trend_sma]
)
)
)
return condition, dataframe
class GodStraNew_SMAonly(IStrategy):
# #################### RESULTS PASTE PLACE ####################
# Buy hyperspace params:
buy_params = {
"buy_crossed_indicator0": "SMA-110",
"buy_crossed_indicator1": "SMA-6",
"buy_crossed_indicator2": "SMA-100",
"buy_indicator0": "SMA-5",
"buy_indicator1": "SMA-5",
"buy_indicator2": "SMA-55",
"buy_operator0": "/<R",
"buy_operator1": "<R",
"buy_operator2": "/<R",
"buy_real_num0": 0.3,
"buy_real_num1": 0.5,
"buy_real_num2": 0.9,
}
# Sell hyperspace params:
sell_params = {
"sell_crossed_indicator0": "SMA-50",
"sell_crossed_indicator1": "SMA-50",
"sell_crossed_indicator2": "SMA-110",
"sell_indicator0": "SMA-15",
"sell_indicator1": "SMA-110",
"sell_indicator2": "SMA-5",
"sell_operator0": "=",
"sell_operator1": "CA",
"sell_operator2": "<",
"sell_real_num0": 0.9,
"sell_real_num1": 0.5,
"sell_real_num2": 0.8,
}
# ROI table:
minimal_roi = {
"0": 0.288,
"81": 0.101,
"170": 0.049,
"491": 0
}
# Trailing stop:
trailing_stop = True
trailing_stop_positive = 0.323
trailing_stop_positive_offset = 0.388
trailing_only_offset_is_reached = True
# #################### END OF RESULT PLACE ####################
# TODO: Its not dry code!
# Buy Hyperoptable Parameters/Spaces.
buy_crossed_indicator0 = CategoricalParameter(
god_genes_with_timeperiod, default="ADD-20", space='buy')
buy_crossed_indicator1 = CategoricalParameter(
god_genes_with_timeperiod, default="ASIN-6", space='buy')
buy_crossed_indicator2 = CategoricalParameter(
god_genes_with_timeperiod, default="CDLEVENINGSTAR-50", space='buy')
buy_indicator0 = CategoricalParameter(
god_genes_with_timeperiod, default="SMA-100", space='buy')
buy_indicator1 = CategoricalParameter(
god_genes_with_timeperiod, default="WILLR-50", space='buy')
buy_indicator2 = CategoricalParameter(
god_genes_with_timeperiod, default="CDLHANGINGMAN-20", space='buy')
buy_operator0 = CategoricalParameter(operators, default="/<R", space='buy')
buy_operator1 = CategoricalParameter(operators, default="<R", space='buy')
buy_operator2 = CategoricalParameter(operators, default="CB", space='buy')
buy_real_num0 = DecimalParameter(0, 1, decimals=DECIMALS, default=0.89009, space='buy')
buy_real_num1 = DecimalParameter(0, 1, decimals=DECIMALS, default=0.56953, space='buy')
buy_real_num2 = DecimalParameter(0, 1, decimals=DECIMALS, default=0.38365, space='buy')
# Sell Hyperoptable Parameters/Spaces.
sell_crossed_indicator0 = CategoricalParameter(
god_genes_with_timeperiod, default="CDLSHOOTINGSTAR-150", space='sell')
sell_crossed_indicator1 = CategoricalParameter(
god_genes_with_timeperiod, default="MAMA-1-100", space='sell')
sell_crossed_indicator2 = CategoricalParameter(
god_genes_with_timeperiod, default="CDLMATHOLD-6", space='sell')
sell_indicator0 = CategoricalParameter(
god_genes_with_timeperiod, default="CDLUPSIDEGAP2CROWS-5", space='sell')
sell_indicator1 = CategoricalParameter(
god_genes_with_timeperiod, default="CDLHARAMICROSS-150", space='sell')
sell_indicator2 = CategoricalParameter(
god_genes_with_timeperiod, default="CDL2CROWS-5", space='sell')
sell_operator0 = CategoricalParameter(operators, default="<R", space='sell')
sell_operator1 = CategoricalParameter(operators, default="D", space='sell')
sell_operator2 = CategoricalParameter(operators, default="/>R", space='sell')
sell_real_num0 = DecimalParameter(0, 1, decimals=DECIMALS, default=0.09731, space='sell')
sell_real_num1 = DecimalParameter(0, 1, decimals=DECIMALS, default=0.81657, space='sell')
sell_real_num2 = DecimalParameter(0, 1, decimals=DECIMALS, default=0.87267, space='sell')
# Stoploss:
stoploss = -1
# Buy hypers
timeframe = '5m'
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
'''
It's good to calculate all indicators in all time periods here and so optimize the strategy.
But this strategy can take much time to generate anything that may not use in his optimization.
I just calculate the specific indicators in specific time period inside buy and sell strategy populator methods if needed.
Also, this method (populate_indicators) just calculates default value of hyperoptable params
so using this method have not big benefits instade of calculating useable things inside buy and sell trand populators
'''
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = list()
# TODO: Its not dry code!
buy_indicator = self.buy_indicator0.value
buy_crossed_indicator = self.buy_crossed_indicator0.value
buy_operator = self.buy_operator0.value
buy_real_num = self.buy_real_num0.value
condition, dataframe = condition_generator(
dataframe,
buy_operator,
buy_indicator,
buy_crossed_indicator,
buy_real_num
)
conditions.append(condition)
# backup
buy_indicator = self.buy_indicator1.value
buy_crossed_indicator = self.buy_crossed_indicator1.value
buy_operator = self.buy_operator1.value
buy_real_num = self.buy_real_num1.value
condition, dataframe = condition_generator(
dataframe,
buy_operator,
buy_indicator,
buy_crossed_indicator,
buy_real_num
)
conditions.append(condition)
buy_indicator = self.buy_indicator2.value
buy_crossed_indicator = self.buy_crossed_indicator2.value
buy_operator = self.buy_operator2.value
buy_real_num = self.buy_real_num2.value
condition, dataframe = condition_generator(
dataframe,
buy_operator,
buy_indicator,
buy_crossed_indicator,
buy_real_num
)
conditions.append(condition)
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'buy']=1
# print(len(dataframe.keys()))
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = list()
# TODO: Its not dry code!
sell_indicator = self.sell_indicator0.value
sell_crossed_indicator = self.sell_crossed_indicator0.value
sell_operator = self.sell_operator0.value
sell_real_num = self.sell_real_num0.value
condition, dataframe = condition_generator(
dataframe,
sell_operator,
sell_indicator,
sell_crossed_indicator,
sell_real_num
)
conditions.append(condition)
sell_indicator = self.sell_indicator1.value
sell_crossed_indicator = self.sell_crossed_indicator1.value
sell_operator = self.sell_operator1.value
sell_real_num = self.sell_real_num1.value
condition, dataframe = condition_generator(
dataframe,
sell_operator,
sell_indicator,
sell_crossed_indicator,
sell_real_num
)
conditions.append(condition)
sell_indicator = self.sell_indicator2.value
sell_crossed_indicator = self.sell_crossed_indicator2.value
sell_operator = self.sell_operator2.value
sell_real_num = self.sell_real_num2.value
condition, dataframe = condition_generator(
dataframe,
sell_operator,
sell_indicator,
sell_crossed_indicator,
sell_real_num
)
conditions.append(condition)
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'sell']=1
return dataframe