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

can't get stop losses or profit targets to execute

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

    can't get stop losses or profit targets to execute

    hello, i am using the market simulation data, and have a very simple strategy developed for testing purposes only. the buy order goes off, but i can not, for the life of me, get any stop loss or profit target to trigger when running this strategy.

    Please advise:

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    ///<summary>
    /// 4
    ///</summary>
    [Description("4")]
    [Gui.Design.DisplayName(
    "My custom strategy4")]
    publicclass MyCustomStrategy4 : Strategy
    {
    #region Variables
    // Wizard generated variables
    privateint myInput0 = 1; // Default setting for MyInput0
    // 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(
    "buy", 1);
    SetProfitTarget(
    "buy", 1);
    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] >= 150)
    {
    EnterLong(DefaultQuantity,
    "Buy");
    }
    }
    #region Properties
    [Description(
    "")]
    [Category(
    "Parameters")]
    publicint MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Does that code even compile? I didn't think there was a SetStopLoss() with that signature. In any case, the default mode for SetStopLoss is currency, which means it will trigger when the price goes below one. These are the lines of code from my strategy I use for those two calls in percentage mode; I specify the parameters as whole numbers (e.g. 5 for 5%).

    Code:
    if (MyProfit > 0)
       SetProfitTarget("", CalculationMode.Percent, MyProfit/100.0);
    
    if (MyStop > 0)
       SetStopLoss("", CalculationMode.Percent, MyStop/100.0, false);
    Last edited by Pete S; 01-24-2008, 07:52 AM. Reason: Typo

    Comment


      #3
      still not working..

      i used part of your code like this:

      protectedoverridevoid Initialize()
      {
      SetProfitTarget(
      "", CalculationMode.Percent, 0.50);
      SetStopLoss(
      "", CalculationMode.Percent, 0.50, false);

      }

      and still no stop loss or profit target gets executed.

      getting very frustrated since i can not begin trading until i can get stop losses and profit targets to actually execute along with the buy/sell order.

      i have many strategies ready to implement, and this is the only part that doesn't work....all my long/short strategies actually execute the order as programmed, but i can't seem to get a stop loss or profit target to go along with it.

      am i the only one with this issue? is it because i'm using the market replay simulator? will i have this issue with a live $$ account? lord knows i don't want to try that as a test...

      Comment


        #4
        C# is case sensitive. Your entry signal name used when submitting an order ("Buy") is different than what you are using when calling SetStopLoss() ("buy"). Also, your syntax is incorrect.

        Please try this:

        SetStopLoss("Buy", CaclulationMode.Ticks, 20, false);
        SetProfitTarget("Buy", CaclulationMode.Ticks, 40);

        CalculateOnBarClose =
        true;
        RayNinjaTrader Customer Service

        Comment


          #5
          still not working..sorry ray...

          Ray, still not executing a stop loss or profit target. here's my whole strategy....i am apply this for the ticker symbol AAPL...as you can see, it's a very simple strategy...simply buy when price over 125...that executes at the end of the minute bar. but i never get a stop loss or profit target execution...what else can it be??



          #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.Strategy;
          #endregion
          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          ///<summary>
          /// 4
          ///</summary>
          [Description("4")]
          [Gui.Design.DisplayName(
          "My custom strategy4")]
          publicclass MyCustomStrategy4 : Strategy
          {
          #region Variables
          // Wizard generated variables
          privateint myInput0 = 1; // Default setting for MyInput0
          // 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(
          "Buy", CaclulationMode.Ticks, 40, false);
          SetProfitTarget(
          "Buy", CaclulationMode.Ticks, 40);
          CalculateOnBarClose =
          true;
          }
          ///<summary>
          /// Called on each bar update event (incoming tick)
          ///</summary>
          protectedoverridevoid OnBarUpdate()
          {
          // Condition set 1
          if (Close[0] >= 125)
          {
          EnterLong(DefaultQuantity,
          "Buy");
          }
          }

          protectedoverridevoid OnBarUpdate()




          #region Properties
          [Description(
          "")]
          [Category(
          "Parameters")]
          publicint MyInput0
          {
          get { return myInput0; }
          set { myInput0 = Math.Max(1, value); }
          }
          #endregion
          }
          }

          Comment


            #6
            .5 = 50%

            You want to use .05 if you mean 5%.

            Comment


              #7
              thanks Pete, but that's not it...

              ticks...price...percent...no matter what i use, don't get executed.

              in latest example, i tried 40 ticks...tried 10 ticks, 1 tick, 100 ticks

              tried price of 0.50, 0.005, 0.05, 5, 10, 1, 100

              tried percent... 0.01, 0.001, 0.05, 0.005, 0.50, 1, 5, 10, 100.

              doesn't matter what i use, no execution.

              maybe there is another setting i need to check? it could just be the code is correct but something else isn't selected?

              Comment


                #8
                Please check your syntax.
                SetStopLoss("Buy", CaclulationMode.Ticks, 40, false);

                It should be "CalculationMode.Ticks".
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Should that even compile?

                  Just curious, if CalculationMode is incorrectly typed, should the strategy even compile?

                  thx

                  Originally posted by NinjaTrader_Josh View Post
                  Please check your syntax.
                  SetStopLoss("Buy", CaclulationMode.Ticks, 40, false);

                  It should be "CalculationMode.Ticks".

                  Comment


                    #10
                    Hello,


                    This will not compile. You are correct.
                    DenNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by tomasak, Today, 12:54 PM
                    0 responses
                    0 views
                    0 likes
                    Last Post tomasak
                    by tomasak
                     
                    Started by Zeezee, Today, 12:45 PM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_ChristopherJ  
                    Started by swjake, Today, 12:04 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post swjake
                    by swjake
                     
                    Started by Richozzy38, Yesterday, 01:06 PM
                    5 responses
                    24 views
                    0 likes
                    Last Post Richozzy38  
                    Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
                    13 responses
                    51 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X