I simply added code to call GetProfitLoss() so as to add some trailing stop functionality.
However, the first stop loss gets canceled somehow and the strategy stays short for the entire 5 days.
After debugging, I narrowed it down to this line of code and surrounded it with Print() statements and include order trading so you can see the damage.
Print( "Right before GetProfitLoss() call."); double currProfitLoss = Position.GetProfitLoss( Close[0], PerformanceUnit.Points); Print( "Right after GetProfitLoss() call.");
3/24/2008 4:59:55 AM Entered internal PlaceOrder() method at 3/24/2008 4:59:55 AM: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=99.99 StopPrice=0 SignalName='cross low' FromEntrySignal='' 3/24/2008 4:59:55 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='cross low' Mode=Ticks Value=4 Currency=0 Simulated=False Right before GetProfitLoss() call. 3/24/2008 4:59:56 AM Cancelled pending exit order, since associated position is closed: Order='NT-00001/Back101' Name='Stop loss' State=Working Instrument='$USDJPY' Action=BuyToCover Limit price=0 Stop price=100.06 Quantity=1 Strategy='ProbabilityHLM' Type=Stop Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='518045a11ec349fe90b3cc5c00dace06' Gtd='12/1/2099 12:00:00 AM'
Very dangerous. You need to make this a TOP priority bug fix.
Fortunately, there's a workaround. I wrote my own ProfitLoss() method by using Position.AvgPrice Price depending on whether long or short.
Sincerely,
Wayne
Comment