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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        50 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        16 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        23 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X