Code for my own strategy trying

Trying to make code for strategy…but little confusing with bar numbering

code :

for stock_name in watchlist:

chart = tsl.get_intraday_data(stock_name, 'NSE',5)
chart['SMA'] = talib.SMA(chart['close'], timeperiod=20) #pandas

CL = chart['close']
OP = chart['open']
HG = chart['high']
LW = chart ['low']

Entry = (CL > chart.iloc[-2]) and (chart.iloc[-3]<chart.iloc[-2])
Stop_Loss = chart.iloc[-2]
Target = (CL - LW)*3

print (Entry)
print (traget)
print (Stop_Loss)

pdb.set_trace()

uptrend = (CL > chart['close']) and (LW < chart['close'])

downtrend = (CL < chart['close']) and (LW > chart['close'])

PLS HELP @Tradehull_Imran Sir

iam assuming ur CL representing lastest candle

CL = chart['close']

here CL is series of close values of all candles


               CL > chart.iloc[-2]

here comparsion is between a sereis and a single value ( doesnt work)

       ` chart.iloc[-2]`

gives u enttire row (open , hi . lo , close) ,

i tjhink u r lookog for below specific candles
cc = chart.iloc[-1] #current candle
pc = chart.iloc[-2] #previous candle

u can access o , h . l , c of specific candles
cc[‘close’] or cc[‘open’] …

or describe ur strategy , will try to fixing ur code

1 Like