\unprotect

\newcount\levelcounter

\levelcounter\zerocount

\def\????se{@@@@se}

\def\setupsection
  {\dosingleempty\dosetupsection}

\def\dosetupsection[#1]%
  {\iffirstargument
     \getparameters[\????se][\c!level=,#1]%
   \fi
   \processaction
     [\@@@@selevel]
     [   \v!part=>\levelcounter\minusone,
      \v!chapter=>\levelcounter\zerocount,
      \v!section=>\levelcounter\plusone,
      \v!default=>\levelcounter\zerocount,
      \v!unknown=>\levelcounter\zerocount]}

\def\startsection
  {\dosingleempty\dostartsection}

\def\dostartsection[#1]#2%
  {\begingroup
    \global\advance\levelcounter\plusone
    \ifcase\levelcounter\let\currentlevelsection\part
    \or\let\currentlevelsection\chapter
    \or\let\currentlevelsection\section
    \or\let\currentlevelsection\subsection
    \or\let\currentlevelsection\subsubsection
    \or\let\currentlevelsection\subsubsubsection
    \fi
    \currentlevelsection[#1]{#2}}

\def\stopsection
  {\global\advance\levelcounter\minusone
   \endgroup}

\protect

\starttext

\dorecurse
  {10}
  {\dorecurse{6}{\startsection{Ward}\input ward\endgraf}
   \dorecurse{6}{stopsection}}

\stoptext
