[Help] Specify max number of contracts in backtest

#11
If I am reading it correctly you always want to trade 1 unit of Nifty throughout the history of backtesting, so that you could collect the total points won/loss ?
(below is the solution, but just let me warn you, winning 50 points at Nifty = 3000 is lot different than at Nifty = 6000. (telling you by personal experience)

(whether Nifty was 2000 or 6000, you want to trade only 1 unit of nifty (and not 1 lot which is 50 units).

If so, then that is very simple

SetPositionSize( 1, spsShares );
//this will always trade 1 unit irrespective of other details (just make sure atleast the initial deposit is greater

to trade this

let me know if I have not understood your requirement, if it is not a big trouble after posting your query, if

you can buzz me by PM, then it will catch my attention so that you don't have to wait too long for the reply.
 

Rajvir

Active Member
#12
Hello Hardit and IamAditya, Hello once again. I need your help. As the hardit asked in previous post, I need exactly the same condition in my afl. How to limit the maximum number of Lots in the backtesting AFL. For example Im backtesting a system, I started with 1 lot, but as the profit grows, the number of Lots are being increased, and then finally it starts to trade 500 Lots :clap: :clapping: :D

Now to trade 500 Lots is unrealistic. So I want to limit the number of Lots to 50 only, even when there is enough margin to trade 500 Lots. Please tell me how to do it ASAP. Thanks alot
 
#13
Use the function Max.
for e.g if x contains the value of position size being traded then

x = max(x,100); //if 100 is the maximum you want to trade.

//then you can use this x with either PositionSize or SetPositionSize()
 

Rajvir

Active Member
#14
Sorry bro but I didnt get it. Can you please write the exactly required AFL. I want to start with trading 1 lot and then limit the number of Lots to 50. Please write exactly required condition so that I could copy paste that condition and other readers may also take benefit of it just by editing 50 with their prefered quantity. Thanks once again
 

mcxinvest

Well-Known Member
#15
Hello
I am using AMibroker 5.2. If you also using the same, you can do is, go to
Symbol tab> information>contract specification> round lot size to 50 and set the margin deposit (if you want).
I think this should sort the purpose, as in this case you dont have to change the afl , if you testing the same system on other commodity/equity.
 

iamaaditya

Active Member
#16
Sorry bro but I didnt get it. Can you please write the exactly required AFL. I want to start with trading 1 lot and then limit the number of Lots to 50. Please write exactly required condition so that I could copy paste that condition and other readers may also take benefit of it just by editing 50 with their prefered quantity. Thanks once again
You want to start with 1 lot irrespective of account size ?
Also, is there Lot Size there ?

Also what % of the Account (Equity) do you want to trade ?
By default Amibroker assumes that it is 100%.

So say if you have 1,00,000 in Account (setmargin()), and you have put the lot size as 50 (assuming it is Nifty), then the no. of contracts it trades is
1,00,000/(price*50) (this is reduced to lowest integer).


anyways, it seems you want the working code.

Going by initial request, i am assuming you just want to limit the Max Number of Contracts (i will consider it as Units traded (since you haven't specified lot size or may be you have already factored that in)

Just put this one line, and it will never trade more than 500 contracts.

Positionsize = max(equity(),500);

HTH

Also kindly request you to go thru' AB helpfile on Position Size, Portfolio-level backtesting, et cetera.
 

Rajvir

Active Member
#17
Let me explain again pls

Initial equity = 100000

Lot Size = 50

Initial price = 6300

Margin = 31%

So if I have 1 lakh in account and Nifty price is 6300 , I will be able to trade 1 nifty lot only. Now as the profit grows , after 3-4 years it starts to trade 400-500 Lots. But I want that maximum number of lots should never exceed 50 . Even when I have 1 billion dollar in my accnt, it should trade at most 50 lots only. Thats my point. So what exactly shall I write in the start of my AFL , as the above given condition is not working for me again.
 

Similar threads