Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop loss order placements?

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

    Stop loss order placements?

    Hello world!!

    I'm a NT7 new user and developing a new strategy. Now, I'm facing a problem with stop loss order placements when I enter a position.
    For example, in a long position, I want to set a stop loss order 2 ticks below the lowest low of last 3 bars [since today].

    Here is a part of my script :

    #region Variables
    // User defined variables (add any user defined variables below)
    private int stochaMin = 20; // Default setting for StochaMin
    private int quantity = 1; // Valeur par Default setting for Quantity
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {


    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Resets the stop loss to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, 2);
    }

    else if(Position.MarketPosition == MarketPosition.Long)
    {
    if (Close[0]!=Low[0])
    SetStopLoss("Long", CalculationMode.Ticks, MIN(Low,3)[0] - 1*TickSize,true);



    //Buying condition
    if (Close[0] < Bollinger(2, 14).Lower[0] && Stochastics(5, 14, 3).K[0] < stochaMin)
    {
    EnterLong(quantity, "Long");
    }
    ...

    I was told that I was wrong if I wrote that script. In your opinion, does that code work? Please, can anyone help me?

    Thank you in advance!

    #2
    stevie,

    Welcome to the NinjaTrader forum! For future references, please avoid duplicate posts as we can better assist them in one thread alone for each item. As for your NinjaScript question, I've attached a sample script that should help you out. I've commented on the code in order for clarification.
    Attached Files
    Bobby Y.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    630 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    564 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X