The system is not new, of course, and that is not the point. I could not manage to implement something properly in order to test it properly. Also, I really needed this feature in other ATS as well. (in the current form, it can help only those who have EXTRA money in the truest sense of the word).
To be more specific, I could not implement the position reversal. The current state of the program implements something like:
SHORT POSITION 1st candle: close price is above MA (buy signal) 2nd candle: closure of the short position at the open price of the new candle (this is when the long position must be opened) 3rd candle: (this is where it goes wrong) the long position is opened at the open price of this candle (and not the 2nd candle).
This process is illustrated in the image (description of the situation with "BUY", the same with the "SELL", of course).
I would be glad if the more advanced minds than mine contributed to solving this task. If possible, please fix the attached code. Of course, I would be grateful for simple tips as well. (Although I am not sure if I will be able to convert simple tips into code - too little experience).