I have noticed that there is a discrepancy when I use the following code in my strategies
CODE:
Please log in to see this code.
The stop seems to execute properly but the printed data in the "Exit Name" column of the Trades tab is significantly different for the executed stop in all cases.
QUOTE:
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit % Profit $ Bars Held Profit per Bar Entry Name Exit Name MAE % MFE %
Long GRMN 13,522 8/17/2009 28.40 11/4/2009 29.31 3.20 $12,289.12 57 $215.60 Trailing Chandelier 20.01 -2.40 39.61
Long ADSK 15,996 11/19/2009 24.16 5/6/2010 29.10 20.44 $79,004.34 115 $686.99 Trailing Chandelier 26.59 -6.87 45.61
In fact the value in the "Exit Name" column is never reached.
Am I doing something wrong?
Vince
Size:
Color:
Vince,
It's hard to guess from just two lines. Maybe it's a rotation strategy and Bars should be replaced with
p.Bars. Maybe something else. Guesswork is counterproductive.
Size:
Color:
Hi Eugene!
It is in a non-rotation strategy. I will build and post a complete working script that you can run that will demonstrate the problem.
Vince
Size:
Color:
Run the following code on the Dow 30 with 3% equity for 6-10 years
CODE:
Please log in to see this code.
Notice that the values seem correct for the initial trades and get progressively "strange" fpr later and later trades.
Vince
Size:
Color:
The initial trades are not representative as your code contains an error:
CODE:
Please log in to see this code.
The ATR period (30) is greater than the main loop start bar.
To fix it, use GetTradingLoopStartBar(speriod). And you might even want to take GetTradingLoopStartBar(speriod * 3) as ATR is an unstable indicator. See the WealthScript Programming Guide > Indicators > Stability of Indicators.
Now to your "discrepancy". A discrepancy could be if you used a SellAtStop which directly takes the "level" but here is SellAt
TrailingStop which has a different behavior. As we know, trailing stop is modified only when the level gets below the current trailing stop price stored with the Position.
Size:
Color:
The "last" level that you pass to ExitAtTrailingStop() is not necessarily the level that is active for the TrailingStop. Understood? or do I need to explain more?
Try calling PlotStops(); to visualize what's going on.
Size:
Color:
I believe the following code resolves one oversight (start of loop < ATR period) and the issue with the level variable not always being the maximum.
CODE:
Please log in to see this code.
I still see the same problem though out many closed trades during the latter portion of the period.
Vince
Size:
Color:
Vince, you still don't seem to have completely understood the difference between the trailing exit and a stop. Your "level" is
not the exit level because it can decrease (for longs; vice versa for short trades). It would be if *AtTrailingStop was replaced with *AtStop, I guess. Like Cone suggested above, see for yourself and compare the PlotStops() output to the "
level" plotted with DrawCircle():
CODE:
Please log in to see this code.
P.S. Some differences can be attributed to a gap open (see SellAtTrailingStop >
Remarks in the QuickRef).
Size:
Color: