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.
SetOption( "InitialEquity", 100000);
it returns -10 not the 6 contracts as expected. What is the array that stores the number of contracts?
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.
Thank you for reply. It is now clear how to proceed. I really appreciate that.
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.
Those settings can be set by code also.
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).
Anyway don't forget to read here.
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.
spsValue (position value) in futures mode is
Margin x Number of contracts
spsShares and 1 contract to trade
spsValue and value of 3000.
if you set
spsValue to e.g.
5000 you can still trade just 1 contract because of
3000 in the example.
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.