Alert from Strategy Monitor not being generated consistently
Author: sshiggins
Creation Date: 12/12/2016 9:02 PM
profile picture

sshiggins

#1
Hello,

I am a new Wealth-Lab Pro user that has been trading with Active Trader Pro (ATP) for years. My intent is to automate some of the ideas that have been profitable in ATP, to take the emotional aspect out of the trades.

I am running into an interesting issue.

- I have 4 strategies that have been testing very well in back testing with various Date Ranges (days, weeks, months…) at various scales (1 min, 3 min, 5 min…) in both Raw and Portfolio Simulation modes
- I am now testing these 4 strategies in Strategy Monitor against 4 unique paper accounts at 1 min scale (position at 50% of account balance)
- All 4 strategies have stop losses “Sell at percent based Trailing Stop “ (.01%)
- All 4 strategies have some form of profit based exist, including
o Sell at Limit (low)
 Current open Position is profitable
or
o Sell at Profit target (.02%)
- The issue is that the stop losses and exists are not generating alerts consistently. There are many situations, where I see a position that is well below the stop loss (much more than .01% loss) or much higher than the exit (Profitable or over .02% profitable) and no alert is generated, much less showing up in Order or being Filled. This does not happen all the time. Entries are working fine and there are some stop losses and/or exits that complete successfully.
- If I manually close the “stuck” position, trading continues as expected, for a while
- I have tried moving the exits to the beginning of the list to apply to all relevant positions as well as directly in front of or after the relevant open, with little difference.
- Questions:
o Could WLP be losing track of a position?
o I don’t believe trading volume has an effect on Strategy Monitor testing, is this correct?
o Any ideas for what I should try?

Thank you,
Scott
profile picture

Eugene

#2
Hi Scott,

Please share your Strategy code to get a bird's eye view. So that we could start with something. Thanks.

QUOTE:
in both Raw and Portfolio Simulation modes

You're not using Port.Sim. in Strategy Monitor, aren't you?
profile picture

sshiggins

#3
The entry code is working fine. I am using RAW mode for Strategy Monitor. Below are the exits and stop losses that are not working consistently. As I mentioned, I have tried putting them at the beginning of the rules list as well as after the long and short entry positions. The behavior does not appear to be correct in either case.

Thank you for the quick response!

Strategy 1 Exit / Stop Loss code:

CODE:
Please log in to see this code.


Strategy 2 Exit / Stop Loss code:

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

Eugene

#4
Many of your exits in code #1 refer to the current active Position "p" whereas check a different Position i.e. LastActivePosition. In my opinion this is a problem.

Also, market orders in your code do not precede the stops and limits in every case.

Code #2 looks okay. Although you have omitted the entry code, its interaction with the rest of the Strategy could also give a clue.
profile picture

Cone

#5
Because the code uses .NetProfitAsOfBar(bar), you must run this in Raw Profit mode. You said you were using RAW, so this is good.

Also, you have the same condition (NetProfitAsOfBar(bar) > 0) for both Market and Limit orders in Code #1. Since Market orders always should have precendence, the limit exits will never be used.

Anyway, it's a somewhat complex system of exits. The question is, "do the exits really need to be aligned for specific entry types?" If not, please use this simplified code:

CODE #1 (limit orders removed)
CODE:
Please log in to see this code.


Let me know if that works out for you and then we can work on Code #2.
profile picture

sshiggins

#6
Thank both of you. I will incorporate your suggestions. FYI - I originally did not have the Market orders in the first code. I added them, thinking it might have a better chance of execution. They had no real impact as the alerts were not even being generated. I will let you know how this goes.

thanks again!
profile picture

Cone

#7
When you use the Strategy Wizard, you need to make sure to group your entries and exits properly. I almost never use the Wizard, but it looks to me like you created different exits for different entry conditions. The code I posted above doesn't care how the position is entered, only if it's short or long. In this case, if there's a profit, the position is exited at market on the next bar, assuming that the trailing stop is not hit first. You're likely to get significantly different results with this code (which is what you may have wanted from the beginning) than with your Wizard code.
profile picture

sshiggins

#8
Thanks for your patience I am ramping up on C# and Wealth-Lab at the same time. I was a 360 assembly and C programmer many years ago.

I see major differences in what you are writing vs what the wizard is generating. I am seeing more flexibility and control in what you are writing.

In a quick run of the code you provided, I am seeing some trades with exits of Profit, but they are far from profitable. I am investigating now. It may be the timing of selling at Market on a quick move. I will make some adjustments to try to address this. Backtesting has gone from over $100 a bar profit to loss of ~$9 per bar at 1 minute bars.

If I put exits after entries, will they be executed on the same bar >> e.g. sell a profitable position that you just opened?
profile picture

Eugene

#9
QUOTE:
In a quick run of the code you provided, I am seeing some trades with exits of Profit, but they are far from profitable. I am investigating now.

