Unfortunately it's not working and I don`t know why. Can somebody tell me which are my options to code a system which buys/sells on the open of next bar?
You haven't said WHY you want to use a different approach rather than your first example, which works. Your second example doesn't work as you expect because you only assigned new Buy and Sell prices... you didn't do anything to change when the entry/exit occurs relative to the signal.
Here's one possible alternative:
SetTradeDelays(0,0,0 0);
BuySig = Cross(MA(C,20), MA(C,50));
SellSig = Cross(MA(C,50),MA(C,20));
// Enter/Exit one bar after the signal occurs
Buy = Ref(BuySig,-1);
Sell = Ref(SellSig,-1);
BuyPrice = Open;
SellPrice = Open;
Thank you very much for your answer. I haven't said why I wanted to use a different approach because I was just experimenting and exploring how I can code the same logic in a different way.