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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    132 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X