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

long timeframes vs. trailing stop loss

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

    long timeframes vs. trailing stop loss

    I have my trailing stop loss defined at time of trade entry in OnBarUpdate function. When I run my strategy for 15-min timeframe, i get stopped out on really great entries. Apparently, because the trail stop-loss checks at end of bar or something.

    i set a profit target of only 5 ticks in same place as trail stop-loss, and the 15-min bar goes like 30 ticks. i want it to exit when i hit profit of 5 ticks. it works ok on short timeframes.

    should i be putting my trail stop loss outside of OnBarUpdate, and if so, where? I'm new to scripting, and the only functions i have in the samples i'm using are Initialize and OnBarUpdate.

    #2
    Yes SetTrailStop() will update the stop based on the close of the bar.

    Based on your description am I right to assume this is over historical data? When looking at historical data the system will not know the order in which prices were hit on the bar and will default to the stop loss being hit first if it's unsure. In real time it would fill the target first.
    For more details on this: http://www.ninjatrader.com/support/h...ime_vs_bac.htm

    If you wanted to be able to backtest with this sort of trail you would need to add intrabar granularity. so that the stop could be placed on the smaller time frame.
    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by



    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thanks Lance, that is great info. yes, i'm just backtesting my newly minted ninjascripts & wizard strategies before trying them live.

      i will turn it on in my sim acct tomorrow when there's more volatility and see if the 15-min will trigger both an entry and profitable exit in same bar.

      Comment


        #4
        No problem, let me know if you have further questions.
        LanceNinjaTrader Customer Service

        Comment


          #5
          i changed it to SetStopLoss and now it's triggering the exit at 5 ticks within the same 15-min bar. this is what i want. i may make copy of strategy with trailstoploss test both in SIM during live market data.

          Comment


            #6
            You could use SetStopLoss() to update it manually in the OnBarUpdate()

            Typically SetTrailStop() isn't needed if you're coding yourself. I find it's more common to use with the wizard, but it can also be more convenient depending on the sort of trailing rule you want to use.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            3 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Working...
            X