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.
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.
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:
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.