Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars since event and conditional trailing stop

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

    Bars since event and conditional trailing stop

    Hi
    I wonder if there is a quick way for

    1) Knowing the date or the bar number of a true condition (ie when the an indicator reached a given value).

    2) Set a trailing stop only in case of a profit and delete the trailing stop once the position is closed.

    Best

    g.

    #2
    gileper,

    1) Knowing the date or the bar number of a true condition (ie when the an indicator reached a given value).

    Time[0] always references the current time stamp for that OnBarUpdate() call. This would be able to be stored or displayed when a condition is true.

    2) Set a trailing stop only in case of a profit and delete the trailing stop once the position is closed.





    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks,

      as regarding the time of the event I use to store as you say the Time[0].
      I know some platform allows to write something like (SMA(20)=30)[i].Time ... I mean i get quickly the last i-th Date when the sma was 30.

      2) as for the trailing stop, i read "you should always reset the trail stop price/offset value when your strategy is flat otherwise". How to eliminate the stop for the next trade? (I use the trailstop only in case of partial profit)

      If the trailingstop is set on barupdate only and not in initialize, it seem that it will be not deleted on execution.

      if trailingStop was not a void I could set IOrder torder= trailingstop(..) and then using order update to set torder=null when filled or cancelled.

      best
      g

      Comment


        #4
        gileper,

        Unfortunately there is nothing like your example I am aware of, however there may be a way to do that with C#. NinjaScript is based on C#.

        SetStopLoss() will override the SetTrailStop() function if you use both. You may want to spend some time reviewing those two reference samples I posted in my previous message to you. Likely you will want to just use the SetStopLoss() and update it based on your conditions, i.e. implement your own form of trailing stop.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        157 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        91 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        143 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        131 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X