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

parabolic stop fails

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

    #16
    Hello David,

    Print the order object in OnOrderUpdate() so we can see what is happening with each order.
    Code:
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
    {
        Print(order.ToString());
    }​
    Save the output from the NinjaScript Output window by right-clicking the output window and select Save As.
    Attach the output text file with your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      ok, i added that line and ran it again. the new trace file is attached
      Attached Files

      Comment


        #18
        Hello David,

        I see this is historical (backtest) and not real-time. Note that Set methods, such as SetParabolicStop(), will update only On bar close in historical with the primary series only. This means that any trailing movements will only occur when the bar updates on bar close.

        I am also seeing that the parabolic stop was submitted after the last entry fill in the output.

        The entry filled at 4:20 PM at a price of 4537.

        orderId='NT-01313-10695' account='Backtest' name='Buy' orderState=Filled instrument='ES 03-23' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=4537 onBehalfOf='' id=-1 time='2022-01-31 16:20:00' gtd='2099-12-01' statementDate='2023-03-01'

        The parabolic stop was submitted at 4532 and became working.

        orderId='NT-01314-10695' account='Backtest' name='Parabolic stop' orderState=Working instrument='ES 03-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4532 quantity=1 tif=Gtc oco='NT-00862-10695' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-31 16:20:00' gtd='2099-12-01' statementDate='2023-03-01'

        The order price of the stop is updated at 4:30 PM to 3949

        orderId='NT-01314-10695' account='Backtest' name='Parabolic stop' orderState=ChangePending instrument='ES 03-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=3949 quantity=1 tif=Gtc oco='NT-00862-10695' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-31 16:20:00' gtd='2099-12-01' statementDate='2023-03-01'

        Are you calling SetParabolicStop() again in the code?

        This appears every 5 minutes in the output.

        The order was working at 3949 and then the end of the session occurs and cancels the order before the order price is touched.

        orderId='NT-01316-10695' account='Backtest' name='Exit on session close' orderState=Submitted instrument='ES 03-23' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-31 17:00:00' gtd='2099-12-01' statementDate='2023-03-01'

        orderId='NT-01314-10695' account='Backtest' name='Parabolic stop' orderState=Cancelled instrument='ES 03-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=3949 quantity=1 tif=Gtc oco='NT-00862-10695' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-01-31 16:20:00' gtd='2099-12-01' statementDate='2023-03-01'

        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hi Chelsea, the strategy code was created by your colleague, and the settings were matched to his test. All i did was add the prints you asked for (in blue). Everthing else was an add-on he sent me.

          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 ParabolicStopTest : Strategy
          {
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Enter the description for your new custom Strategy here.";
          Name = "ParabolicStopTest";
          Calculate = Calculate.OnBarClose;
          EntriesPerDirection = 1;
          EntryHandling = EntryHandling.AllEntries;
          IsExitOnSessionCloseStrategy = true;
          ExitOnSessionCloseSeconds = 30;
          IsFillLimitOnTouch = false;
          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
          OrderFillResolution = OrderFillResolution.Standard;
          Slippage = 0;
          StartBehavior = StartBehavior.WaitUntilFlat;
          TimeInForce = TimeInForce.Gtc;
          TraceOrders = true;
          RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
          StopTargetHandling = StopTargetHandling.PerEntryExecution;
          BarsRequiredToTrade = 20;
          // Disable this property for performance gains in Strategy Analyzer optimizations
          // See the Help Guide for additional information
          IsInstantiatedOnEachOptimizationIteration = true;
          }
          else if (State == State.Configure)
          {
          SetProfitTarget("", CalculationMode.Ticks, 20);
          SetParabolicStop("", CalculationMode.Ticks, 20, false, 0.02, 0.2, 0.02);
          }
          }

          protected override void OnBarUpdate()
          {
          if (BarsInProgress != 0)
          return;

          if (CurrentBars[0] < 1)
          return;

          // Set 1
          if ((Position.MarketPosition == MarketPosition.Flat)
          && (Close[0] > Open[0]))
          {
          EnterLong(Convert.ToInt32(DefaultQuantity), "");
          }

          }

          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice,
          int quantity, int filled, double averageFillPrice,
          OrderState orderState, DateTime time, ErrorCode error, string comment)
          {
          Print("___________________________________");
          Print(Convert.ToString(Times[0][0]));
          Print("The order: " + order.ToString());
          Print("The most current order state is: " + order.OrderState); // OrderState.PartFilled
          Print("This particular order update state is: " + orderState); // OrderState.Working

          }

          }
          }
          ​

          Comment


            #20
            Hello David,

            I am doing some testing to see if I am able to reproduce and will let you know what I find.

            I appreciate your patience.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hello trader3000a,

              Thank you for your patience on this.

              The ParabolicStop will be setting the stop price based on levels calculated on the ParabolicSAR as if the strategy was always in a position. This can mean that the stop price is updated to be further from the market.

              In testing, I am finding that the ParabolicStop order is able to update in the direction of the market as this moves in the direction of the position and fill, exiting the trade. (Meaning it will move up on each bar close as the market price moves up)

              Attached is the very simple test script, and the output produced.

              ParabolicStopTest_NT8.zip

              NinjaScript Output 3_17_2023 11_46 AM.txt

              Click image for larger version  Name:	2023-03-17_11-50-05.png Views:	0 Size:	83.7 KB ID:	1241108
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hi Chelsea,
                I downloaded your ParabolicStopTest posted yesterday, and ran it for 2023 ES 5 minute chart (connection is Rithmic for Ninjatrader). Attached are the screenshots with examples of failures and trace files.
                David
                Attached Files

                Comment


                  #23
                  Hello David,

                  I don't see what the issue is.

                  The parabolic stop is being filled when the price drops below the price of the order.

                  Is there something in the output numbers you are referring to?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hi Chelsea,
                    Here is a screenshot of a trade from your strategy. Your strategy sets the intial level of the parabolic stop at 20 ticks below any BUY order (5 ES points/$250 ES) once an order is triggered.

                    There is a buy order at 9:50am at the price of 4042.00.
                    The initial level of the parabolic stop at 20 ticks below the buy order should be 4037.
                    Between 10:20 and 11:30, price touches that level (4037) 9 times but fails to trigger a stop.
                    The trade continues to fail to the level 3987.50
                    At that point we see text telling us that a parabolic stop closed the trade at 3987.50 for a loss of 218 ticks (not 20 ticks), for a loss of $2725 (not $250 or better, a tick or 2 of slippage notwithstanding).

                    This is not an isolated example.

                    thanks,
                    David
                    Attached Files

                    Comment


                      #25
                      Hello David,

                      From the output, you should be seeing that the price of the parabolic stop is changing in OnOrderUpdate() with new data and moving lower.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Hi Chelsea,
                        My example is a long trade. Stops on long trades aren't supposed to move lower. They are only supposed to move up if they move at all.
                        David

                        Comment


                          #27
                          Hello David,

                          The stop would be set to the calculated price of the parabolicSAR, be that toward or away from the market.

                          "Although logic wise very similiar, this technique works different from the ParablicSAR indicator. The indicator will provide trailing stop levels 'always in the market' assuming a constant market position switch, either long or short (reversing). The SetParabolicStop() method in contrast will apply the same parabolic trailing technique sensitive to price acceleration to the custom strategy entry signal / position it is associated with."​


                          Below is a link to a video of testing this test script on ES 06-23 5 Minute on the date I am seeing in your screenshot March 9th.


                          To confirm, if you follow the steps exactly as shown in the video, the behavior is different?

                          May I confirm you are using 8.1.1.1?
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Segwin, 05-07-2018, 02:15 PM
                          14 responses
                          1,788 views
                          0 likes
                          Last Post aligator  
                          Started by Jimmyk, 01-26-2018, 05:19 AM
                          6 responses
                          837 views
                          0 likes
                          Last Post emuns
                          by emuns
                           
                          Started by jxs_xrj, 01-12-2020, 09:49 AM
                          6 responses
                          3,293 views
                          1 like
                          Last Post jgualdronc  
                          Started by Touch-Ups, Today, 10:36 AM
                          0 responses
                          12 views
                          0 likes
                          Last Post Touch-Ups  
                          Started by geddyisodin, 04-25-2024, 05:20 AM
                          11 responses
                          62 views
                          0 likes
                          Last Post halgo_boulder  
                          Working...
                          X