Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't quite figure out trailing stops

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can't quite figure out trailing stops

    Hello, I'm banging my head against the wall a bit with trailing stops.

    I have my profit target:

    Code:
    SetProfitTarget(EnterLongName, CalculationMode.Currency, 100);
    And I want to set a trailing stop:

    Code:
    SetTrailStop(EnterLongName, CalculationMode.Percent, .5, false);
    My assumption is that will set a 50% trailing stop. so if I hit $50 profit my trailing stop would be at $25. However, that isn't happening, see the screenshot. There is no stop set. In the screenshot the stock dips down and never stops me out then exits on session close. In this case I would actually expect it to have stopped out at $50 loss since my profit target was $100.

    From my observations, as I'm backtesting over the last 5 months with NASDAQ 100 and S&P 500 the trailing stop is never in effect, so it's not just this stock or timeframe. I'm definitely using the API wrong.

    Please help!

    Log:

    Code:
    3/10/2020 6:45:00 AM Strategy 'MyStrategy/-1': Entered internal SubmitOrderManaged() method at 3/10/2020 6:45:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=39.05 StopPrice=0 SignalName='LongProfitTarget' FromEntrySignal=''
    Strategy 'MyStrategy/-1': Stop/target handling set to 'By strategy position' since currency based stop order was placed.
    3/10/2020 1:00:00 PM Strategy 'MyStrategy/-1': Cancelled order due to end of session handling: BarsInProgress=0, orderId='NT-00001-931' account='Backtest' name='Trail stop' orderState=Working instrument='OKE' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=19.52 quantity=100 tif=Day oco='NT-00000-931' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-03-10 06:45:00' gtd='2099-12-01' statementDate='2020-05-27'
    3/10/2020 1:00:00 PM Strategy 'MyStrategy/-1': Cancelled order due to end of session handling: BarsInProgress=0, orderId='NT-00002-931' account='Backtest' name='Profit target' orderState=Working instrument='OKE' orderAction=Sell orderType='Limit' limitPrice=40.05 stopPrice=0 quantity=100 tif=Day oco='NT-00000-931' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-03-10 06:45:00' gtd='2099-12-01' statementDate='2020-05-27'
    Attached Files

    #2
    Hello ,

    Thanks for your post.

    A CalculationMode of Percent is defined as follows:

    Percentage away from the average entry, based on the average entry price.

    It is not tied to the profit target's distance.

    I may suggest testing a simple strategy with realtime data to observe how this functions. I have attached an example that can be used to test with.

    Please let me know if you have any additional questions.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    59 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    133 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X