I didn't know who to buy on first day of week and sell on last day of week, so I coded to buy on Monday and Sell on Friday. Unfortunately, some weeks, Monday or Friday is a holiday. How can I improve my code ?
Instead of hard coding 1 and 5 you can detect the difference in dayofweek . If one bar change is negative it means that it is beginning of the week. The day before that is the end of the week.