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

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 Radano, 06-10-2021, 01:40 AM
        19 responses
        604 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        3 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        470 views
        0 likes
        Last Post tradingnasdaqprueba  
        Started by aa731, Today, 02:54 AM
        0 responses
        5 views
        0 likes
        Last Post aa731
        by aa731
         
        Started by Christopher_R, Today, 12:29 AM
        0 responses
        10 views
        0 likes
        Last Post Christopher_R  
        Working...
        X