A method for controlling an electrical converter, the electrical converter comprising a plurality of semiconductor switches, wherein the electrical converter is adapted for generating a two-level or multi-level output voltage from an input voltage by switching the plurality of semiconductor switches; the method comprising the steps of: receiving a reference electrical quantity ( i S *) and an actual electrical quantity ( i S); determining a sequence of future electrical quantities of the electrical converter from the actual electrical quantity, wherein the sequence of future electrical quantities starts at an actual time step and is determined up to a horizon of time steps; determining a maximal cost value based on the sequence of future electrical quantities; iteratively determining an optimal switching sequence for the electrical converter, wherein a switching sequence comprises a sequence of future switching states for the semiconductor switches of the electrical converter, wherein the sequence of future switching states, which is iteratively determined, starts at the actual time step and is determined up to the horizon of time steps; and selecting the first switching state of the optimal switching sequence as a next switching state ( u) to be applied to the semiconductor switches of the electrical converter; wherein the optimal switching sequence is iteratively determined by: extending a switching sequence by appending a possible switching state to the switching sequence; determining a cost value for the extended switching sequence with a cost function based on the sequence of future electrical quantities, wherein the cost function is based on a norm of a matrix equation with a triangular matrix, which is multiplied with the extended switching sequence; and discarding the extended switching sequence, when the cost value is higher than the maximal cost value. receiving a reference electrical quantity ( i S *) and an actual electrical quantity ( i S); determining a sequence of future electrical quantities of the electrical converter from the actual electrical quantity, wherein the sequence of future electrical quantities starts at an actual time step and is determined up to a horizon of time steps; determining a maximal cost value based on the sequence of future electrical quantities; iteratively determining an optimal switching sequence for the electrical converter, wherein a switching sequence comprises a sequence of future switching states for the semiconductor switches of the electrical converter, wherein the sequence of future switching states, which is iteratively determined, starts at the actual time step and is determined up to the horizon of time steps; and selecting the first switching state of the optimal switching sequence as a next switching state ( u) to be applied to the semiconductor switches of the electrical converter; wherein the optimal switching sequence is iteratively determined by: extending a switching sequence by appending a possible switching state to the switching sequence; determining a cost value for the extended switching sequence with a cost function based on the sequence of future electrical quantities, wherein the cost function is based on a norm of a matrix equation with a triangular matrix, which is multiplied with the extended switching sequence; and discarding the extended switching sequence, when the cost value is higher than the maximal cost value. extending a switching sequence by appending a possible switching state to the switching sequence; determining a cost value for the extended switching sequence with a cost function based on the sequence of future electrical quantities, wherein the cost function is based on a norm of a matrix equation with a triangular matrix, which is multiplied with the extended switching sequence; and discarding the extended switching sequence, when the cost value is higher than the maximal cost value.