For Short

import datetime

trade=0
Trade= pd.DataFrame(columns=['Trade_Date'])
for i in range(len(df_options)):
if (trade==0) & (df_options['Time'][i]>=datetime.datetime.strptime('10:00:00', '%H:%M:%S').time()) & (df_options['Time'][i]<=datetime.datetime.strptime('10:05:00', '%H:%M:%S').time()):
Entry_Price=df_options['Open'][i]
Entry_Time=df_options['Time'][i]
Entry_date=df_options['date'][i]
sl=Entry_Price*1.7
trade=1
continue
if (trade==1):
if (Entry_date==df_options['date'][i]) & (df_options['Time'][i]>=datetime.datetime.strptime('15:15:00', '%H:%M:%S').time()):
Exit_Price=df_options['Open'][i]…

Complete Python Code for Super Trend:

def TrueRange(data):
data = data.copy()
data["TR"] = np.nan
for i in range(1,len(data)):
h = data.loc[i,"high"]
l = data.loc[i,"low"]
pc = data.loc[i-1,"close"]
x = h-l
y = abs(h-pc)
z = abs(l-pc)
TR =…

Donchian Channel(DC) and Super Trend

About DC — https://en.wikipedia.org/wiki/Donchian_channel

About Super Trend — https://investobull.com/what-is-super-trend-indicator-and-how-to-use-it/

Here I am going to explain DC-super trend back testing with python.

Donchian Channel(DC) formula:

upper channel = highest high of last N-periods

lower channel = lowest low of last N-periods

middle channel =( (upper channel + lower channel)/2)

python code:

#donchan channel 20candles period
N = 20
df['upper_channel'] = np.nan
df['lower_channel'] = np.nan
df['middle_channel'] = np.nan
df['upper_channel'] = df['High'].rolling(N).max().shift(N-20)
df['lower_channel'] = df['Low'].rolling(N).min().shift(N-20)
df['middle_channel'] = ((df['upper_channel']+df['lower_channel'])/2)

super trend python code:

df = ATR_df.copy()#Calculation of SuperTrend
df['Upper Basic']=(df['High']+df['Low'])/2+(f*df['atr'])
df['Lower Basic']=(df['High']+df['Low'])/2-(f*df['atr'])
df['Upper Band']=df['Upper Basic']
df['Lower Band']=df['Lower Basic']
for i in range(n,len(df)):
if df['Close'][i-1]<=df['Upper Band'][i-1]…

vamsi krishna

I'm a Data Science enthusiast who loves to play with machine learning and deep learning.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store