Reset figure numbering [closed]

I define the MyChapter as a newcounter for my chapters. I use the

\renewcommand{\thefigure}{\theMyChapter.\arabic{figure}}


for figure numbering. I works correctly up to chapter 3, but from chapter 4 it does not reset the figure numbers. For example if I have 3 figure in chapter 3, the first figure of chapter 4 is number 4.4 and the second one is numbered 4.5 (it means it does not reset). What should I do?

Edited: The document seems like this:

\documentclass[a4paper, 11pt]{book}
\usepackage[toc,page]{appendix}
\usepackage{pstricks}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathcomp}
\usepackage{mathtools}
\usepackage{commath}
\usepackage{physics}
\usepackage{textcomp}
\usepackage{enumitem}
\usepackage{xepersian}

%%%%%%%%% Chapter Counter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{MyChapter}
\renewcommand{\theequation}{\theMyChapter.\arabic{equation}}
\numberwithin{figure}{MyChapter}
\def\MyChapterNumbering{\ifcase\theMyChapter صفرم\or یکم\or دوم\orدهم \fi }
\def\MyChapterNumberingg{\ifcase\theMyChapter  یکم\or دوم\or سوم\or چهارم\or دهم \fi }
\long\def\MyChapter#1{\setcounter{equation}{0}
\newpage
\vglue5cm
{\topicfont\small\noindent فصل \MyChapterNumberingg \\ \vglue1cm \noindent\large #1}
\vglue2cm
\noindent{}
\pagestyle{fancy}

\thispagestyle{empty}
\stepcounter{MyChapter}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\captionsetup{labelsep=period}
\pagestyle{empty}
\DefaultMathsDigits

\begin{document}
\tableofcontents
\pagenumbering{arabic}

\MyChapter{test1}

\MyChapter{test2}

\end{document}


closed as off-topic by Mensch, user156344, Raaja, Stefan Pinnow, SebastianoApr 4 at 8:07

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Try \numberwithin{figure}{chapter} – user121799 Aug 4 '18 at 14:58
• With an uptodate TeX Distribution you can use \counterwithin{figure}{chapter} without an additional package. With older distributions you have to load package chngcntr. Macro \numberwithin is provided by package amsmath. – esdd Aug 4 '18 at 15:08
• To answer this, we would need a complete but minimal document, starting with \documentclass and ending with \end{document}. How would @esdd know you're loading amsmath? – user121799 Aug 4 '18 at 15:50
• Also we do not know how the counter Mychapter is defined and what the purpose of its definition is. It could also be that you want to use \numberwithin{figure}{MyChapter} ... – esdd Aug 4 '18 at 16:03
• I'm voting to close this question as off-topic because it is solved in comments. – Mensch Apr 4 at 5:40