How to retrive the number of contract from SetPositionSize in Futures Mode?

I would like to retrieve the number of contracts in the exploration calculated using SetPositionSize. For instance, in example below PositionSize returns the % of equity, -10, not 6, the number of contracts.

RoundLotSize=1;
PointValue=1000;
MarginDeposit=1440;
SetOption( "InitialEquity", 100000);
SetOption("FuturesMode",True);
SetOption("AccountMargin",100);
SetPositionSize(10,spsPercentOfEquity);

Filter=1;
AddColumn(PositionSize,"Pos");

it returns -10 not the 6 contracts as expected. What is the array that stores the number of contracts?

Many thanks,

P

The number of contracts purchased will change with your equity. Equity is calculated during the back test, not during an exploration. Therefore, during an exploration all you will see is the Position Size value that you set, i.e. 10% of equity, or -10 (see the SetPostionSize() documentation for an explanation of the encoding scheme).

Yes, that's true, the number of contracts is a function of the current equity and hence it is dynamic. Exploration was just an example, my goal is to set the number of contracts in the auto trading/IB controller based on the current account equity.

In that case, your first decision is which equity value you are going to use for position sizing: your actual account equity from IB (which AmiBroker will not know about), or the equity in AmiBroker (which may not match IB).

If you are going to use IB's equity, then you will need to do your own calculation of the number of shares/contracts to use. If you use AmiBroker's equity, then you will need to run a back test if you want AmiBroker to calculate the contracts for you. If you're using an exploration or a chart to trigger the IB Controller, then you're back to calculating the number of contracts yourself.

1 Like

Thank you for reply. It is now clear how to proceed. I really appreciate that.

Best,

P

Related to this topic, I have a question about the SetPositionSize() function working with futures:
When the second parameter of the function is spsValue as I show:

SetPositionSize( size,  spsValue )

What parameter "size" should I indicate to buy a future for example?

I mean, if we trade the MIniSP500 future, where one point is 50 USD, to buy a future we should indicate:

size = market price of the MIniSP500 * 50

which assuming that the MiniSP^500 trades at 3000USD would be:

size = 3000 points * 50 USD/point = 150.000 USD

Thanks in advance

You should set contract specifications in information window of symbol.

EXAMPLE!
22

Those settings can be set by code also.

// EXAMPLE!
RoundLotSize = 1;
MarginDeposit = 3000;// 3000 is just example value! Set by Exchange
TickSize = 0.25;
PointValue = 50;

And you enable Futures Mode and set to trade 1 contract (spsShares refers to number of Shares and Contracts).

SetOption("FuturesMode", True);
SetPositionSize(1, spsShares);

Anyway don't forget to read here.

2 Likes

Thank you for your prompt response.
I understand perfectly what you indicate... in fact everything tuned as you tell me.
I also understand the use of setpositionsize for the case of number of contracts (spsShares)....
The question I ask is to really understand how the case of spsValue works with futures, because based on it, I can determine "size" in the function to assume a certain risk....
Then I need to be clear what the function understands by "size" when I work with futures for this method in this case, because the futures do not mark the real market value, if not you have to make the corresponding operation depending on the leverage to determine the real value of the operation and if this is the one that understands spsValue

I mean, in the case of spsValue with futures (Mini today 3000 point):

size =  3000 point x 50 USD/points = 150.000 

Would it buy one contract?

In any case, of course I can always use the spsShares option instead of the spsValue option.

Thanks again!!!

spsValue (position value) in futures mode is Margin x Number of contracts

First using spsShares and 1 contract to trade
23


Then using spsValue and value of 3000.
24

if you set spsValue to e.g. 5000 you can still trade just 1 contract because of MarginDeposit being 3000 in the example.

24

2 Likes

Now I got it the idea!!
Thank you very much!!!

By the way, I loved your article to understand the settings for working in forex.

1 Like