-- coding: utf-8 -- """EURUSDSRWITHCANDLESBacktesting.ipynb Automatically generated by…
- User
-- coding: utf-8 --
"""EURUSD_SR_WITH_CANDLES_Backtesting.ipynb
Automatically generated by Colab.
Original file is located at https://colab.research.google.com/drive/1g-syOO2ong6jScRaLr7xxThR1PvJVZxo
Resistance/Support AND Candles Patterns
"""
import pandas as pd df = pd.read_csv("EURUSD_Candlestick_1_D_ASK_05.05.2003-30.06.2021.csv")
#Check if NA values are in data df=df[df['volume']!=0] df.reset_index(drop=True, inplace=True) df.isna().sum() df.tail()
"""# Support and Resistance FUNCTIONS"""
def support(df1, l, n1, n2): #n1 n2 before and after candle l for i in range(l-n1+1, l+1): if(df1.low[i]>df1.low[i-1]): return 0 for i in range(l+1,l+n2+1): if(df1.low[i]<df1.low[i-1]): return 0 return 1
def resistance(df1, l, n1, n2): #n1 n2 before and after candle l for i in range(l-n1+1, l+1): if(df1.high[i]<df1.high[i-1]): return 0 for i in range(l+1,l+n2+1): if(df1.high[i]>df1.high[i-1]): return 0 return 1
length = len(df) high = list(df['high']) low = list(df['low']) close = list(df['close']) open = list(df['open']) bodydiff = [0] * length
highdiff = [0] * length lowdiff = [0] * length ratio1 = [0] * length ratio2 = [0] * length
def isEngulfing(l): row=l bodydiff[row] = abs(open[row]-close[row]) if bodydiff[row]<0.000001: bodydiff[row]=0.000001
bodydiffmin = 0.002 if (bodydiff[row]>bodydiffmin and bodydiff[row-1]>bodydiffmin and open[row-1]<close[row-1] and open[row]>close[row] and (open[row]-close[row-1])>=-0e-5 and close[row]<open[row-1]): #+0e-5 -5e-5 return 1 elif(bodydiff[row]>bodydiffmin and bodydiff[row-1]>bodydiffmin and open[row-1]>close[row-1] and open[row]<close[row] and (open[row]-close[row-1])<=+0e-5 and close[row]>open[row-1]):#-0e-5 +5e-5 return 2 else: return 0def isStar(l): bodydiffmin = 0.0020 row=l highdiff[row] = high[row]-max(open[row],close[row]) lowdiff[row] = min(open[row],close[row])-low[row] bodydiff[row] = abs(open[row]-close[row]) if bodydiff[row]<0.000001: bodydiff[row]=0.000001 ratio1[row] = highdiff[row]/bodydiff[row] ratio2[row] = lowdiff[row]/bodydiff[row]
if (ratio1[row]>1 and lowdiff[row]<0.2*highdiff[row] and bodydiff[row]>bodydiffmin):# and open[row]>close[row]): return 1 elif (ratio2[row]>1 and highdiff[row]<0.2*lowdiff[row] and bodydiff[row]>bodydiffmin):# and open[row]<close[row]): return 2 else: return 0def closeResistance(l,levels,lim): if len(levels)==0: return 0 c1 = abs(df.high[l]-min(levels, key=lambda x:abs(x-df.high[l])))<=lim c2 = abs(max(df.open[l],df.close[l])-min(levels, key=lambda x:abs(x-df.high[l])))<=lim c3 = min(df.open[l],df.close[l])<min(levels, key=lambda x:abs(x-df.high[l])) c4 = df.low[l]<min(levels, key=lambda x:abs(x-df.high[l])) if( (c1 or c2) and c3 and c4 ): return 1 else: return 0
- Assistant
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.