Positions are opened randomly and never get closed
Author: RHAT
Creation Date: 9/27/2018 6:09 PM
profile picture

RHAT

#1
Hello,

i have a problem in the Strategy-Builder/Backtesttool of WL.

My WL is WL-Developer 6.9.15,
My OS is Win10 (64bit).



Here are the facts:

While backtesting, Long-Postition(s) is/are opened randomly and get never closed (like buy & hold).

It happens in the single open position mode but further Long-Positions are opened after such an error position is still open.

No compiler message, no alert or message in the debug log due to this problem.

It appers in every new strategy, doesn´t matter if in Strategy-Builder or as code version.

The same problem with already functionating code which is saved under a new name.

I tried to close the positions with „Current open position is older than a number of bars“ and „Active open position is older than a number of bars“ - makes no difference.

In one code (not in more) the problem was gone when i changed in the entry line the [bar+1] to [bar].

I don´t know if it is important but one day before the problem occured the first time, i installed the extension “Performance Visualizer” but on that day when i installed this extension (and restarted WL) i had no error.

By the way, i´ve tried a combination of the entry of a single open position code and the exits of a multi open position code to try to be able to close all open positions – than I had a complete multi open position strategy, even if the entry condition was “if (IsLastPositionActive == false)” multi positions were opened.



Please find in the attachment a strategy code (which i kept as simple as possible) in .txt format were the error occurs (this is the single open position version).
I also attached the trade list from the code example.


Has anybody a solution or an idea how to fix this problem?

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

Eugene

#2
Welcome aboard.

QUOTE:
While backtesting, Long-Postition(s) is/are opened randomly and get never closed (like buy & hold).

Your sample code inherits the single-position design pattern yet opens two positions. No wonder it will fail to manage (sell/cover) them. Please refer to the WealthScript Programming Guide > Programming Trading Strategies > Multi-Position Strategies on how to rewrite it if you wish to manage multiple positions. Let me know if any assistance is required with getting it done.

P.S. I've renamed the confusing and somewhat misleading topic title "Strategy Builder: Random Buy&Hold orders". As you understand this neither has to do with the "Strategy Builder" (your Strategy is not Rule-based) nor with Buy&Hold (which works correctly).
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).