Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetTrailStop does not work when Mode is Currency

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

    SetTrailStop does not work when Mode is Currency

    Hi there,

    I have coded a strategy that has the following code in the OnBarUpdate event:

    Code:
    if (_triggerIdentified)
    {
        EnterShort(_numberOfContracts, shortTradeID);
        SetTrailStop(shortTradeID, _trailingStopAndProfitCalculationMode, _beginTrailingStopDistance, false);
        if (_profitTarget > 0)
        {
            SetProfitTarget(shortTradeID, _trailingStopAndProfitCalculationMode, _profitTarget);
        }
    }
    shortTradeID = "ShortTradeID";
    _trailingStopAndProfitCalculationMode = CalculationMode.Currency;
    _beginTrailingStopDistance = 500;
    _profitTarget = 0;

    The Short Entry happens, but a stop is never set. If however I change the CalculationMode to CalculationMode.Ticks, and change the value to 20 it works fine.

    Why is it that CalculationMode.Currency doesn't work. I am assuming that when in Currency mode the value should be the dollars I want to risk loosing, is this correct?

    Regards,

    Scott

    #2
    Hello Scott,

    Yes, you are correct. The CalculationMode.Currency is an amount of loss in dollars.

    Are you getting any error messages or messages in the Output Window?

    If you set TraceOrders to True, are you able to see that the order is being ignored?

    If so, please post the message you are seeing.


    What is the value of _beginTrailingStopDistance when the order is placed?
    What is the value of _beginTrailingStopDistance when SetTrailStop is called? (These may not be the same because SetTrailStop is set after the order is placed.)


    Also, I want to mention that you are setting the trail stop after the order is placed. This means that when a new order is placed, the script will first use the old setting of SetTrailStop and then this gets modified afterward. SetStopLoss / SetTrailStop / SetProfitTarget should always be called before the order is placed. (Even if you plan to modify them after.)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ChelseaB,

      Thanks for the response mate, and the great info when to set stops and profits.
      I will create a simplified strategy tonight and see if I can replicate the issue. I will update this post with the details.

      Regards,

      Scott

      Comment


        #4
        ChelseaB,

        Ok took me a little while to get back to this, but I have now created a simple strategy that demonstrates the issue. I basically just places a short position on bar# 50 with a trailing stop, and the trailing stop never gets set.

        Replication Steps:
        1) Add the attached TestTrailingStopsStrategy.cs to NT8.
        2) Load chart that has a least 50 bars of data.
        3) Apply TestTrailingStopsStrategy.

        You will see position is entered at bar 50, but no trailing stop is placed.

        Here is the OnBarUpdate event hander:
        Code:
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 50) {
                SetTrailStop("TestTradeID", CalculationMode.Currency, 500, false);
                EnterShort(1, "TestTradeID");
            }
        }
        I am assuming that this is the correct way to set a trailing stop before the position?

        Thanks for your time,

        Regards,

        Scott
        Attached Files

        Comment


          #5
          Hello Scott,

          Thank you for supplying the script for me to test.

          I received an error message when I enabled TraceOrders. The initial stop distance may be incorrectly calculated when the order is placed.

          I am currently inquiring with development to see what the expected behavior is and if this should be reported as a bug.

          Are you getting any error messages or messages in the Output Window?

          If you set TraceOrders to True, are you able to see that the order is being ignored?

          If so, please post the message you are seeing.

          Below is a link to the help guide on enabling TraceOrders.
          http://ninjatrader.com/support/helpG...raceorders.htm
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            ChelseaB,

            Thanks for the response mate. I check the Output Window and yes there is an error there:

            Enabling NinjaScript strategy 'TestTrailingStopsStrategy/63780009' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes

            I set TraceOrders to true in the SetDefaults state of the strategy, and recompiled without error, then turned the strategy off, then cleared the NinjaScript output window and then turned the strategy back on, and it produced the same line again in the output window:

            Enabling NinjaScript strategy 'TestTrailingStopsStrategy/63780009' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes

            Regards,

            Scott

            Comment


              #7
              Hello Scott,

              This particular message is not an error message but simply informational that your strategy has started. This lists the properties set with the strategy as it is enabled.

              The error I am seeing appears when the entry order is placed (and not as the strategy is enabled).

              The message I am seeing is:
              Strategy 'TestTrailingStopsStrategy/63992971': Calculated trail stop order price was smaller/equal 0. No trail stop order placed.

              Are you receiving any errors that appear only when the entry order is placed (at the time the trail stop is actually submitted)?


              I have reported the behavior to our development. This issue is being tracked with #NTEIGHT-9265.
              Last edited by NinjaTrader_ChelseaB; 01-12-2016, 09:24 AM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                ChelseaB,

                Thanks for sending to the Dev Team.

                The only thing I am seeing in the NinjaScript Output Window, including when the trailing stop should have been placed, is what I posted in my last message.

                Regards,

                Scott.

                Comment


                  #9
                  Hi Scott,

                  If you are not getting any further output in the output window, this means that TraceOrders is not set to true or that you have not removed the script and re-added this. (Any change to State.SetDefaults in NT8 or Initialize() in NT7 requires that you remove and re-add the script to a chart for those changes to take affect.

                  If TraceOrders is set to true and the script has been removed and re-added and there is still no further output in the output window, this means that no entry order is being placed.
                  The entry order will also appear in the output window when TraceOrders is set to true.

                  Below is a video I've created this to provide to development that highlights the issue.
                  http://screencast.com/t/r1gJnnjOyXE

                  Also, here is a video of me running the script you have supplied with only one single modification. I set TraceOrders to true.
                  http://screencast.com/t/Y8z0XRAMplF


                  Last, I wanted to mention I am currently working with our Product Management to understand what the behavior should be with this newly introduced item (This usage was not available to NinjaTrader 7). This item is being tracked with ID# NTEIGHT-9265.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    ChelseaB,

                    First of all let me say, stella effort with the videos mate!!! Absolutely fantastic support, thanks for your efforts!!

                    I did have TraceOrders enabled, but the key was removing the strategy and re-adding. I was just enabling and disabling. As soon as I removed and re-added, I saw the same output as you. However I don't see any trace of the trailing stops it says it has entered in the chart window. I should say I am only looking at historical data, as the strategy places the position and trailing stop after the first 50 bars. But you can't actually see the stop anywhere on the chart. Also we discussed weather the value parameter when using CalculationMode.Currency was the amount you are willing to loose, but I didn't ask if it was the total based on the number of contracts you had in that order, or it was the distance in price from the entry price of the order? Maybe that is why it doesn't show up.... as $500 away from the entry price would be as they say.... of the chart mate?

                    See the attached pic:



                    Here is the entire order duration:



                    Again, thanks for your effort mate ;-)

                    Regards,

                    Scott

                    Comment


                      #11
                      Hello Scott,

                      Do you have the Chart Trader area open on your chart?

                      You will not see any working orders made by the strategy unless this is open.
                      (Filled orders will show, but working orders do not unless chart trader is open)

                      I am not able to view your screenshots. Can you zip these screenshots and then attach the zip file?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        ChelseaB,

                        Hey mate... that would be right... I do a quick google, find an image sharing service.. and they disappear straight after I share an image...

                        I have attached a zip. No I didn't have the Chart Trader open. But I am not evaluating in real time... the strategy just places a trade after the first 50 bars, which it identifies in the first day of the historical data in the chart with 5 days of data. I don't see any stop on the chart for that one position, and that trade get's close on market close.

                        So are you saying that historical stops will not show, unless there will executed? If so that would explain it.

                        Regards,

                        Scott
                        Attached Files

                        Comment


                          #13
                          Hello Scott,

                          Historical executions will only show on the chart if the order filled and there is an execution.

                          There is not a way to represent orders in a working state as well as all of the modifications before they have filled historically.

                          This may be possible using a script, but this would clutter up the screen with where working orders were and where they have been modified along with where they have filled.


                          If you are running live and you live a working order, this will only show on the chart if Chart Trader is open and the account selected on this is the same account that the order is working on. Once the order fills, the working marker from chart trader (on the right of the chart) will disappear and there will be an execution marker on the bar on the chart where the execution took place.

                          This is the same as in NinjaTrader 7.
                          I recommend that you watch the training videos for NinjaTrader 7 to get familiar using NinjaTrader.
                          Order Entry - https://www.youtube.com/watch?v=IZmV...56536A44DD7105
                          Charting - https://www.youtube.com/watch?v=V8d6...56536A44DD7105

                          There will be some differences between NinjaTrader 7 and NinjaTrader 8, however, in neither platform are you able to see orders in a working state historically. You will only be able to see a working order from the chart trader area when that order is still in a working state. After it fills it is no longer shown with chart trader on the right of the chart and becomes an execution marker. Again this is the same in both versions.
                          Last edited by NinjaTrader_ChelseaB; 01-14-2016, 05:13 PM.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            ChelseaB,

                            Thanks for the great advise mate. I will check out the vids. This all makes sense now.
                            (except of course for the issue you have sent to the dev team ;-)

                            Regards,

                            Scott

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by lorem, Today, 09:18 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post lorem
                            by lorem
                             
                            Started by hazylizard, Today, 08:38 AM
                            4 responses
                            11 views
                            0 likes
                            Last Post hazylizard  
                            Started by geddyisodin, Today, 05:20 AM
                            2 responses
                            20 views
                            0 likes
                            Last Post geddyisodin  
                            Started by Max238, Today, 01:28 AM
                            5 responses
                            47 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Started by giulyko00, Yesterday, 12:03 PM
                            3 responses
                            13 views
                            0 likes
                            Last Post NinjaTrader_BrandonH  
                            Working...
                            X