# How stop loss in amibroker backtest works?

#### mutualguru

##### Active Member
Can any amibroker programming gurus can help me with clearing this concept. I want to add stop loss function to my backtest script and I found this fixed stop loss code.

Code:
``````amount = 2; // 2% loss
ApplyStop( stopTypeLoss, stopModePercent, amount, True );``````
my question is how amibroker determines a stop loss while backtesting? whether it takes daily change in percentage for stop loss or after completion of a trade

example

Code:
``````Days | Daily gain/loss percentage
1	1.41
2	-1.34
3	-2.52
4	3.8
5	2.95
6	-0.9
7	1.62
8	-3.86
9	1.23
10	4.82
11	-4.85
12	2.39
13	-0.77
14	-2.56
15	-5.39
16	-3.44
17	4.47``````
First column is the day and second column is the gain/loss percentage. these days are the trading days we kept the stock. After 17 days the above stock gave a total loss of -2.94. in the above data where will amibroker will apply stop. If i am correct on these days 3,8,11,14,16 trade will be exited using my stop loss condition or it will exit when the

Last edited:

#### hedron

##### Member
You might try fooling with the exitatstop parameter. Applystop wasn't respecting my stop until I switched it to 1, but another value might be better for your strategy.

#### mastermind007

##### Well-Known Member
Can any amibroker programming gurus can help me with clearing this concept. I want to add stop loss function to my backtest script and I found this fixed stop loss code.

Code:
``````amount = 2; // 2% loss
ApplyStop( stopTypeLoss, stopModePercent, amount, True );``````
my question is how amibroker determines a stop loss while backtesting? whether it takes daily change in percentage for stop loss or after completion of a trade

example

Code:
``````Days | Daily gain/loss percentage
1	1.41
2	-1.34
3	-2.52
4	3.8
5	2.95
6	-0.9
7	1.62
8	-3.86
9	1.23
10	4.82
11	-4.85
12	2.39
13	-0.77
14	-2.56
15	-5.39
16	-3.44
17	4.47``````
First column is the day and second column is the gain/loss percentage. these days are the trading days we kept the stock. After 17 days the above stock gave a total loss of -2.94. in the above data where will amibroker will apply stop. If i am correct on these days 3,8,11,14,16 trade will be exited using my stop loss condition or it will exit when the
Study the example code again carefully. There are few other things mentioned in example that you seem to have missed.