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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X