SetShareSize does not accept double values
Author: aykuts
Creation Date: 4/29/2014 2:57 AM
profile picture

aykuts

#1
Hi,

The following code works just fine:
(i.e. :
- opens trades at designated lot sizes,
- displays opened/closed marks on the chart,
- calculates respective performance statistics etc.)

CODE:
Please log in to see this code.


However, and interestingly, the following code, although a replica of the one I presented above, doesnt function properly
(i.e.:
- does not open trades at designated amounts,
- does not show opened/closed triangular marks on the chart,
- does not trade thus does not produce any sort of performance metrics
- etc.)

CODE:
Please log in to see this code.

***

As you might have followed, the only difference between these codes is that, one gets one number as lotsize (i.e. 100 for Y and 150 for X), whereas for the latter case, respective lotsizes are first defined (as double),, then calculated and assigned, and then used as the share size for respective positions.


What is the problem here? Why do my code function properly when I use "100" as my SetShareSize input whereas it does not work when I use one "double lotSizeY"?

Other remarks:
1- when calculated, lotSizeY is something like 375968.992248062 and lotSizeX is something like 383864.341085271. Maybe the precision, or, some other pecularity I cannot understand, might have resulted in this misbehaviour of the SetShareSize method;

2- Obviously, the position size is set as "Override in script";

3- When I choose another position sizing (say, "fixed share size set as 100"), the code works fine;

4- The overall flow of the code works fine when I use these test 100 and 150 share sizes for Y and X respectively. So, I observe that my problem is contained at the SetShareSize method.

Thanks in advance for your consideration and the time,

Best regards,



profile picture

Eugene

#2
It's not a problem of the partial shares because SetShareSize is designed to accept double values. If it does not trade, most likely there is not enough capital. Check "Trades not included due to insufficient capital", and if it's greater than 0, the lotSizeY is producing values that exceed your equity.

P.S. "Open[bar + 1]" will produce an Index Out Of Range exception on the last bar, so adjust by either using GetSessionOpen (if supported by your data provider) or modifying the formula accordingly (e.g. by taking the Close[bar]).
profile picture

aykuts

#3
I sorted the issue out; it is simply the level of Starting Capital; I could not understand that the Starting Capital remains effective and might act as one limit while working with WS Override option. Rising the level of Starting Capital to sufficiently large amount solved my problem.

Thanks,

Aykut
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).