Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 TraderCro, 04-12-2024, 11:36 AM
        7 responses
        102 views
        0 likes
        Last Post TraderCro  
        Started by Bogdan097, Yesterday, 03:25 PM
        3 responses
        18 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Mathias79, Today, 10:38 AM
        4 responses
        8 views
        0 likes
        Last Post Mathias79  
        Started by synthhokie, Today, 10:24 AM
        2 responses
        6 views
        0 likes
        Last Post synthhokie  
        Started by Skifree, Yesterday, 11:47 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Working...
        X