This script is trying to perform well as shown in the chart drawing.

Worth to watch it for study purposes.
Supply and DemandSupport and ResistanceTrend Analysis

Disclaimer