Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optimalisation with double in ExitLongLimit-order

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

    Optimalisation with double in ExitLongLimit-order

    Hi all,

    I noticed strange behaviour while backtesting/optimizing my strategy.

    This is my code for the trail:

    Code:
    //Trailing Stop during for LLA1
                if (BESetLLA1 == true && ExistLLA1 == true && Close[0] > Close [1] 
    //                &&     Close[0] > (entryOrder50.AvgFillPrice + ([COLOR=Red][B]330[/B][/COLOR]* TickSize))
                    )   
                    {
                    stop50 = ExitLongLimit(1,true, DefaultQuantity, Close[0]-[COLOR=Red][B]20[/B][/COLOR]*TickSize, "trailStopLLA1", "LLA1");
                    Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " Traitrl LLA 1 adjusted to " + (Close[0]-(111*TickSize)));
                    }
    I would now like to optimize the range of the trail, so I replaced that red '20' by a double 'Tr' (that I gave a value of 20) so I could enter a range to be tested in the optimizer. I do however see differences between the two versions.

    Eventually I would also like to optimize the distance above my entry where my trail should kick in (the red '330'), but I noticed the same problem)


    Screenshot one is a chart with the red 20 still in place, and screen 2 with the red 20 replaced by the 'Tr'. How come it closes at a different level ?? (FYI: I tried putting the calculation between brackets Close[0]-(Tr*TickSize), but that didn't help)
    Attached Files
    Last edited by Spinn; 07-14-2016, 01:30 AM.

    #2
    Hello Spinn,

    Thank you for writing in.

    To clarify, are you ensuring that you have selected the optimizer result that has the Tr parameter set at 20 and comparing to a backtest with a hard-coded value of 20?

    Are you connected to live data when comparing the backtest and the optimization? When disconnected and running both again, do the values match up?
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your time and effort, NinjaTrader_ZacharyG. Appreciated

      First of all: I noticed the discrepancy between 'Tr' and '20' when I ran my strategy on a chart (I always have one open when I'm writing code and from time to time I compile and 'F5' the chart to verify if everything still works) So, to clarify even further: I did not get to the step of optimizing yet, because I figured the results would be strange, judging by the differences I saw on a simple chart.

      I attached 4 screenshots:

      Two of them are when I ran the strategy on a chart while being connected to an FXCM Demo account and the other two while connected to 'Simulated Data Feed'.

      Furthermore: I tried 20 and Tr on both. The filenames of the screens speak for themselves

      UPDATE: I tried the same thing in the optimizer and it seems the problem does not exist there. Is this due to the inner workings of NT7 and should I just ignore what I see on a 'simple chart' and ALWAYS look at the optimizer only ??
      Attached Files
      Last edited by Spinn; 07-26-2016, 11:48 AM.

      Comment


        #4
        Hello Spinn,

        Can you print out the value of Tr before your ExitLongLimit() method so we can ensure that it is, indeed, set to 20?
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          This code:

          Code:
          //Trailing Stop during for LLA1
                      if (BESetLLA1 == true && ExistLLA1 == true && Close[0] > Close [1] && Close[0] > (entryOrder50.AvgFillPrice + (BE * TickSize)))   
                          {
                          stop50 = ExitLongLimit(1,true, DefaultQuantity, Close[0]-Tr*TickSize, "trailStopLLA1", "LLA1");
                              [B][COLOR=Red]Print ("Tr = " + Tr);[/COLOR][/B]
          //                stop50 = ExitLongStopLimit(1,true, DefaultQuantity, (Close[0]-(25*TickSize)), (Close[0]-(45*TickSize)), "trailStopLLA1", "LLA1");
                          Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " Trail LLA 1 adjusted to " + (Close[0]-(111*TickSize)));
                          }
                      // Breakeven for LLA1
                      if (initialSetLLA1 && !BESetLLA1 && ExistLLA1 == true && Close[0] >= entryOrder50.AvgFillPrice + (350 * TickSize))
                          {
                          Print("BE entryOrder50.AvgFillPrice = " + entryOrder50.AvgFillPrice);
                          Print("BE Position.AvgPrice = " + Position.AvgPrice);
                          stop50 = ExitLongStop(1,true, DefaultQuantity, Close[0]-30*TickSize, "BEstopLLA1", "LLA1");
          //                  stop50 = ExitLongStopLimit(1,true, DefaultQuantity, (Close[0]-40*TickSize), (Close[0]-20*TickSize), "BEstopLLA1", "LLA1"); 
                            BESetLLA1 = true;      // set BE stop once
                          Print(Time[0].ToString("dd/MM/yyyy") + ",  " + Time[0].ToString("HH:mm:ss") +  " BE LLA 1 set @ " + (entryOrder50.AvgFillPrice));
                                      }
          yields this output:

          3-2-2016 3:00:58 | name: initialStopLLA1 | order state: Working | current price: 172,665 | stop price: 172,155 | limit price 172,13
          03-02-2016, 03:00:58 $ $ $ Open PnL: 314,999999999998
          3-2-2016 3:01:07 | name: initialStopLLA1 | order state: Working | current price: 172,73 | stop price: 172,155 | limit price 172,13
          03-02-2016, 03:01:07 $ $ $ Open PnL: 379,999999999995
          BE entryOrder50.AvgFillPrice = 172,35
          BE Position.AvgPrice = 172,35
          3-2-2016 3:01:07 Entered internal PlaceOrder() method at 3-2-2016 3:01:07: BarsInProgress=1 Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=172,70 SignalName='BEstopLLA1' FromEntrySignal='LLA1'
          03-02-2016, 03:01:07 BE LLA 1 set @ 172,35
          3-2-2016 3:01:52 | name: BEstopLLA1 | order state: Working | current price: 172,795 | stop price: 172,7 | limit price 0
          03-02-2016, 03:01:52 $ $ $ Open PnL: 444,999999999993
          3-2-2016 3:01:52 Entered internal PlaceOrder() method at 3-2-2016 3:01:52: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=172,77'5 StopPrice=0 SignalName='trailStopLLA1' FromEntrySignal='LLA1'
          Tr = 20
          03-02-2016, 03:01:52 Trail LLA 1 adjusted to 172,684
          3-2-2016 3:01:52 Cancelled pending exit order, since associated position is closed: Order='NT-00023/Sim101' Name='BEstopLLA1' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=172,7 Quantity=1 Strategy='LiSL210Test' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5faa352ad3434e0f814917d60c45fcfb' Gtd='1-12-2099 0:00:00'
          3-2-2016 3:01:52 Cancelled pending exit order, since associated position is closed: Order='NT-00022/Sim101' Name='initialStopLLA1' State=Working Instrument='$GBPJPY' Action=Sell Limit price=172,13 Stop price=172,155 Quantity=1 Strategy='LiSL210Test' Type=StopLimit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='85897febe392407b90ae4f836661ec52' Gtd='1-12-2099 0:00:00'
          03-02-2016, 03:01:52 Stop50 filled at 172,775
          03-02-2016, 03:01:52 Long Lime Arrow 1 Flat, so SL reset
          entry50 nul
          I am also sharing thoughts with NinjaTrader_ChelseaB in this post (http://ninjatrader.com/support/forum...ad.php?t=87099), hence why there are multiple print statements and different lines of Stop-Orders (albeit commented out) present. Sadly this is not the only issue I'm facing atm

          Thanks again for your consideration !

          Comment


            #6
            Hello Spinn,

            If all that is changed between the two strategies is the use of a variable vs. a hard coded value for setting ExitLongLimit(), I would expect that both strategies would behave the same if the value of the variable and the hard coded value are the same in a backtest.

            I would like to test your strategy on my end.

            Please follow the instructions below to export your strategy.

            To export your script do the following:
            1. Click File -> Utilities -> Export NinjaScript
            2. Enter a unique name for the file in the value for 'File name:'
            3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
            4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


            By default your exported file will be in the following location:
            • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


            Below is a link to the help guide on Exporting NinjaScripts.
            http://www.ninjatrader.com/support/h...nt7/export.htm

            If you would rather your strategy not be available publicly, you can send us an email at platformsupport [at] ninjatrader [dot] com. Please ensure to reference the ticket number 1543713 as well as my name in the body of your email.

            I look forward to assisting further.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              I actually mailed the strategy to platformsupport right before your last post here. I did that because NinjaTrader_ChelseaB asked so. She's working on another issue. I suppose you can finde it there as well

              Comment


                #8
                Hello Spinn,

                As a heads up, I have not yet received the strategy in question.

                Can you please resend this?

                May I confirm you are including a link to the originating forum thread with your email?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I just tried again. No error or 'message not sent'.


                  I did include the link

                  Comment


                    #10
                    Hello Spinn,

                    I have not yet received your email.

                    When you send an email to platformsupport [at] ninjatrader [dot] com you will receive an auto-reply letting you know that your email was received and that a technician will be with you shortly.

                    Are you getting this auto reply message?

                    Are you sending this email from your email or from the Control Center?

                    (Are you replacing the [at] with the @ symbol and the [dot] with a . ?)

                    If the file is large, try sending this via wetransfer.com.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      So far I tried sendig three different mails (all from a Gmail account and to platformsupport [AT] ninjatrader [DOT[ com)

                      • The first one errored out, because your email-server discovered a 'virus' in the .zip file you asked for :
                      Delivery to the following recipient failed permanently:

                      platformsupport [AT] ninjatrader [DOT] com

                      Technical details of permanent failure:
                      Google tried to deliver your message, but it was rejected by the server for the recipient domain

                      The error that the other server returned was:
                      550 5.7.1 Virus found.
                      • Secondly, I unpacked the .zip and put the four separate files in attachment, hoping that this would work. I received no error, but you told me the mail never arrived (see screenshot) (I mistakingly had the idea that the Google-server refused tot send, but the problem is on the NT-server appartently)
                      • Same for the third (that I sent 3 hours ago)
                      • I NEVER received an auto-reply (although I did get those in the past)

                      Is it possible that my mails DO go through (since I get no delivery failure), but they end up in a blacklisted folder or so ??

                      Attached Files
                      Last edited by Spinn; 08-02-2016, 01:22 PM.

                      Comment


                        #12
                        Hello Spinn,

                        I have not seen that an email with a link to this forum thread has been received with anyone on our team.

                        May I confirm you have attempted to use wetransfer.com as I have previously suggested?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Sent via WeTransfer (and received confirmation email)

                          EDIT: also received automatic confirmation from your server
                          Last edited by Spinn; 08-06-2016, 05:38 AM.

                          Comment


                            #14
                            Hello Spinn,

                            I have received the script via wetransfer.

                            I will test the script and report back with what I find.
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by DJ888, 04-16-2024, 06:09 PM
                            6 responses
                            18 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by Jon17, Today, 04:33 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post Jon17
                            by Jon17
                             
                            Started by Javierw.ok, Today, 04:12 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post Javierw.ok  
                            Started by timmbbo, Today, 08:59 AM
                            2 responses
                            10 views
                            0 likes
                            Last Post bltdavid  
                            Started by alifarahani, Today, 09:40 AM
                            6 responses
                            41 views
                            0 likes
                            Last Post alifarahani  
                            Working...
                            X