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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X