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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    51 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X