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

Profit Target only triggered by the Creating Order

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

    Profit Target only triggered by the Creating Order

    Hello,


    If I create an order with TakeProfit and Stoploss, I would like the TakeProfit and Stoploss only triggered by the same order, and not from a different order.

    How can I solve this problem?
    Last edited by doc11; 01-28-2009, 08:36 AM.

    #2
    SetProfitTarget(string fromEntrySignal, CalculationMode mode, double value)
    SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)

    Use the fromEntrySignal to choose which entry order you want to associate them with.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      It does not work I'll show them my code.



      Code:
      #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>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class Test : Strategy
          {
              #region Variables
              // Wizard generated variables
              private int stop = 50; // Default setting for Stop
              private int profit = 10; // Default setting for Profit
              int zaeler = 1;
                      // 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>
              protected override void Initialize()
              {
                 
                  CalculateOnBarClose = false;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  if (BarsPeriod.Id == PeriodType.Tick && BarsPeriod.Value <= 130) return;
                 
                  if(Time[0].Minute != 0 && Time[0].Minute != 5 && Time[0].Minute != 10) return;
      
                  EnterLong(20000, "Trade "+Convert.ToString(zaeler));
                  SetStopLoss("Trade "+Convert.ToString(zaeler), CalculationMode.Ticks, Stop, false);
                  SetProfitTarget("Trade "+Convert.ToString(zaeler), CalculationMode.Ticks, Profit);
                 
                 
                  zaeler = zaeler + 1;
                 
                 
              }
           
              
              #region Properties
              
              [Description("")]
              [Category("Parameters")]
              public int Stop
              {
                  get { return stop; }
                  set { stop = Math.Max(1, value); }
              }
      
              [Description("")]
              [Category("Parameters")]
              public int Profit
              {
                  get { return profit; }
                  set { profit = Math.Max(1, value); }
              }
      
            
              #endregion
          }
      }

      Comment


        #4
        doc11,

        You need to be calling Set() methods before you enter the market or else those Set() methods will not apply for that particular order.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          can you give me an example code?

          Comment


            #6
            SetStopLoss(...);
            SetProfitTarget(...);
            EnterLong(...);
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I have now changed my code, but the result is the same as previously.

              SetStopLoss("Trade "+Convert.ToString(zaeler), CalculationMode.Ticks, Stop, false);
              SetProfitTarget("Trade "+Convert.ToString(zaeler), CalculationMode.Ticks, Profit);
              EnterLong(20000, "Trade "+Convert.ToString(zaeler));

              Comment


                #8
                doc11,

                You will need to debug your orders. Your code is constantly submitting Set() and are potentially modifying your orders all over the place. You are placing entries and modifications on every single OnBarUpdate.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Can you send me a script, in which several orders with TakeProfit and Stoploss be opened, but the TakeProfit and Stoploss only from the corresponding orders are triggered.

                  I have search in the forum and in the Help Guide, but i found nothing.

                  Comment


                    #10
                    doc11,

                    We do not have any reference. Just submit with unique signal names and stop resubmitting constantly.

                    In Initialize():
                    Code:
                    SetStopLoss("Long1", CalculationMode.Ticks, 10);
                    SetStopLoss("Long2", CalculationMode.Ticks, 15);
                    SetStopLoss("Long3", CalculationMode.Ticks, 20);
                    In OnBarUpdate():
                    Code:
                    EnterLong("Long1");
                    EnterLong("Long2");
                    EnterLong("Long3");
                    Each one will have their respective stops.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      They do not understand my problem, I explain it again.

                      for example:
                      • my first Long Trade entry is 1.3050
                      • TakeProfit for the first Trade is 20 Ticks = 1.3070
                      • StopLoss for the first Trade is 20 Ticks = 1.3030
                      After some time has changed the Market Price at 1.3040.
                      The first order is still in the market.
                      • my second Long Trade entry is 1.3040
                      • TakeProfit for the second Trade is 20 Ticks = 1.3060
                      • StopLoss for the second Trade is 20 Ticks = 1.3020

                      Now if the price rises to 1.3060, the first Trade is closed on the TakeProfit from the second Trade.
                      But the second trade must be closed and not the first.

                      They understand my problem, I must TakeProfit and Stoploss attach to a Trade.


                      Comment


                        #12
                        Are you viewing this as from the Strategy Analyzer's chart tab?
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          So I open the Strategy Analyzer.
                          On the left side search I my currency.
                          I click on the currency with the right mouse button, and choose "Backtest".

                          Comment


                            #14
                            doc11,

                            There is a bug which may be related to what you are experiencing that will be addressed in the next version. Please try again then. Thank you.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              When will a new version published.
                              If the bug too in the Lifetrading version?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              10 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              242 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              387 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Working...
                              X