I wrote this in Python, Kindly let me know if this is useful. I took a cumulative sum of multiple buy and sell and compare it with global max and min stock value

def max_profit(input,fee):
min1 = 0
max1 = -1
local_val = 0
print('$$$$$$$$$$$$$$$----',input)
for i in range(1,len(input)):
print('Processing...', input[i])
if (input[i] > input[i-1]):
local_val = local_val + (input[i] - input[i-1] - fee)
print('Trade done:{}, buy:{}, sell:{}'.format( local_val, input[i-1],input[i]))
min1 = min(input[:i+1])
if input[:i+1].index(min1) < input[:i+1].index(max(input[:i+1])):
max1 = max(input[:i+1])
global_val = max1 - min1 - fee
print('Min:{}, max:{}, prof:{}'.format(min1,max1,global_val))
if global_val > local_val:
local_val = global_val
print('Global value >Local value: ',local_val)
if max([local_val, global_val]) > 0:
print('################################### Max profit:',max([local_val, global_val]) )
else:
print('No profit trade can be done!!!!!!!!!!!!!!!!!!')
max_profit([1, 3, 2, 8, 4, 9],2)
max_profit([1, 3, 7, 5, 10, 3],3)
max_profit([9,8,7,1,2],3)
max_profit([20,10,30,50,10,9,8],2)