An indole derivative having the formula wherein a) Y1 is N, which is bound to Z, Z and Y2 are selected from CH2, CO, CS, SO and SO2; provided that at least one of Z and Y2 is CH2; Y3is O, S or CHR7and Y4is O, S or CHR8, provided that only one of Y3 and Y4 is O or S; b) Y2 is N, which is bound to Z, Z and Y1 are selected from CH2, CO, CS, SO and SO2; provided that at least one of Z and Y1 is CH2; Y3is CHR7 and Y4is O, S or CHR8; c) Y2 is N, which is bound to Z, Z and Y3 are selected from CH2, CO, CS, SO and SO2 provided that at least one of Z and Y3 is CH2; Y1 is CHR6 and Y4 is O, S or CHR8; W is a bond, O, S, CO, CS, SO or SO2; n is 0-5, m is 0-5 and n+m is 1-6; provided that when W is O or S, then n≧2 and m≧1; when W is CO, CS, SO or SO2, then n≧1 and m≧1; X is C, CH or N, provided that when X is C, the dotted line indicates a bond, and when X is N or CH, the dotted line indicates no bond; one of R1, R2, R3 and R4 forms a bond to X and the others of R1, R2, R3, R4 and R5 and R9-R12 are independently selected from hydrogen, halogen, cyano, nitro, amino, hydroxy, C1-6-alkyl-amino, di-( C1-6-alkyl )-amino, C1-6-alkyl, C2-6-alkenyl, C2-6-alkynyl, C1-6 alkoxy, C1-6-alkylthio, C1-6-alkyl substituted with hydroxy or thiol, C3-8-cycloalkyl, C3-8-cycloalkyl-C1-6-alkyl, acyl, thioacyl, trifluoromethyl, trifluoromethylsulfonyl or C1-6 alkylsulfonyl; R is hydrogen, C1-6-alkyl, C2-6-alkenyl, C2-6-alkynyl, C1-6-alkyl substituted with hydroxy or thiol, C3-8-cycloalkyl, C3-8-cycloalkyl-C1-6-alkyl, acyl, thioacyl, trifluoromethylsulfonyl and C1-6 alkylsulfonyl; or pharmaceutically acceptable salts thereof. The compounds of the invention are potent dopamine D4 ligands.