Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I can't introduce a stoploss order, help!

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

    I can't introduce a stoploss order, help!

    First of all sorry about my english if i introduce some mistakes,
    I have just begun with the Ninja few days ago and I'm trying to program an estrategy I think so easy.
    I want to open a long/short position if Max/Min of a determinate Bar is crossed (Bar that ends at 16:00), first of all I can't introduce the long and short position in the same estrategy.
    But I managed to create an estrategy that open the long position if 16barMax is crossed , and now I want to exit the long position if price turns 4% from my entry price, How can I do it?

    Here I let you the probisional Code, which errors you find it?

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    ///<summary>
    /// Estrategia del libro Guia del Trader de Petitjean
    ///</summary>
    [Description("Estrategia del libro Guia del Trader de Petitjean")]
    publicclass RRHlong : Strategy
    {
    #region Variables
    // Wizard generated variables
    privatedouble stop = 4.000; // Default setting for Stop
    // User defined variables (add any user defined variables below)
    #endregion
    ///<summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    SetStopLoss("enterlong", CalculationMode.Percent, Stop, false);
    CalculateOnBarClose = true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (ToTime(Time[0]) == ToTime(16, 0, 0))
    {
    Variable0 = High[0] + 1 * TickSize;
    }
    // Condition set 2
    if (Variable0 != 0)
    {
    EnterLongStop(DefaultQuantity, Variable0, "enterlong");
    }
    }
    #region Properties
    [Description("")]
    [Category("Parameters")]
    publicdouble Stop
    {
    get { return stop; }
    set { stop = Math.Max(10.00, value); }
    }
    #endregion
    }
    }
    #region Wizard settings, neither change nor remove

    Help please!!!

    #2
    Hi julen,

    One of our NinjaScript trainees will respond to you later in the day. Thank you for your patience.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      Sorry for the delay.

      You will want to use something like this:

      SetStopLoss("enterlong", CalculationMode.Percent, Stop, false);

      And make sure the stop value is 0.04, not 4. 4 means 400%.

      This will help:

      DenNinjaTrader Customer Service

      Comment


        #4
        Thanks a lot, my really problem was the 0,04; I thought that 4 means 4% not 400%!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        598 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X