fixing issues in trading pattern code with detailed explanations