Sample 1
Sample 1
Sample 1
import numpy as np
import pandas_ta as ta
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from datetime import datetime
from backtesting import Strategy
from backtesting import Backtest
df=pd.read_csv("EURUSD_Candlestick_5_M_ASK_30.08.2022,.30.09.2022.csv")
df
df['VWAPSignal'] = VWAPsignal
def TotalSignal(l):
if (df.VWAPSignal[l]==2
and df.Close[l]<=df['BBL_14_2.0'][l]
and df.RSI[l]<45):
return 2
if (df.VWAPSignal[l]==1
and df.Close[l]>=df['BBU_14_2.0'][l]
and df.RSI[l]>55):
return 1
return 0
TotSignal = [0]*len(df)
for row in range(backcandles, len(df)): #careful backcandles used previous cell
TotSignal[row] = TotalSignal(row)
df['TotalSignal'] = TotSignal
df[df.TotalSignal!=0].count()
def pointposbreak(x):
if x['TotalSignal']==1:
return x['High']+1e-4
elif x['TotalSignal']==2:
return x['Low']-1e-4
else:
return np.nan
class MyStrat(Strategy):
initsize = 0.99
mysize = initsize
def init(self):
super().init()
self.signal1 = self.I(SIGNAL)
def next(self):
super().next()
slatr = 1.2*self.data.ATR[-1]
TPSLRatio = 1.5
if len(self.trades)>0:
if self.trades[-1].is_long and self.data.RSI[-1]>=90:
self.trades[-1].close()
elif self.trades[-1].is_short and self.data.RSI[-1]<=10:
self.trades[-1].close()