Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by love2code2trade, Yesterday, 01:45 PM
    3 responses
    22 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by trilliantrader, Today, 08:16 AM
    2 responses
    6 views
    0 likes
    Last Post trilliantrader  
    Started by samish18, Today, 08:31 AM
    1 response
    1 view
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by Creamers, 09-08-2023, 10:26 AM
    6 responses
    157 views
    0 likes
    Last Post JonyGurt  
    Started by funk10101, Today, 08:14 AM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X