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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    46 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
    14 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    22 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X