Trailing Stop Cancelled multiple times
Author: thetraderman
Creation Date: 5/18/2011 1:43 PM
profile picture

thetraderman

#1
I'm running my script and it gets to the point where my trailing stop kicks in and gets executed. My logs and the bars pane both show that the stop was executed (buy/sell arrows are in place) but for some reason the orders window shows that the stop was cancelled. Not sure why since I didn't do anything. Also the "Account Balances and Positions" pane still show the original buy order as opened and it is updating. Do you know what would cause this? Here is the code.

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

thetraderman

#2
Also I noticed the short positioned doubled when it tried to execute the stop. Not sure why. I am trying to set posSizer to one trade per symbol to see if that helps. Also another question, why is it when switch the tab to script edit mode (to look and edit my script), the posSizer switches from one trade per symbol to fixed number of shares and out of one trade per symbol option? Any way to force it to stay where I last set it?
profile picture

Cone

#3
QUOTE:
My logs and the bars pane both show that the stop was executed (buy/sell arrows are in place) but for some reason the orders window shows that the stop was cancelled.
I can't think of any reason that this would happen other than manually canceling the order [accidentally] or turning off Auto-Trading.

QUOTE:
I noticed the short positioned doubled when it tried to execute the stop.
Re: "the stop". The code above only shows exit logic. Nonetheless, there is one bug that we discovered recently and will be fixed for 6.2; not sure if this applies to your case...

Assume you're trading a script on 5-minute intervals, and your script alerted to enter at stop on the 1015 bar. Say the stop triggered and entered the Position at 1016, and then you lose your internet connection until 1018. When the connection is restored, the chart is reloaded (to ensure it has all the data), and the Alert is re-issued as long as the 1015 is still the last full bar in the chart.

If the previous order were still Active (or Stage), WLP wouldn't place a new order. However, WLP doesn't consider orders that have already filled in that "no-duplicate" logic. So, in this example, the alert would cause a new order to be placed, and if marketable, it would be filled too.

QUOTE:
I am trying to set posSizer to one trade per symbol to see if that helps.
It will only help theoretically. If multiple Alerts are placed to enter a trade, then you'll get multiple Positions.

QUOTE:
why is it when switch the tab to script edit mode (to look and edit my script), the posSizer switches from one trade per symbol to fixed number of shares and out of one trade per symbol option?
I really can't imagine how that can happen. Can you go through all the steps, click by click, so I can try to duplicate it, please?
profile picture

thetraderman

#4
It's possible now that I think of it, that I accidentally hit the cancel instead of OK for the PosSizer so it was never accepted. I'll try again and see if it happens being more aware.

With reagrds to the cancelled orders I know for sure I did not turn off auto trading because once I closed the order by hand by issuing a sell, the system went back and bought more shares on the next buy signal. I'll try to keep a better eye on it but I hope I can find the reason or explain it otherwise I am stuck at the machine all day which defeats the purpose of auto-trading.
profile picture

Cone

#5
In my opinion, all Auto-Trading should be monitored, not continuously, but monitored. It isn't a "launch and leave" solution since there are so many factors involved - software, power, ISP, and machines can fail (I had a P/S suddenly fail on my 2 weeks ago). Auto-Trading is great for getting many orders to market quickly and without mistakes, but problems can occur.

After looking closely at your logic, it's possible that you're putting your stops too close to the market, or on the wrong side of it. For example, if ABCD is trading at 25.20 and you enter a sell at 25.21 stop (or higher), Fidelity will reject that order because it's immediately marketable.

To minimize the possibility of that situation occurring, you need to give your stops more room, and/or perform a proximity test between the stop price and the Close of the last bar. If it's "close enough", use ExitAtMarket.
profile picture

thetraderman

#6
I took your advice and I did find an issue. I didn't check when I did a trailing stop if I was on the next bar to prevent a stop and entry on the same bar. I'll try it and see what happens. Also I put in some print statements and I noticed that for every stop error the trail value went down and it could be doing it quite a few times until finally the trigger is pulled. Could it be that I really should not put in an else to the if(ExitAtTrailingStop ..) since it will always fail until the trigger is pulled?
profile picture

Cone

#7
QUOTE:
Could it be that I really should not put in an else to the if(ExitAtTrailingStop ..) since it will always fail until the trigger is pulled?
The else is a modifier of the if(Low[bar] < p.EntryPrice.. statement. So I don't see a problem. You're either going to enter SellAtStop(bar+1, p, High[bar],... whoops, that's it right there.

You see, the chances that the market is already trading at or below this order is very high. If you want to stop out, SellAtMarket right there.
profile picture

thetraderman

#8
Another question I have which I find strange is occasionally I would get alert for a buy or sell, the logs in my code would show that a market buy or sell was implemented but I do not get an order conformation as if the trade was never made. I do have auto-trading enabled and on paper for now. Do you know what would cause this?
profile picture

Cone

#9
For a likely explanation for stop/limit orders, see Orders > Paper Trading > How Orders Are Filled

For market orders, I have no idea and there's not enough information to guess. Need a script, symbol/DataSet, timeframe, streaming or Strategy Monitor? other settings...
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).