Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

basic profit target orders cause major malfunctions.

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

    basic profit target orders cause major malfunctions.




    people with nt,



    a few days ago i started looking at profit target orders. however, incorporating this kind of orders to strategies of mine causes the nt platform to malfunction when running optimization processes.


    i have attached a sample strategy with stop loss orders that produces the results i will document next.

    [ATTACH]n1236398[/ATTACH]


    first i left the ema indicator as the only criterion to open and close positions and ran optimizations 1) without profit targets and 2) with profit target orders for all entries.


    these are the results for the 1 factor strategy without profit targets:


    Click image for larger version

Name:	202302 nt profit target failures 1 factor strategy r0002 i 0001.jpg
Views:	252
Size:	134.6 KB
ID:	1236394


    Click image for larger version

Name:	202302 nt profit target failures 1 factor strategy r0002 i 0002.jpg
Views:	209
Size:	214.5 KB
ID:	1236395



    and these are the results when every entry has both a stop loss and a profit target:


    Click image for larger version

Name:	202302 nt profit target failures 1 factor strategy r0001 i 0001.jpg
Views:	212
Size:	135.9 KB
ID:	1236396




    Click image for larger version

Name:	202302 nt profit target failures 1 factor strategy r0001 i 0002.jpg
Views:	210
Size:	217.5 KB
ID:	1236397

    #2



    the performance for the strategies above could be considered somewhat ugly but the most important result is that all optimization processes are successfully completed.



    i then activated - uncommented all 3 indicators inside the strategy, the stop loss orders and ran optimizations once again with and without profit targets.



    these are the results with 3 factors without profit targets:


    Click image for larger version  Name:	202302 nt profit target failures 3 factor strategy r0002 i 0001.jpg Views:	0 Size:	134.5 KB ID:	1236401


    Click image for larger version  Name:	202302 nt profit target failures 3 factor strategy r0002 i 0002.jpg Views:	0 Size:	215.4 KB ID:	1236402



    and these screengrabs below illustrate the issue, i keep getting frustrating optimization results that have been aborted before they have been completed and show just one single positive results and zeroes:


    Click image for larger version  Name:	202302 nt profit target failures 3 factor strategy r0001 i 0001.jpg Views:	0 Size:	123.7 KB ID:	1236403



    Click image for larger version  Name:	202302 nt profit target failures 3 factor strategy r0001 i 0002.jpg Views:	0 Size:	205.6 KB ID:	1236404




    everything is the same except for the profit target orders and the nt platform will malfunction badly. ¿how can this be fixed? ¿are there any samples of how to properly utilize profit target orders?


    Comment


      #3
      Hello rtwave,

      Thank you for your post.

      So I may better assist you, please answer the following:
      What version of NinjaTrader are you using? This may be found at Control Center > Help > About. (For example, 8.0.?.?)
      When you run the optimization that is introducing the unexpected results with zeroes, do you receive any errors on the screen or on the Log tab of the Control Center? If so, what do these errors report?
      What are the optimization settings you are using? Please provide screenshots demonstrating your settings before clicking on Run to start the optimization.

      I look forward to your reply.

      Comment


        #4



        NinjaTrader_Emily,



        these failed - aborted optimization processes are a recurrent issue that i have reported and documented abundantly. i have created multiple posts in these fora that can be found in my profile with ease.



        the nt version is 8.0.27.1 64-bit.



        there are no error messages logged anywhere on nt when the failed results are presented.



        and for the range over the which the inputs can be optimized: 5;60;1 for all periods, 1;30;1 for the adx, -0.5;0;.01 and 0;0.5;.01 for momentum respectively.


        Code:
        #region Using declarations
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.ComponentModel.DataAnnotations;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows;
        using System.Windows.Input;
        using System.Windows.Media;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Gui;
        using NinjaTrader.Gui.Chart;
        using NinjaTrader.Gui.SuperDom;
        using NinjaTrader.Gui.Tools;
        using NinjaTrader.Data;
        using NinjaTrader.NinjaScript;
        using NinjaTrader.Core.FloatingPoint;
        using NinjaTrader.NinjaScript.Indicators;
        using NinjaTrader.NinjaScript.DrawingTools;
        #endregion
        
        //This namespace holds Strategies in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Strategies
        {
            public class ntsamplestoplossprofittargetm : Strategy
            {
                private EMA EMA1;
                private Momentum Momentum1;
                private ADX ADX1;
        
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                                    = @"";
                        Name                                        = "ntsamplestoplossprofittargetm";
                        Calculate                                    = Calculate.OnBarClose;
                        EntriesPerDirection                            = 1;
                        EntryHandling                                = EntryHandling.UniqueEntries;
                        IsExitOnSessionCloseStrategy                = false;
                        ExitOnSessionCloseSeconds                    = 30;
                        IsFillLimitOnTouch                            = false;
                        MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                        OrderFillResolution                            = OrderFillResolution.Standard;
                        Slippage                                    = 1;
                        StartBehavior                                = StartBehavior.ImmediatelySubmitSynchronizeAccount;
                        TimeInForce                                    = TimeInForce.Gtc;
                        TraceOrders                                    = true;
                        RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelCloseIgnoreRejects;
                        StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                        BarsRequiredToTrade                            = 100;
                        // Disable this property for performance gains in Strategy Analyzer optimizations
                        // See the Help Guide for additional information
                        IsInstantiatedOnEachOptimizationIteration    = true;
                        Period                            = 9;
                        Momp                    = 20;                
                        Moml1                    = -.5;
                        Moml2                    = .5;
                        Adxp                    = 20;
                        Adxl                    = 30;
                        Contracts                = 1;
                        Stoploss                        = 60;
                        Profittarget                    = 60;
                    }
                    else if (State == State.Configure)
                    {
                    }
                    else if (State == State.DataLoaded)
                    {                
                        EMA1                = EMA(Close, Convert.ToInt32(Period));
                        Momentum1                = Momentum(Close, Convert.ToInt32(Momp));
                        ADX1                    = ADX(Close, Convert.ToInt32(Adxp));
                        SetStopLoss(@"shortposition", CalculationMode.Ticks, Stoploss, false);
                        SetStopLoss(@"longposition", CalculationMode.Ticks, Stoploss, false);
        //                SetProfitTarget(@"shortposition", CalculationMode.Ticks, Profittarget);
        //                SetProfitTarget(@"longposition", CalculationMode.Ticks, Profittarget);
                    }
                }
        
                protected override void OnBarUpdate()
                {
                    if (BarsInProgress != 0)
                        return;
        
                    if (CurrentBars[0] < 1)
                        return;
        
                     // Set 1
                    if ((Position.MarketPosition != MarketPosition.Short)
                        && (Close[0] < EMA1[0])
                        && (Momentum1[0] < Moml1)
                        && (ADX1[0] > Adxp))
                    {
                        EnterShort(Convert.ToInt32(Contracts), @"shortposition");
                    }
        
                    else
        
                         // Set 4
                        if ((Position.MarketPosition == MarketPosition.Long)
                             && (Close[0] < EMA1[0]))
                        {
                            ExitLong(Convert.ToInt32(Contracts), @"exitlongposition", @"longposition");
                        }
        
        
                     // Set 3
                    if ((Position.MarketPosition != MarketPosition.Long)
                        && (Close[0] > EMA1[0])
                        && (Momentum1[0] > Moml2)
                        && (ADX1[0] > Adxp))
                    {
                        EnterLong(Convert.ToInt32(Contracts), @"longposition");
                    }
        
        
                    else
        
        
                         // Set 2
                        if ((Position.MarketPosition == MarketPosition.Short)
                             && (Close[0] > EMA1[0]))
                        {
                            ExitShort(Convert.ToInt32(Contracts), @"exitshortposition", @"shortposition");
                        }
        
        
        
                }
        
                #region Properties
        
                [NinjaScriptProperty]
                [Range(1, int.MaxValue)]
                [Display(Name="Period", Order=1, GroupName="Parameters")]
                public int Period
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(1, int.MaxValue)]
                [Display(Name="Momp", Order=2, GroupName="Parameters")]
                public int Momp
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(double.MinValue, double.MaxValue)]
                [Display(Name="Moml1", Order=3, GroupName="Parameters")]
                public double Moml1
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(double.MinValue, double.MaxValue)]
                [Display(Name="Moml2", Order=4, GroupName="Parameters")]
                public double Moml2
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(1, int.MaxValue)]
                [Display(Name="Adxp", Order=5, GroupName="Parameters")]
                public int Adxp
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(1, double.MaxValue)]
                [Display(Name="Adxl", Order=6, GroupName="Parameters")]
                public double Adxl
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(1, int.MaxValue)]
                [Display(Name="Contracts", Order=7, GroupName="Parameters")]
                public int Contracts
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(1, int.MaxValue)]
                [Display(Name="Stoploss", Order=8, GroupName="Parameters")]
                public int Stoploss
                { get; set; }
        
                [NinjaScriptProperty]
                [Range(1, int.MaxValue)]
                [Display(Name="Profittarget", Order=9, GroupName="Parameters")]
                public int Profittarget
                { get; set; }
        
                #endregion
        
            }
        }
        
        ​

        Comment


          #5
          Hello rtwave,

          Thank you for your patience.

          Please share your script as an export so I may import it into my platform and test the optimization to see if I get the same results. To export, go to Control Center > Tools > Export > NinjaScript AddOn. This should allow you to name the .zip file which may then be attached to your reply here in the forum. Please also advise the exact settings you are using for the optimization that fails. A screenshot (or multiple screenshots if you need to scroll down to display more) of the Strategy Analyzer page before clicking "Run" would be helpful so I can replicate the same optimization as you are using.

          Additionally, who is your data provider and are you connected to data while running the optimization?

          I look forward to your reply.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          72 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X