Isn't this the effect of Fidelity $8 commission (default) applied?
profile picture

sshiggins

#10
This is with the commission applied. You have to trade large positions to make it work.
profile picture

sshiggins

#11
I am attempting to paper test this exit code with a simplified entry code > see below. The entry Alerts are generated and Orders are filled regularly. As I watch the positions in Account Balances and Positions (Streaming Updates on), I see positions hit well over .1% profit or loss, but exit Alerts are not generated. Any Ideas?

NOTE: I have run the strategy below with just Exit Code 1, just Exit Code 2 and with both in place. Backtesting shows different results in each case, but paper testing is failing to close positions.

thanks,

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

Eugene

#12
1. AtLimit entries can not just be mixed with AtStop exits on the same bar. Your strategy is missing properly setting the Position.Priority as per this FAQ:

I want to test a strategy that buys and sells with stop/limit orders on the same bar.

2. I don't know what for you're duplicating the exit code. It makes no sense to me.

3. Even if the "Exit code 2" were different, its placement is incorrect too: it should rather precede "Entry Code".
profile picture

sshiggins

#13
I noted that I had run the Strategy with just Exit Code 1 as it is shown preceding the entry. Exit Alerts are not being generated reliably. I am actually paper testing the code below now and there are two positions opened by the Entry Code. One Long and One short. There has been three executions of the main trading loop with no Sell or Cover Alerts being generated, even though both positions are profitable by over .03. One at .04 and the other at .05. On the forth execution of the Main Trading Loop, both positions were exited, profitably, but one with much lower profit than what it should have been.

- Any ideas regarding the delay? The strategy is missing profit opportunities that are crossing the required .03 threshold.

Thanks for the same bar exit link. I have been reading it and several other related discussion regarding same bar exists and reverses.

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

Eugene

#14
The code could be somewhat simplified for easier reading. On a recent example, could you illustrate the lower than expected profit?

CODE:
Please log in to see this code.


P.S. AtLimit/AtStop orders should not be combined on same bar (see #12 above).
profile picture

sshiggins

#15
The more complex entry code was generated by WLP rules. As it turns out, the separation of the Moving Average calculations allows for tuning for each location they are used. Thanks for the simplification suggestions.

As for the examples; as I was watching one or two positions, I would see them above the .03 threshold when the strategy main loop executed. It was above before and after for a while, but no alert was generated. I saw this happen multiple times. I closed WLP and clean up all paper accounts and restarted the strategy. It appears to be working better now.
profile picture

Eugene

#16
sshiggins asked in a different thread, now combined with this one:


This code is a stripped down version of something I have been testing. I stripped it down to troubleshoot the exit strategy. I have used the trailing stop exits in multiple strategies and have run into a intermittent issue with it. See additional notes and questions below.

CODE:
Please log in to see this code.


I have had the above and other code based strategies with the same exit shown above get into a situation where a short position is entered but gets stuck, lost... I have seen up to 50+ bars of a stock price headed up in a losing direction, but the CoverAtTrailingStop never generates an Alert.

I have been watching for Alerts but no Cover Alerts are generated, but other, Sell Buy or Short Alerts are.

This testing is with only one symbol at a time.

I have also seen this happen for long positions.

I was just watching a profitable short position go up to over $9,000 then over about 10 minutes drop to $6,500 profit. The .01% trailing stop should have closed the position, but it is still open.

- Any Ideas? It looks like WLP is loosing track of the position.

- Where is the position data and associated trailing stop data stored? Is there a way to manually look at it?

- Is position data maintained across restarts (and logins) of WLP?
This is critical as WLP often gets into odd states and requires a restart. NOTE: I restart WLP every day due to minimize issue throughout a trading day.

- If a strategy that is active in the strategy monitor is opened via "Open this strategy in a Strategy window" and modified, then saved, will the changes effect the currently running strategy?
NOTE: I have put in a "CoverAtMarket(bar + 1, p, "ShortProfit2");" to see if the strategy would unconditionally close the position, but no Alert was generated. I had to enter a manual trade ticket to close the short position.

thank you
profile picture

Eugene

#17
1. Please review my reply #12 and fix your AtStop/AtLimit orders. It does not make much sense to discuss your strategy w/o first seeing this fixed.

2. Also, AtMarket orders should precede AtLimit/AtLimit orders.
profile picture

sshiggins

#18
Apologies for the redundant / duplicate thread. I am fixing issue per #12 now, but in general:

- Where is the position data and associated trailing stop data stored? Is there a way to manually look at it?

thanks,
profile picture

Eugene

#19
What do you mean by the "position data"?

As for the trailing stop value, this is obviously stored in your "double amount" variable.
profile picture

sshiggins

#20
OK sorry for the stupid question about storage location ;-).

So I see that currently the data is not retained across restarts of WLP, so if there are open positions they would need to be dealt with manually.
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).