I'm making a special tick command. Without *, the tick shows on the left side. With *, it should appear on the right side. The * (or lack of) should set a few macros to change the behaviour of the tick. What is happening though, is that all ticks are appearing on the right side. (If the most recent ytick call does not have a *, they will appear on the left. I know this problem has to do with expansion. I think what I need to do is completely expand each ytick call.
\documentclass{article}
\RequirePackage{tikz}
\usetikzlibrary{calc}
\RequirePackage{pgfplots}
\RequirePackage{pgffor}
\pgfplotsset{compat=newest}
\newcommand{\ticksign}{-}
\newcommand{\tickside}{0}
\newcommand{\tickanchor}{east}
\newcommand{\ticklength}{2pt}
\NewDocumentCommand{\ytick}{ s m O{#2} }{%
\IfBooleanTF{#1}{
\gdef\ticksign{}
\gdef\tickside{1}
\gdef\tickanchor{west}
}{
\gdef\ticksign{-}
\gdef\tickside{0}
\gdef\tickanchor{east}
}
\coordinate (tick) at ({rel axis cs: \tickside , 0} |- {axis cs: 0, #2}) ;
\draw[gray] (tick) -- + (\ticksign \ticklength , 0pt);
\node[anchor=\tickanchor ] at ($ (tick) + (\ticksign \ticklength , 0pt) $) {#3} ;
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[hide axis,clip=false]
\addplot table[header=false,x expr=\coordindex, y index=0] {
1
2
3
2
1
};
\ytick{1}[one] % should be on left side
\ytick{3}[three] % should be on left side
\ytick*{2}[two]
\end{axis}
\end{tikzpicture}
\end{document}


