Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

C# Script FUncion for Trailing Stop

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

    C# Script FUncion for Trailing Stop

    Hi, could you please tell me if there is a script function (C#) to enter a trailing stop in NJ?

    BAckground: I use IB. They have extensive trailing stops. Before going live I would like to try out a strategy with trailing stops and backtest in NJ.
    Thank you!

    #2
    Welcome to our forums Larry, please have a look at SetTrailStop() in NinjaScript - http://www.ninjatrader-support.com/H...TrailStop.html

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Welcome to our forums Larry, please have a look at SetTrailStop() in NinjaScript - http://www.ninjatrader-support.com/H...TrailStop.html
      I have been using that ... the code is below. HOWEVER, at least in backtesting, this acts as a Stop and not as a Trailing Stop.
      Thank you,

      protectedoverridevoid Initialize()
      {
      SMA(Fast).Plots[
      0].Pen.Color = Color.Orange;
      SMA(Slow).Plots[
      0].Pen.Color = Color.Green;
      Add(SMA(Fast));
      Add(SMA(Slow));

      CalculateOnBarClose =
      false;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      if (SMA(Fast)[0] > SMA(Slow)[0] && InMarket == false)
      {
      EnterLong(DefaultQuantity,
      "");
      SetTrailStop(trailing);
      InMarket =
      true;
      }

      Comment


        #4
        What amount did you enter for 'trailing', it might not get activated at all if set too high...

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        64 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        35 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        51 views
        0 likes
        Last Post CarlTrading  
        Working...
        X