SellAtStop doesn't exit a short position
Author: thetraderman
Creation Date: 4/21/2011 1:26 PM
profile picture

thetraderman

#1
This code is to exit a short position.

I have been looking at this for a while and can't seem to figure out why I get a failure. Thanks for you help!

I tried different variations for the stop parameter including High[bar], Open, etc. I did verify that the exit bar was within limits of the current bar's low (i.e. there is an overlap). Also I have similar code but reversed comparisons for stops on longs and I don't get a failure. This could just be a coincidence where I may get errors in the future.

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

thetraderman

#2
Please forgive my latest question. Silly error. Needed CoverAtStop not SellAtStop.

Just realized I left out the most important line above by cutting and pasting.
CODE:
Please log in to see this code.
profile picture

Cone

#3
You can avoid this error by using ExitAtStop/Limit/Market signals. Behind the scenes, Wealth-Lab will use a Sell or Cover as required for the Position that you pass to the signal.
profile picture

thetraderman

#4
First of all sorry for the duplicate post. I'll be more careful next time. I thought the administrators deleted it.

Secondly, I tried ExitAtStop and also CoverAtMarket and both with the same results. Also the error occurs when I single step one bar at a time so the two trading loops is not the reason. It happens with static data and no real time updates. Is there anything else you see wrong with my code?

Also what's weird is CoverAtMarket works with no problems on a regular short exit, not sure why it wouldn't work at a stop.
profile picture

Cone

#5
I didn't look at the code because I thought you implied that you found what you did wrong by using the wrong signal.

The only thing that is apparently wrong in the snippet is the use of p.Shares in the script. Except when using the SetShareSize method, p.Shares will always evaluate to 1. Position Sizing occurs after the script is run, so attempting to work with absolute cash, equity, and DD values is not possible without extraordinary effort.
profile picture

thetraderman

#6
Actually in RAW mode p.Shares does equate properly when setting the number of shares to a fixed value. I verified this. I'll try looking further on my side. Thanks for confirming the code at least looks correct.
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).