Issues with Code of PCR sentiment indicator

Course Name: Trading using Options Sentiment Indicators, Section No: 3, Unit No: 12, Unit type: WaterMarkVideo

Hi team,

How profit is calculated on PCR based sentiment indicator seems to be flawed under if…elif block ? Can you please double check logic , it seems profit at some place is calculated otherway around then it should have been. Thanks so much. I am talking above profit calcualtion in code below.

if (UBB_cross and (not buy_flag) and flag ==1): #…places “BUY” oPCR crosses upper bollinger band to open a trade
flag = 0
buy_flag = True
sell_flag = False
transaction_start_price = future_cost #…price at which S&P 500 future bought when order is placed
order_details = [1,“Buy” , “UBB crossed” , “0” , “position taken”]

elif (LBB_cross and (not sell_flag) and flag ==1): #.......places "SELL" order if PCR crosses lower bollinger band to open a trade
	flag = 0
	sell_flag = True  
	buy_flag = False
	transaction_start_price = future_cost
	order_details = [-1,"Sell" , "LBB crossed" , "0" , "position taken"]

elif (mAvg_cross_up and flag==0 and (not buy_flag)) : #........places "BUY" order if PCR crosses mAvg from low to high to close a trade  
	flag = 1
	buy_flag = False 
	sell_flag = False
	pro = future_cost -transaction_start_price
	order_details = [1,"Buy" , "mAvg crossed" , "0" , "position closed"]
	
elif( LSL_cross and flag == 0 and (not buy_flag)):#......places "BUY" order if PCR crosses lower stoploss band to close a trade
	flag = 1
	buy_flag = False
	sell_flag = False
	pro = future_cost - transaction_start_price
	order_details = [1,"Buy" , "LSB crossed" , "stoploss executed" , "position closed"]
elif( (future_cost - transaction_start_price) > abs_SL and flag == 0 and (not buy_flag)):#......places "BUY " order if PCR crosses lower stoploss absolute value
	flag = 1
	buy_flag = False
	sell_flag = False
	pro = future_cost - transaction_start_price
	order_details = [1,"Buy" , "LSB crossed" , "stoploss executed abs" , "position closed"]		
			
elif (mAvg_cross_down and flag==0 and (not sell_flag)):#.....places "SELL" order if PCR crosses mAvg from high to low to close a trade
	flag = 1
	sell_flag = False
	buy_flag = False
	pro = -(Data['future'][i] - transaction_start_price)
	order_details = [-1,"Sell" , "mAvg crossed (h to l)" , "0" , "position closed"]
				
elif(USL_cross and flag==0 and (not sell_flag)):# ..places "SELL" order if PCR crosses upper stoploss band to close a trade
	flag = 1
	sell_flag = False
	buy_flag = False
	pro = -(Data['future'][i] - transaction_start_price)
	order_details = [-1,"Sell" , "USB crossed" , "stoploss executed" , "position closed"]

elif((-future_cost + transaction_start_price) > abs_SL and flag==0 and (not sell_flag)):# ..places "SELL" order if PCR crosses upper stoploss absolute value
	flag = 1
	sell_flag = False
	buy_flag = False
	pro = -(Data['future'][i] - transaction_start_price)
	order_details = [-1,"Sell" , "USB crossed" , "stoploss executed_abs" , "position closed"]

For Example:

Probably Profit should be calculated in mAvg_cross_down scenario by simply subtracting Entry Price from Exit Price. We were in buy position and expect to make profit when Price of Futures goes up and thats what we expect when PCR comes below mAVG. Not entirely sure why -ve sign is put in front of in code snippet below ‘pro = -(Data[‘future’][i] - transaction_start_price)’. Can you please advise ?

“elif (mAvg_cross_down and flag==0 and (not sell_flag)):#…places “SELL” order if PCR crosses mAvg from high to low to close a trade
flag = 1
sell_flag = False
buy_flag = False
pro = -(Data[‘future’][i] - transaction_start_price)
order_details = [-1,“Sell” , “mAvg crossed (h to l)” , “0” , “position closed”]”

Should not profit in above just be:
pro = (Data[‘future’][i] - transaction_start_price)

(and if that is so , can you please check entire code and advise }

Hi Rohan,

We are looking into this and will get back to you.

Thanks Akshay - any update on this , thanks?

Hi Rohan,

Thanks for pointing this out. It looks like the profit calculations are inverted. So basically the profit/loss should be calculated as:

profit/loss = (exit price - entry price) * (position)

We are working on making changes to the code and video accordingly. We will update you once both of them are updated.