Counting Bars from Short

For Intraday, I would like to Short when Signal crosses MACD and Cover at the 4th bar from Short. Can any of you advise me to do the coding for counting the bars?

To exit after N-bars from entry it is recommended to use appropriate function ApplyStop.

Open Formula editor and in Code snippets window go to folder Stops, open it and double click N-bar stop.
Modifiy bars = 10; to bars = 4;


Write code in similar fashion as to be seen in picture above.
Cover has to be set to zero if exiting only at stop.

@av.ragavan, check also this previous answer from @Tomasz.

Thanks it is working. If I check Code snippets, it is blank as below:


Am I missing something here?

You apparently have deleted default code snippets XML file from Amibroker installation folder. Or some useless antivirus software has done damage again.

So close AmiBroker and via AmiBroker setup file do an upgrade installation as to be seen in 2nd picture of below post

Then default snippets XML file should be back in place and those default snippets being visible in formula editor's code snippets window.

Thanks for your guidance. I am getting below error while upgrading, please help me out in fixing this issue: