@ehsanarab
This block means a different loop, see picture (framed in red), try it like this, but I haven't tested the code because I only use MQL5. Since you are using CID_X for counting, you can use it to force a stop if stop means a new start, otherwise you first have to think about how you want to restart after a stop.
Another note: You must never use the same name for a constant and a variable (loop_counter)!!!
12205855-6d8b-4f26-8113-8633003f7ba1-image.png
https://fxdreema.com/shared/yupIHbEA