-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrypto_ta_analysis.py
More file actions
1465 lines (1076 loc) · 64.6 KB
/
crypto_ta_analysis.py
File metadata and controls
1465 lines (1076 loc) · 64.6 KB
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ccxt
import pandas as pd
import pandas_ta as ta
import time
from datetime import datetime
import schedule
import pytz
#---Binance Connection--------------------------------------------------------------
# binance api
apiKey = ""
secretKey = ""
mailAddress = ""
sendTo = ""
password = ""
# API CONNECT
exchange = ccxt.binance({
"apiKey": apiKey,
"secret": secretKey,
'enableRateLimit': True,
'options': {
'defaultType': 'future'
},
'enableRateLimit': True
})
#exchange.set_sandbox_mode(True)
#----PD,TA Integers--------------------------------------------------------------------------
tm = ""
intervalText = ""
###
bool_4h = True
bool_1d = True
###
#taAnalysisTime = True
testBool = True
closedCandlePatterns = False
###
barNumber2 = 2 # 2
candleCountLimit = 51 # 37
CandlePattern = ""
Direction = ""
starCount = 0
###
listOfData1Symbol = []
listOfData2Symbol = []
#------------------------
pumbDumpBool = True
i = 0
timeCounter = 60 # 46 normal
###
priceChangePercent = 1000 # 15
priceChangePercentNeg = -1000
###
minVolShowed = -1
maxVolShowed = 8
#################
lenOfSymbolTables = 0
symbol = "BTCUSDT"
processAllPer = 0 # max 100
dataTxt = ""
startSettingsBool = True
processFutureBool = False
DelistCoPDFuture = ["USDCUSDT"]
DelistCoTAFuture = ["USDCUSDT"]
DelistCoForProcess = ["USDCUSDT"]
OpenPositionsList = []
####### ShortLongProcess --------------------
dataProcessF1 = pd.DataFrame(columns=['currentTime','btcPoz','btcNeg','symbol','symbol2','price','processOption','point','star','candle','rsi','bbands_L','bbands_M','bbands_U','stochrsi_K','stochrsi_D','psar_L','psar_S','psar_R','macd_H','macd_S','ma_25','ma_48'])
listOfProcessOpt = "listOfProcessOpt.txt"
def sortLongInf() :
CurrentTime()
global dataProcessF1
#balance = exchange.fetch_balance()
#if float(balance['total']["USDT"]) >= 1 : # 2
dataProcessF1.loc[len(dataProcessF1.index)] = [currentTime,btcStarCountPoz,btcStarCountNeg,symbolT,symbolT2,barClosePrice0,Direction,processAllPer,starCount,CandlePattern,tableIndicators['rsi'][1],tableIndicators['bbands_L'][1],tableIndicators['bbands_M'][1],tableIndicators['bbands_U'][1],tableIndicators['stochrsi_K'][1],tableIndicators['stochrsi_D'][1],tableIndicators['psar_L'][1],tableIndicators['psar_S'][1],tableIndicators['psar_R'][1],tableIndicators['macd_H'][1],tableIndicators['macd_S'][1],tableIndicators['ma_25'][1],tableIndicators['ma_48'][1]]
def processShortLong() : # total yerine free balance ? - acık emirler yok edilsin - anlık close price al
global dataProcessF,dataProcessF1,BullishProcess,BearishProcess,BearishStart,BullishStart,positionCount # iki (isimden symbol) bir tane olsun -
if not dataProcessF1.empty:
#reverse data frame
dataProcessF1 = dataProcessF1.iloc[::-1]
print("dataProcessF1 : ",dataProcessF1)
BullishTableCount = 0
BearishTableCount = 0
BullishProcess = False
BearishProcess = False
BullishStart = False
BearishStart = False
#dataProcessF1 = dataProcessF1.sort_values(by='point', ascending=False)
dataProcessF = dataProcessF1.reset_index(drop=True)
for x in DelistCoForProcess: # eth,btc,bnb.. ayrı bir analiz yhapısı olustur uzun vade veya yuksek kaldırac icin
dataProcessF = dataProcessF[dataProcessF["symbol"].str.contains(x) == False]
Recorder()
print("BearishTableCount",BearishTableCount,"BullishTableCount",BullishTableCount)
print("tableDataLenght : ",len(dataProcessF.index))
else :
print("empty dataProcessF1")
####### PD --------------------
def PumpDumpData () :
global i
if i == timeCounter:
i = 0
CurrentTime()
global data2,DelistCoPDFuture,DelistCoTAFuture
# future
data = pd.read_json('https://fapi.binance.com/fapi/v1/ticker/24hr')
data1 = pd.DataFrame(data.sort_values(by=["symbol"], ascending=True), columns=["symbol","lastPrice","quoteVolume","priceChangePercent"])
for x in DelistCoPDFuture:
data1 = data1[data1["symbol"].str.contains(x) == False]
data2 = data1[data1['symbol'].str.endswith('USDT')]
data2 = data2[data2["symbol"].str.endswith('DOWNUSDT') == False]
data2 = data2[data2["symbol"].str.endswith('UPUSDT') == False]
data2.drop(data2[data2["lastPrice"] == 0].index, inplace = True)
pChangePer = data2["priceChangePercent"].values.tolist()
# delist new listed coins or coins these have not enough candles
global startSettingsBool,lenOfSymbolTables,listOfData1Symbol,listOfData2Symbol
if len(data1.index) != lenOfSymbolTables :
if listOfData1Symbol:
listOfData2Symbol = data2["symbol"].values.tolist()
set1 = set(listOfData1Symbol)
set2 = set(listOfData2Symbol)
missing = list(sorted(set1 - set2))
added = list(sorted(set2 - set1))
print('missing:', missing)
print('added:', added)
DelistCoPDFuture = DelistCoPDFuture + missing + added # bir cok koini missing diye yakaliuor düzelt
DelistCoTAFuture = DelistCoPDFuture + missing + added
#startSettingsBool = True
print("lenOfSymbolTables not equal data2, symbol length equation started")
for x in DelistCoPDFuture:
data2 = data2[data2["symbol"].str.contains(x) == False]
listOfData1Symbol = data2["symbol"].values.tolist()
lenOfSymbolTables = len(data1.index)
if startSettingsBool == True:
sT = data2['symbol'].to_numpy()
for symbolForDel in sT :
co = str(symbolForDel[:-4]) + "/USDT"
bars = exchange.fetch_ohlcv(co, timeframe= "1d", since = None, limit = candleCountLimit)
dfbars = pd.DataFrame(bars, columns=["timestamp", "open", "high", "low", "close", "volume"])
if len(dfbars.index) < candleCountLimit :
DelistCoTAFuture.append(symbolForDel)
if len(dfbars.index) < 3 :
DelistCoPDFuture.append(symbolForDel)
continue
time.sleep(0.05)
for x in DelistCoPDFuture:
data2 = data2[data2["symbol"].str.contains(x) == False]
listOfData1Symbol = data2["symbol"].values.tolist()
startSettingsBool = False
print("updatedSettings","startSettingsBool : ",startSettingsBool)
# for too many requests
time.sleep(0.025)
#i
global Sdata,Pdata,Vdata
if i == 0 :
Sdata = data2["symbol"].values.tolist()
Pdata = data2["lastPrice"].values.tolist()
Vdata = data2["quoteVolume"].values.tolist()
if i != 0:
Sdata1 = data2["symbol"].values.tolist()
Pdata1 = data2["lastPrice"].values.tolist()
Pdata2 = [i - j for i, j in zip(Pdata1, Pdata)]
Pdata3 = [i / j for i, j in zip(Pdata2, Pdata)]
PdataACC = [i * 100 for i in Pdata3]
Vdata1 = data2["quoteVolume"].values.tolist()
Vdata2 = [i - j for i, j in zip(Vdata1, Vdata)]
Vdata3 = [i / j for i, j in zip(Vdata2, Vdata)]
VdataACC = [i * 100 for i in Vdata3]
#table0
global table0,table00
table0 = pd.DataFrame(list(zip(Sdata,PdataACC,VdataACC,Pdata1,Vdata1,pChangePer)),columns =['Symbol','priceAcc','volAcc','price','volume','pChangePer'])
table0 = table0[(table0['pChangePer']>= priceChangePercentNeg ) & (table0['pChangePer']<= priceChangePercent)]
table0 = table0[(table0['volAcc']>= minVolShowed )&(table0['volAcc']<= maxVolShowed )]
if not table0.empty and Sdata == Sdata1:
table0.sort_values(by=['priceAcc'], inplace=True, ascending=False)
table00 = table0.reset_index(drop=True)
tableNeg0 = table0.iloc[::-1]
tableNeg00 = tableNeg0.reset_index(drop=True)
#print("symbol",tableNeg00['Symbol'][0],"price",tableNeg00['price'][0],"priceacc",tableNeg00['priceAcc'][0])
global symbol,symbolPoz2,priceAcc,volAcc,price,symbolNeg,symbolNeg2,priceAccNeg,volAccNeg,priceNeg
#1 poz
symbol = table00['Symbol'][0]
symbolPoz2 = str(symbol[:-4]) + "/USDT"
priceAcc = table00['priceAcc'][0]
volAcc = table00['volAcc'][0]
price = format(float(table00['price'][0]), '.8f')
#volume = table00['volume'][0]
#1 neg
symbolNeg = tableNeg00['Symbol'][0]
symbolNeg2 = str(symbolNeg[:-4]) + "/USDT"
priceAccNeg = tableNeg00['priceAcc'][0]
volAccNeg = tableNeg00['volAcc'][0]
priceNeg = format(float(tableNeg00['price'][0]), '.8f')
#volumeNeg = tableNeg00['volume'][0]
# -------------- pump dump test --------------------------------
if priceAcc > 1 and not symbol :
print('PUMP0',symbol,'PA0',priceAcc,'VA0',volAcc,'Pr0',price)
#1.Dump Datas
if priceAccNeg < -1 and not symbolNeg :
print('DUMP0',symbolNeg,'PA0',priceAccNeg,'VA0',volAccNeg,'Pr0',priceNeg)
# ---------------------------------------------------------------
else :
i = 0
i = i+1
####### TA --------------------
def CurrentTime() :
global currentTimeInGreenwich
global currentTime
greenwichTz = pytz.timezone("Europe/London")
timeInGreenwich = datetime.now(greenwichTz)
currentTimeInGreenwich = timeInGreenwich.strftime("%d/%m/%Y %H:%M:%S")
#print(timeInGreenwich.hour) # tek tek sayı olarak alma bir döngü yapılabilir
now = datetime.now()
currentTime = now.strftime("%d/%m/%Y %H:%M:%S")
#print("Current Time =", currentTime)
#print("Current Time G =", currentTimeInGreenwich)
#------------------------------
def interval_4h():
global tm,dataTxt,intervalText
tm = "4h"
intervalText = "4 hour candle"
dataTxt = "taDF4h.txt"
CurrentTime()
print("I'm working...4h",currentTime)
TechnicalAnalysis()
def interval_1d():
global tm,dataTxt,intervalText
tm = "1d"
intervalText = "1 day candle"
dataTxt = "taDF1d.txt"
CurrentTime()
print("I'm working...1d",currentTime)
TechnicalAnalysis()
def taTimeIntervals () :
if bool_4h == True :
schedule.every().days.at("16:00:10").do(interval_4h) #h_4_00 =
schedule.every().days.at("20:00:10").do(interval_4h) #h_4_20 =
schedule.every().days.at("00:00:10").do(interval_4h) #h_4_16 =
schedule.every().days.at("04:00:10").do(interval_4h) #h_4_12 =
schedule.every().days.at("08:00:10").do(interval_4h) #h_4_8 =
schedule.every().days.at("12:00:10").do(interval_4h) #h_4_4 =
if bool_1d == True :
schedule.every().day.at("00:00:19").do(interval_1d)
taTimeIntervals()
#------------------------------
def Recorder() :
if not dataProcessF.empty :
with open(dataTxt, 'a') as f:
df_string = dataProcessF.to_string()
f.write(df_string)
f.write('\n')
#------------------------------
def Indicators () :
################################### (INDICATOR) ########################################
global tableIndicators,rsi,bbands_L,bbands_M,bbands_U,stochrsi_K,stochrsi_D,psar_L,psar_S,psar_R,macd_H,macd_S,ma_25,ma_48,indicatorPointsBullish,indicatorPointsBearish,rsiPointBullish,rsiPointBearish,bbandPointBullish,bbandPointBearish,stockRSiBullish,stockRSiBearish
#rsi
rsi = ta.rsi(dfbarCloseAll, 14) # rsi uyumsuzlugu hesaplama
rsi = rsi.values.tolist()
#print(symbolT,rsi,"type",type(rsi))
time.sleep(0.01)
#bbands
bbands = ta.bbands(dfbarCloseAll,21,2) # boll ort bant üstü ürta bant altı üst bant üst alt bant üst
bbands_L = bbands["BBL_21_2.0"].values.tolist()
bbands_M = bbands["BBM_21_2.0"].values.tolist()
bbands_U = bbands["BBU_21_2.0"].values.tolist()
#print(symbolT,bbands,"type",type(bbands))
time.sleep(0.01)
#stochrsi
stochrsi = ta.stochrsi(dfbarCloseAll,14,14,3,3) # stock rsi kesisim bulma
stochrsi_K = stochrsi["STOCHRSIk_14_14_3_3"].values.tolist()
stochrsi_D = stochrsi["STOCHRSId_14_14_3_3"].values.tolist()
#print(symbolT,stochrsi_K,"type",type(stochrsi_K))
time.sleep(0.01)
#psar
psar = ta.psar(dfbarHighAll,dfbarLowAll,dfbarCloseAll,0.02,0.02,0.2) # sarlar biraz geniş olabilir farklı deger gosteriyor
psar_L = psar["PSARl_0.02_0.2"].values.tolist()
psar_S = psar["PSARs_0.02_0.2"].values.tolist()
psar_R = psar["PSARr_0.02_0.2"].values.tolist()
#print(symbolT,psar_S,"type",type(psar))
#print(symbolT,psar)
time.sleep(0.01)
#macd
macd = ta.macd(dfbarCloseAll,12,26,9)
macd_H = macd["MACDh_12_26_9"].values.tolist()
macd_S = macd["MACDs_12_26_9"].values.tolist()
#print(symbolT,macd)
time.sleep(0.01)
#ma25 ma48
ma25 = ta.ma("sma",dfbarCloseAll, length = 25)
ma_25 = ma25.values.tolist()
ma48 = ta.ma("sma",dfbarCloseAll, length = 48)
ma_48 = ma48.values.tolist()
#print(symbolT,ma_25,"type",type(ma_25))
#fib
#fibonacci = ta.fwma(dfbarCloseAll,10,True)
#print(symbolT,fibonacci)
#adx
#adx = ta.adx(dfbarHighAll,dfbarLowAll,dfbarCloseAll, length = 14)
#print(symbolT,adx,"type",type(adx))
tableIndicators = pd.DataFrame(list(zip(rsi,bbands_L,bbands_M,bbands_U,stochrsi_K,stochrsi_D,psar_L,psar_S,psar_R,macd_H,macd_S,ma_25,ma_48)),columns =['rsi','bbands_L','bbands_M','bbands_U','stochrsi_K','stochrsi_D','psar_L','psar_S','psar_R','macd_H','macd_S','ma_25','ma_48'])
tableIndicators = tableIndicators.iloc[::-1] # reverse table
tableIndicators = tableIndicators.reset_index(drop=True)
indicatorPointsBullish = 0
indicatorPointsBearish = 0
rsiPointBullish = 0
rsiPointBearish = 0
bbandPointBullish = 0
bbandPointBearish = 0
stockRSiBullish = 0
stockRSiBearish = 0
# 10 point rsi
if tableIndicators['rsi'][1] > 75 :
indicatorPointsBearish = indicatorPointsBearish + 10
rsiPointBearish = rsiPointBearish + 10
elif tableIndicators['rsi'][1] > 65 :
indicatorPointsBearish = indicatorPointsBearish + 5
rsiPointBearish = rsiPointBearish + 5
if tableIndicators['rsi'][1] < 25 :
indicatorPointsBullish = indicatorPointsBullish + 10
rsiPointBullish = rsiPointBullish + 10
elif tableIndicators['rsi'][1] < 35 :
indicatorPointsBullish = indicatorPointsBullish + 5
rsiPointBullish = rsiPointBullish + 5
# 10 point bbands
if tableIndicators['bbands_U'][1] < barHighPrice :
indicatorPointsBearish = indicatorPointsBearish + 10
bbandPointBearish = bbandPointBearish + 10
elif tableIndicators['bbands_M'][1] < barClosePrice :
indicatorPointsBearish = indicatorPointsBearish + 5
bbandPointBearish = bbandPointBearish + 5
if tableIndicators['bbands_L'][1] > barLowPrice :
indicatorPointsBullish = indicatorPointsBullish + 10
bbandPointBullish = bbandPointBullish + 10
elif tableIndicators['bbands_M'][1] > barClosePrice :
indicatorPointsBullish = indicatorPointsBullish + 5
bbandPointBullish = bbandPointBullish + 5
# 10 point stochrsi
if tableIndicators['stochrsi_K'][1] > 70 :
indicatorPointsBearish = indicatorPointsBearish + 5
stockRSiBearish = stockRSiBearish + 5
elif tableIndicators['stochrsi_K'][1] < 20 :
indicatorPointsBullish = indicatorPointsBullish + 5
stockRSiBullish = stockRSiBullish + 5
if tableIndicators['stochrsi_D'][1] > 70 :
indicatorPointsBearish = indicatorPointsBearish + 5
stockRSiBearish = stockRSiBearish + 5 # ikiye ayrılabilir stockRSiBearishD stockRSiBearishK diye
elif tableIndicators['stochrsi_D'][1] < 20 :
indicatorPointsBullish = indicatorPointsBullish + 5
stockRSiBullish = stockRSiBullish + 5
#10 point psar
"""if not math.isnan(tableIndicators['psar_S'][1]) :
indicatorPoints = indicatorPoints + 5
#print(symbolT,"psar_S",tableIndicators['psar_S'][1],tableIndicators['psar_R'][1])
if tableIndicators['psar_R'][1] == 1 and not math.isnan(tableIndicators['psar_S'][1]):
print(symbolT,"psar_S",tableIndicators['psar_S'][1],tableIndicators['psar_R'][1],"--------------")
indicatorPoints = indicatorPoints + 5
if not math.isnan(tableIndicators['psar_L'][1]) :
indicatorPoints = indicatorPoints + 5
#print(symbolT,"psar_L",tableIndicators['psar_L'][1],tableIndicators['psar_R'][1])
if tableIndicators['psar_R'][1] == 1 and not math.isnan(tableIndicators['psar_L'][1]):
print(symbolT,"psar_L",tableIndicators['psar_L'][1],tableIndicators['psar_R'][1],"--------------")
indicatorPoints = processHalfPerBearish + 5"""
#------------------------------
def CheckLowValueInCandles():
global CheckLowValuestar
global CheckHighValuestar
global CheckLowValuestar3
global CheckHighValuestar3
CheckLowValuestar = 0
CheckHighValuestar = 0
CheckLowValuestar3 = 0
CheckHighValuestar3 = 0
#global rangeStartValueForAverage
priceLowCount10 = 0
priceHighCount10 = 0
priceLowCount9 = 0
priceHighCount9 = 0
for x in range(rangeStartValueForAverage,rangeStartValueForAverage + 10):
if barLowPrice < float(dfbarLowAll[len(dfbars.index) - x]) :
priceLowCount10 = priceLowCount10 + 1
if barHighPrice > float(dfbarHighAll[len(dfbars.index) - x]) :
priceHighCount10 = priceHighCount10 + 1
if priceLowCount10 == 10 :
CheckLowValuestar = CheckLowValuestar + 1 # 1 star -
#print(symbolT,"1 star - low value in 10 candle")
if priceHighCount10 == 10 :
CheckHighValuestar = CheckHighValuestar + 1 # 1 star -
#print(symbolT,"1 star - low value in 10 candle")
for x in range(rangeStartValueForAverage + 1,rangeStartValueForAverage + 10):
if x < rangeStartValueForAverage + 9 :
if barLowPrice3 < float(dfbarLowAll[len(dfbars.index) - x]) :
priceLowCount9 = priceLowCount9 + 1
if barHighPrice3 > float(dfbarHighAll[len(dfbars.index) - x]) :
priceHighCount9 = priceHighCount9 + 1
if priceLowCount9 == 9 :
CheckLowValuestar3 = CheckLowValuestar3 + 1 # 1 star -
#print(symbolT,"1 star - low3 value in 9 candle")
if priceHighCount9 == 9 :
CheckHighValuestar3 = CheckHighValuestar3 + 1 # 1 star -
#print(symbolT,"1 star - low3 value in 9 candle")
#------------------------------
def CheckCandles():
##########CheckCandlesAverageLowOrHigh######################
global CheckCandlesAveragePozstar
global CheckCandlesAverageNegstar
CheckCandlesAveragePozstar = 0
CheckCandlesAverageNegstar = 0
global CheckCandlesAveragePozstar3
global CheckCandlesAverageNegstar3
CheckCandlesAveragePozstar3 = 0
CheckCandlesAverageNegstar3 = 0
global ClosePriceAverage6,ClosePriceAverage12,ClosePriceAverage24,ClosePriceAverage36
global Close3PriceAverage6,Close3PriceAverage12,Close3PriceAverage24,Close3PriceAverage36
#global Average6CandleCount
#global Average12CandleCount
#global Average24CandleCount
#global Average36CandleCount
#global rangeStartValueForAverage
#Average Close Price 6 Candle
AllClosePrice6Candle = 0
AllClose3Price6Candle = 0
for x in range(rangeStartValueForAverage,rangeStartValueForAverage + Average6CandleCount):
if x > rangeStartValueForAverage :
AllClose3Price6Candle = AllClose3Price6Candle + float(dfbarCloseAll[len(dfbars.index) - x])
AllClosePrice6Candle = AllClosePrice6Candle + float(dfbarCloseAll[len(dfbars.index) - x])
ClosePriceAverage6 = (AllClosePrice6Candle / Average6CandleCount )
Close3PriceAverage6 = AllClose3Price6Candle / (Average6CandleCount -1)
#Average Close Price 12 Candle
AllLowHighLevel12Candle = 0
AllClose3Price12Candle = 0
AllLowHigh3Level12Candle = 0
AllClosePrice12Candle = 0
for x in range(rangeStartValueForAverage,rangeStartValueForAverage + Average12CandleCount):
if x > rangeStartValueForAverage :
AllLowHigh3Level12Candle = AllLowHigh3Level12Candle + ( float(dfbarHighAll[len(dfbars.index) - x]) - float(dfbarLowAll[len(dfbars.index) - x]) )
AllClose3Price12Candle = AllClose3Price12Candle + float(dfbarCloseAll[len(dfbars.index) - x])
AllLowHighLevel12Candle = AllLowHighLevel12Candle + ( float(dfbarHighAll[len(dfbars.index) - x]) - float(dfbarLowAll[len(dfbars.index) - x]) )
AllClosePrice12Candle = AllClosePrice12Candle + float(dfbarCloseAll[len(dfbars.index) - x])
LowHighLevelAverage12 = AllLowHighLevel12Candle / Average12CandleCount
LowHighLevel3Average12 = AllLowHigh3Level12Candle / (Average12CandleCount -1 )
ClosePriceAverage12 = (AllClosePrice12Candle / Average12CandleCount)
Close3PriceAverage12 = AllClose3Price12Candle / (Average12CandleCount -1)
#Average Close Price 24 Candle
AllClosePrice24Candle = 0
AllClose3Price24Candle = 0
for x in range(rangeStartValueForAverage,rangeStartValueForAverage + Average24CandleCount):
if x > rangeStartValueForAverage :
AllClose3Price24Candle = AllClose3Price24Candle + float(dfbarCloseAll[len(dfbars.index) - x])
AllClosePrice24Candle = AllClosePrice24Candle + float(dfbarCloseAll[len(dfbars.index) - x])
ClosePriceAverage24 = (AllClosePrice24Candle / Average24CandleCount)
Close3PriceAverage24 = AllClose3Price24Candle / (Average24CandleCount -1)
#Average Close Price 36 Candle
AllLow3Level36Candle = 0
AllHigh3Level36Candle = 0
AllClose3Price36Candle = 0
AllLowLevel36Candle = 0
AllHighLevel36Candle = 0
AllClosePrice36Candle = 0
for x in range(rangeStartValueForAverage,rangeStartValueForAverage + Average36CandleCount):
if x > rangeStartValueForAverage :
AllLow3Level36Candle = AllLow3Level36Candle + float(dfbarLowAll[len(dfbars.index) - x])
AllHigh3Level36Candle = AllHigh3Level36Candle + float(dfbarHighAll[len(dfbars.index) - x])
AllClose3Price36Candle = AllClose3Price36Candle + float(dfbarCloseAll[len(dfbars.index) - x])
AllLowLevel36Candle = AllLowLevel36Candle + float(dfbarLowAll[len(dfbars.index) - x])
AllHighLevel36Candle = AllHighLevel36Candle + float(dfbarHighAll[len(dfbars.index) - x])
AllClosePrice36Candle = AllClosePrice36Candle + float(dfbarCloseAll[len(dfbars.index) - x])
HighLevelAverage36 = AllHighLevel36Candle / Average36CandleCount
High3LevelAverage36 = AllHigh3Level36Candle / (Average36CandleCount - 1)
LowLevelAverage36 = AllLowLevel36Candle / Average36CandleCount
Low3LevelAverage36 = AllLow3Level36Candle / (Average36CandleCount - 1)
ClosePriceAverage36 = AllClosePrice36Candle / Average36CandleCount
Close3PriceAverage36 = AllClose3Price36Candle / (Average36CandleCount -1)
#rangeStartValueForAverage = 3 # reset range star average
#List Of 4 Average Values
ListOfAverage = [ClosePriceAverage6,ClosePriceAverage12,ClosePriceAverage24,ClosePriceAverage36]
List3OfAverage = [Close3PriceAverage6,Close3PriceAverage12,Close3PriceAverage24,Close3PriceAverage36]
global averageLowCount
averageLowCount = 0
for x in ListOfAverage:
if x > barClosePrice :
averageLowCount = averageLowCount + 1
if averageLowCount > 3 :
CheckCandlesAverageNegstar = CheckCandlesAverageNegstar + 2 # 2 star - lower than 4 average price
#print(symbolT,"2 star - lower than min 4 average price")
elif averageLowCount > 1 :
CheckCandlesAverageNegstar = CheckCandlesAverageNegstar + 1 # 1 star - lower than 2 average price
#print(symbolT,"1 star - lower than min 2 average price")
if averageLowCount < 1 :
CheckCandlesAveragePozstar = CheckCandlesAveragePozstar + 2 # 2 star - lower than 4 average price
#print(symbolT,"2 star - lower than min 4 average price")
elif averageLowCount < 2 :
CheckCandlesAveragePozstar = CheckCandlesAveragePozstar + 1 # 1 star - lower than 2 average price
#print(symbolT,"1 star - lower than min 2 average price")
averageLow3Count = 0
for x in List3OfAverage:
if x > barClosePrice3 :
averageLow3Count = averageLow3Count + 1
if averageLow3Count > 3 :
CheckCandlesAverageNegstar3 = CheckCandlesAverageNegstar3 + 2 # 2 star - lower than 4 average price
#print(symbolT,"2 star - lower than min 4 average price")
elif averageLow3Count > 1 :
CheckCandlesAverageNegstar3 = CheckCandlesAverageNegstar3 + 1 # 1 star - lower than 2 average price
#print(symbolT,"1 star - lower than min 2 average price")
if averageLow3Count < 1 :
CheckCandlesAveragePozstar3 = CheckCandlesAveragePozstar3 + 2 # 2 star - lower than 4 average price
#print(symbolT,"2 star - lower than min 4 average price")
elif averageLow3Count < 2 :
CheckCandlesAveragePozstar3 = CheckCandlesAveragePozstar3 + 1 # 1 star - lower than 2 average price
#print(symbolT,"1 star - lower than min 2 average price")
##########BarLowHighLevelCompareToOtherBars#################
global BarLowHighLevelstar
global BarLowHighLevelstar3
BarLowHighLevelstar = 0
BarLowHighLevelstar3 = 0
if (barHighPrice - barLowPrice) > LowHighLevelAverage12 :
BarLowHighLevelstar = BarLowHighLevelstar + 1 # 1 star - low high level higher than average in 10 candle
#print(symbolT,"1 star - low high level higher than average in 10 candle")
if (barHighPrice3 - barLowPrice3) > LowHighLevel3Average12 :
BarLowHighLevelstar3 = BarLowHighLevelstar3 + 1
##########BarLowLevelCompareToOtherBars#################
global BarLowLevelstar
global BarHighLevelstar
global BarLowLevelstar3
global BarHighLevelstar3
BarLowLevelstar = 0
BarHighLevelstar = 0
BarLowLevelstar3 = 0
BarHighLevelstar3 = 0
if barLowPrice < LowLevelAverage36 :
BarLowLevelstar = BarLowLevelstar + 1 # 1 star - low level higher than average in 34 candle
#print(symbolT,"1 star - low level higher than average in 34 candle")
if barHighPrice > HighLevelAverage36 :
BarHighLevelstar = BarHighLevelstar + 1
# candle 3
if barLowPrice3 < Low3LevelAverage36 :
BarLowLevelstar3 = BarLowLevelstar3 + 1 # 1 star - low level higher than average in 34 candle
#print(symbolT,"1 star - low level higher than average in 34 candle")
if barHighPrice3 > High3LevelAverage36 :
BarHighLevelstar3 = BarHighLevelstar3 + 1
#------------------------------
def TechnicalAnalysis () :
global symbolT,dfbars,dataProcessF1
dataProcessF1.drop(dataProcessF1.index , inplace=True)
barNumber3 = barNumber2 + 1
barNumber4 = barNumber3 + 1
barNumber5 = barNumber4 + 1
# A
if not data2.empty:
# Coin Candle Data
btcRow = data2.loc[data2['symbol'] == 'BTCUSDT']
tableTA = pd.concat([btcRow, data2.drop(btcRow.index)], axis=0).reset_index(drop=True)
for x in DelistCoTAFuture:
tableTA = tableTA[tableTA["symbol"].str.contains(x) == False]
#reverse data frame
#tableTA = tableTA.iloc[::-1]s
symbolTable = tableTA['symbol'].to_numpy()
#print("TASymbolTable",symbolTable)
btcControlBool = True
for symbolT in symbolTable :
global symbolT2
symbolT2 = str(symbolT[:-4]) + "/USDT"
bars = exchange.fetch_ohlcv(symbolT2, timeframe= tm, since = None, limit = candleCountLimit)
dfbars = pd.DataFrame(bars, columns=["timestamp", "open", "high", "low", "close", "volume"])
if len(dfbars.index) < candleCountLimit :
DelistCoTAFuture.append(symbolT)
if tm == "5m" or tm == "15m" or tm == "30m" :
DelistCoPDFuture.append(symbolT)
continue
global dfbarCloseAll,dfbarOpenAll,dfbarHighAll,dfbarLowAll
dfbarOpenAll = dfbars["open"]
dfbarHighAll = dfbars["high"]
dfbarLowAll = dfbars["low"]
dfbarCloseAll = dfbars["close"]
global barClosePrice0
# 1
barClosePrice0 = float(dfbarCloseAll[len(dfbars.index) - 1])
barClosePrice0 = format(float(barClosePrice0), '.8f')
global barOpenPrice,barHighPrice,barLowPrice,barClosePrice
# 2 3 4 5 6 candle
barOpenPrice = float(dfbarOpenAll[len(dfbars.index) - barNumber2])
barHighPrice = float(dfbarHighAll[len(dfbars.index) - barNumber2])
barLowPrice = float(dfbarLowAll[len(dfbars.index) - barNumber2])
barClosePrice = float(dfbarCloseAll[len(dfbars.index) - barNumber2])
global barOpenPrice3,barHighPrice3,barLowPrice3,barClosePrice3
barOpenPrice3 = float(dfbarOpenAll[len(dfbars.index) - barNumber3])
barHighPrice3 = float(dfbarHighAll[len(dfbars.index) - barNumber3])
barLowPrice3 = float(dfbarLowAll[len(dfbars.index) - barNumber3])
barClosePrice3 = float(dfbarCloseAll[len(dfbars.index) - barNumber3])
barOpenPrice4 = float(dfbarOpenAll[len(dfbars.index) - barNumber4])
barClosePrice4 = float(dfbarCloseAll[len(dfbars.index) - barNumber4])
barOpenPrice5 = float(dfbarOpenAll[len(dfbars.index) - barNumber5])
barClosePrice5 = float(dfbarCloseAll[len(dfbars.index) - barNumber5])
#General Values
global starCount,processPerPoz,processPerNeg,rangeStartValueForAverage,starCountToPrint,CandlePattern,Direction
mainAllBodyDif = 0.5
taleAllBodyDif = 0.5
negBarRealBodyWholeBodyRate = 0.5
DojiDifference = 0.05 # eksik düzenle yapisini
RateHeadHandleHammer = 2.2 # farklı formasyonlarda farklı değerler alabilir
rateNeedles_Body = 2
RateHeadHandleInverseHammer = 1.8
starCountToPrint = 3
rangeStartValueForAverage = barNumber3
mainbodyDownBodyRate = 1.5
SpinningUpDownRate = 1.5
global Average6CandleCount,Average12CandleCount,Average24CandleCount,Average36CandleCount,processAllPer
Average6CandleCount = 4
Average12CandleCount = 10
Average24CandleCount = 22
Average36CandleCount = 34
if (barHighPrice - barLowPrice == 0) or (barHighPrice3 - barLowPrice3 == 0): # because of zero division
#print(symbolT,"zerodivision")
continue
##########BtcAnalysis#################
global btcStarCountPoz,btcStarCountNeg,btcAnalysisPointsBullish,btcAnalysisPointsBearish,btcPrice
if symbolT == "BTCUSDT" and btcControlBool == True :
btcPrice = barClosePrice
btcStarCountPoz = 0
btcStarCountNeg = 0
btcAnalysisPointsBullish = 0
btcAnalysisPointsBearish = 0
CheckCandles()
Indicators ()
btcStarCountPoz = btcStarCountPoz + CheckCandlesAveragePozstar # bearish if > 2
btcStarCountNeg = btcStarCountNeg + CheckCandlesAverageNegstar # bullish if > 2
# 20 points
if btcStarCountPoz > 1 :
btcAnalysisPointsBearish = btcAnalysisPointsBearish + 10 # test et
elif btcStarCountPoz >= 1 :
btcAnalysisPointsBearish = btcAnalysisPointsBearish + 5
if btcStarCountNeg > 1 :
btcAnalysisPointsBullish = btcAnalysisPointsBullish + 10
elif btcStarCountNeg >= 1 :
btcAnalysisPointsBullish = btcAnalysisPointsBullish + 5
# btc indicator point
if indicatorPointsBearish >= 20 :
btcAnalysisPointsBearish = btcAnalysisPointsBearish + 10
elif indicatorPointsBearish >= 15 :
btcAnalysisPointsBearish = btcAnalysisPointsBearish + 5
if indicatorPointsBullish >= 20 :
btcAnalysisPointsBullish = btcAnalysisPointsBullish + 10
elif indicatorPointsBullish >= 15 :
btcAnalysisPointsBullish = btcAnalysisPointsBullish + 5
print("btcpozstar",btcStarCountPoz,"btcnegstar",btcStarCountNeg)
btcControlBool = False
# 1A. HAMMER AND DRAGONFLY DOJI (BULLISH) ##############################################################################################################
#Hammer Values
hammerstarCount = 0
# 1a hammer - pozitive (cekic)
if testBool == True and barClosePrice > barOpenPrice and (barOpenPrice - barLowPrice) > (RateHeadHandleHammer * (barClosePrice - barOpenPrice)) and mainbodyDownBodyRate * (barClosePrice - barOpenPrice) > (barHighPrice - barClosePrice) :
CheckCandles() # her formasyonda mi hesaplanmali yoksa bir kere tum coinler icin mi (hepsi) ?
CheckLowValueInCandles()
hammerstarCount = hammerstarCount + BarLowHighLevelstar + CheckLowValuestar + CheckCandlesAverageNegstar
# 1 star - pozitive hammer
hammerstarCount = hammerstarCount + 1
#print(symbolT," 1 star - pozitive hammer")
if (barClosePrice - barOpenPrice) / (barHighPrice - barLowPrice) > DojiDifference and hammerstarCount >= starCountToPrint :
Direction = "Bullish"
CandlePattern = "Hammer Poz"
starCount = hammerstarCount
Indicators()
processAllPer = indicatorPointsBullish + btcAnalysisPointsBullish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer)
elif hammerstarCount >= starCountToPrint :
Direction = "Bullish"
CandlePattern = "Dragonfly Doji Poz"
starCount = hammerstarCount
Indicators()
processAllPer = indicatorPointsBullish + btcAnalysisPointsBullish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer) # dragonfly - long legged ayrımını yap
# 1b hammer - negative (cekic)
elif testBool == True and barOpenPrice > barClosePrice and (barClosePrice - barLowPrice) > (RateHeadHandleHammer * (barOpenPrice - barClosePrice)) and mainbodyDownBodyRate * (barOpenPrice - barClosePrice) > (barHighPrice - barOpenPrice) :
CheckCandles()
CheckLowValueInCandles()
hammerstarCount = hammerstarCount + BarLowHighLevelstar + CheckLowValuestar + CheckCandlesAverageNegstar
if (barOpenPrice - barClosePrice) / (barHighPrice - barLowPrice) > DojiDifference and hammerstarCount >= starCountToPrint :
if closedCandlePatterns == False:
Direction = "Bullish"
CandlePattern = "Hammer Neg"
starCount = hammerstarCount
Indicators()
processAllPer = indicatorPointsBullish + btcAnalysisPointsBullish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer)
elif hammerstarCount >= starCountToPrint :
Direction = "Bullish"
CandlePattern = "Dragonfly Doji Neg"
starCount = hammerstarCount
Indicators()
processAllPer = indicatorPointsBullish + btcAnalysisPointsBullish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer) # dragonfly - long legged ayrımını yap
# 1B. SHOOTING STAR AND GROVESTONE DOJI (BEARISH) ##############################################################################################################################
#Shooting Star Values
ShootingStarstarCount = 0
# 1a shooting star - negative
if testBool == True and barOpenPrice > barClosePrice and (barHighPrice - barOpenPrice) > (RateHeadHandleHammer * (barOpenPrice - barClosePrice)) and mainbodyDownBodyRate * (barOpenPrice - barClosePrice) > (barClosePrice - barLowPrice) :
CheckCandles()
CheckLowValueInCandles()
ShootingStarstarCount = ShootingStarstarCount + CheckCandlesAveragePozstar + CheckHighValuestar + BarLowHighLevelstar
#Negative shooting star + 1 star
ShootingStarstarCount = ShootingStarstarCount + 1
if (barOpenPrice - barClosePrice) / (barHighPrice - barLowPrice) > DojiDifference and ShootingStarstarCount >= starCountToPrint:
Direction = "Bearish"
CandlePattern = "Shooting Star Neg"
starCount = ShootingStarstarCount
Indicators()
processAllPer = indicatorPointsBearish + btcAnalysisPointsBearish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer)
elif ShootingStarstarCount >= starCountToPrint :
Direction = "Bearish"
CandlePattern = "Gravestone Doji Star Neg"
starCount = ShootingStarstarCount
Indicators()
processAllPer = indicatorPointsBearish + btcAnalysisPointsBearish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer) # gravestone - long legged ayrımını yap
# 1b shooting star - positive
elif testBool == True and barClosePrice > barOpenPrice and (barHighPrice - barClosePrice) > (RateHeadHandleHammer * (barClosePrice - barOpenPrice)) and mainbodyDownBodyRate * (barClosePrice - barOpenPrice) > (barOpenPrice - barLowPrice) :
CheckCandles()
CheckLowValueInCandles()
ShootingStarstarCount = ShootingStarstarCount + CheckCandlesAveragePozstar + CheckHighValuestar + BarLowHighLevelstar
if (barClosePrice - barOpenPrice) / (barHighPrice - barLowPrice) > DojiDifference and ShootingStarstarCount >= starCountToPrint:
Direction = "Bearish"
CandlePattern = "Shooting Star Poz"
starCount = ShootingStarstarCount
Indicators()
processAllPer = indicatorPointsBearish + btcAnalysisPointsBearish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer)
elif ShootingStarstarCount >= starCountToPrint :
Direction = "Bearish"
CandlePattern = "Gravestone Doji Star Poz"
starCount = ShootingStarstarCount
Indicators()
processAllPer = indicatorPointsBearish + btcAnalysisPointsBearish + (starCount * 10)
sortLongInf()
print(symbolT,Direction,CandlePattern,starCount,processAllPer) # gravestone - long legged ayrımını yap
# 2A.INVERTED HAMMER (BULLISH) ##############################################################################################################################
#Inverted Hammer Values
inversehammerstarCount = 0
if closedCandlePatterns == False and testBool == True and barClosePrice > barOpenPrice and (barHighPrice - barClosePrice) > (RateHeadHandleInverseHammer * (barClosePrice - barOpenPrice)) and barClosePrice - barOpenPrice > barOpenPrice - barLowPrice and barOpenPrice3 > barClosePrice and barOpenPrice3 > barClosePrice3 and (barOpenPrice3 - barClosePrice3) / (barHighPrice3 - barLowPrice3) > negBarRealBodyWholeBodyRate and (barClosePrice - barOpenPrice) / (barHighPrice - barLowPrice) > DojiDifference :
CheckCandles()
inversehammerstarCount = inversehammerstarCount + CheckCandlesAverageNegstar
# 4 5 candle negative control
if barOpenPrice4 > barClosePrice4 and barOpenPrice5 > barClosePrice5:
inversehammerstarCount = inversehammerstarCount + 2
elif barOpenPrice4 > barClosePrice4 or barOpenPrice5 > barClosePrice5:
inversehammerstarCount = inversehammerstarCount + 1
# 2 yıldız daha eklenecek ( +1 eklenebilir)
# 1 star - condition is okay
inversehammerstarCount = inversehammerstarCount + 1
if inversehammerstarCount >= starCountToPrint :
Direction = "Bullish"
CandlePattern = "Inverted Hammer"
starCount = inversehammerstarCount
Indicators()
processAllPer = indicatorPointsBullish + btcAnalysisPointsBullish + (starCount * 10)
sortLongInf()