Question regarding "Portfolio-Wide Conditions" example
Author: abegy
Creation Date: 5/19/2017 4:43 PM
profile picture

abegy

#1
Hi Eugene,

I run the Portfolio-wide conditions script example available in the wiki with the following modification

CODE:
Please log in to see this code.


Normally, trade positions must be ended after 1 bar and have a maximum hold position equal to 2.

But when I look on trades sheet, I see several trades with a hold position greater than 2. Can you explain me why? Is it because of the setcontext synchronization logic ?

To reproduce the result, run the script with the modification on the Dow30 dataset with a raw mode.

Thanks for your help


profile picture

Eugene

#2
Hi Alexandre,

Cone will correct me if I'm wrong (he's the author):

CODE:
Please log in to see this code.
profile picture

abegy

#3
Thanks a lot
profile picture

abegy

#4
Hi Eugene,

I have another problem when I try to adapt the script to use autostops and priority in positions..
When I run the following strategy with the Dow30 dataset (set 20% of the equity with a first date of 01/01/2000), there is no error :

CODE:
Please log in to see this code.


But with the following script, there is a runtime error (position entry cannot be zero). I run the script with symbol AXP from the Dow30 dataset with same parameters.

CODE:
Please log in to see this code.


Do you see why ?


profile picture

Cone

#5
It's because V has a shorter history. To make sure you're using real data in a script like this one, check for the FirstActualBar.

Just add this after SetContext() -
CODE:
Please log in to see this code.
profile picture

abegy

#6
Thanks Cone. I tried it but I see a strange result (see my screenshot). The 4 trades have a the same exit date as the entry date.
Moreover, there are 2 positions for the same symbol (XDM).

Do you see another problem in the code ?
profile picture

Cone

#7
Just fyi: AAPL replaced T in the Dow 30 on 19 March 2015.

I can't have the same script that you have. If your data loading range starts on 1/1/2000 and the trading loop starts at bar 30, there's no way that you can get into a trade on 1/3/2000 (bar #2) as indicated in your Trades list. Furthermore, even if you started on bar #1, you couldn't get a CrossOver since the SMA would be 0.
profile picture

abegy

#8
This is the script :

CODE:
Please log in to see this code.


Each time I run it, I have the same result displayed in the screenshot. I agree with you that this is not possible normally but this is the case and I do not see what is wrong in the code.

profile picture

Cone

#9
I see it too running that code. I can't remember ever using the AutoStops, and that seems to be where something has gone wrong. We'll have to investigate that.