OnBarUpdate() {
....
SetTrailStop("[0] Buy 1729 XLY", CalculationMode.Percent, 0.1, false);
EnterLong(0, 1729, "[0] Buy 1729 XLY");
}
When the code was executed in StrategyAnalyzer, it appears that the trailing stop price was set to the filled price of EnterLong() rather than 10% below. Consequently, the trailing stop order was triggered and filled exactly at the entry price, as soon as the buy order was filled. See the attached image.
Here is the log:
-----------------------------------
1/29/2010 9:00:00 PM Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='[0] BUY 1729 XLY' Mode=Percent Value=0.1 Currency=0 Simulated=False
1/29/2010 enterLongPosition (20, SHY) on bar[270] EnterLong (cash= 50000.00 size= 1.00 price= 28.91 stop= 28.87 '[0] BUY 1729 XLY')
1/29/2010 1:00:00 PM Entered internal PlaceOrder() method at 1/29/2010 1:00:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1,729 LimitPrice=0 StopPrice=0 SignalName='[0] BUY 1729 XLY' FromEntrySignal=''
1/29/2010 OnExecution (0, XLY) on bar[270] Order='NT-00000/Backtest' Name='[0] BUY 1729 XLY' State=Filled Instrument='XLY' Action=Buy Limit price=0 Stop price=0 Quantity=1,729 Strategy='MyRS' Type=Market Tif=Gtc Oco='' Filled=1729 Fill price=28.97 Token='90abae11480b4e28a1bacef794714fc2' Gtd='12/1/2099 12:00:00 AM'
1/29/2010 OnExecution (0, XLY) on bar[270] Order='NT-00002/Backtest' Name='Trail stop' State=Filled Instrument='XLY' Action=Sell Limit price=0 Stop price=75.17 Quantity=1,729 Strategy='MyRS' Type=Stop Tif=Gtc Oco='NT-00000-743' Filled=1729 Fill price=28.97 Token='1fcabbbab6e447539c756722a01d11b4' Gtd='12/1/2099 12:00:00 AM'
------------------------------------------------------------
The reason why I have SetTrailStop() in OnBarUpdate() is that I want to eventually set the stop based on ATR of the instrument - so, it's not static. I tried that with CalculationMode.Ticks and had the same problem. I don't have SetStopLoss() anywhere in the strategy. The strategy runs on the daily timeframe.

Comment