Using ApplyAutoStops in multiple Strategy windows
Author: abegy
Creation Date: 4/17/2017 2:19 PM
profile picture

abegy

#1
Hi Eugene,

I see a problem with ApplyAutostops in the Strategy windows. if you open 2 strategies in the Strategy windows and the both of them used ApplyAutostops, the ApplyAutostops used the last parameter of your stops and not the parameter of your script.

Please test it with this simple scripts :
--> Script 1 (RUN First)

CODE:
Please log in to see this code.


--> Script 2 (RUN after the script 1)

CODE:
Please log in to see this code.


If you RUN again the script 1, you will see that all your trades is exit after 2 bars.

Does I make somethings wrong ?
profile picture

Eugene

#2
Hi Alexandre,

No, I don't think you did anything wrong. The problem description looks like caused by the use of static variables and/or methods by ApplyAutoStops in Community Components.

As a workaround, remove all links to ApplyAutoStops and paste its entire code found in thread below into each Strategy where you had ApplyAutoStops installed:

Post by thodder #6

Don't forget to include public enum AutoStopMode.

Thanks for spotting the issue.
profile picture

abegy

#3
Thank you Eugene. I will try like this
profile picture

Eugene

#4
The bug will be fixed in C.Components 2017.05. However, any existing strategies will have to call a new method (at the end of the Strategy code). To be exemplified on the AutoStops Wiki page when the updated extension is released (late April - early May).

P.S. The code must have an extra call to a new method called OnProcessingComplete after the trading loop. To avoid the bug that abegy has brought into the spotlight, it must be added to ALL strategies that employ AutoStops in C.Components after updating the library to v2017.05:

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

Eugene

#5
Alexandre, the fix is out. Please update C.Components to v2017.05.
profile picture

abegy

#6
Hi Eugene,

I try it with the new components but I have the same problem. To be sure, I restarted my computer after the installation. But still the same problem. Do you have an idea ?
profile picture

Eugene

#7
Hi Alexandre,

The issue is fixed. I double checked that. You're doing something wrong but I don't know what since you haven't provided a detailed test case.
profile picture

abegy

#8
I start my computer, load Wealth-lab and open a new strategy from code with the code of the the script 1. I run it.
After that, I open a new strategy from code with the code of the the script 2. I run it.
I run again the script 1 and see my trades with the 2 bars (see my screen shot).

I have checked that the components dll is the last one (date : 4/30/2017). Any idea ?
profile picture

Eugene

#9
Thanks, it's clear now. Please review my post #4 above. The important but overlooked point here is that you must call PositionEx.OnProcessingComplete() at the end of Execute() in each strategy that uses ApplyAutoStops from C.Components. This is where the fix is grounded.
profile picture

abegy

#10
Yes. it works. Sorry for the mistake.
Thanks a lot Eugene.
profile picture

Eugene

#11
Alexandre,

That's good news to hear!