Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trailstop based on dynamic value

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

    Trailstop based on dynamic value

    Hi,

    I'm looking to use a trailstop when I enter a long (or short) position placed
    at a distance of 2*10 day ATR from the price I enter the position at. I want
    the trailstop to move with the price if the trade goes in my favour but obviously
    not move if the trade goes against me. I'm looking to backtest this strategy so I
    need to fully automate it with Ninjascript. Below is what I have done so far; but
    I believe that from the language "CalculationMode.Price, ATR(10)[0]*2" the trailing stop
    will be set at the price which has a value of 2*10 day ATR. Instead I wish the trailstop to
    be set at a DISTANCE of 2*10dayATR.

    Can you assist?

    Thanks,

    Ciaran


    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(SMA(50), SMA(100), 1))
    {
    EnterLong(DefaultQuantity, "");
    SetTrailStop(CalculationMode.Price, ATR(10)[0]*2);
    }

    // Condition set 2
    if (CrossBelow(SMA(50), SMA(100), 1))
    {
    EnterShort(DefaultQuantity, "");
    SetTrailStop(CalculationMode.Price, ATR(10)[0]*2);

    #2
    Hello ciaranfryan,

    Thank you for your post.

    at a distance of 2*10 day ATR from the price I enter the position at.

    You can reference the price you entered with Position.AvgPrice

    SetTrailStop(CalculationMode.Price, Position.AvgPrice - ATR(10)[0]*2);
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    649 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    576 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X