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

Backtest on intrabar strategy with setstoploss

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

    Backtest on intrabar strategy with setstoploss

    Hello everyone,

    I'm trying to develop and backtest a strategy with intrabar granularity.
    I followed example at this link: http://www.ninjatrader.com/support/f...ead.php?t=3572

    This sample script works with two DataSeries objects: primary and secondary.
    In backtest environment It works fine for entry position. In fact I've found long and short position placed in intrabar time.

    The problem is on CloseOrder logic!

    My closeorder logic is done by SetTrailStop or SetProfitTarget methods.

    When I check my report I notice that all closeorder follow only primary DataSeriers and not secondary Dataseries. It seems that all orderclose are exactly placed at the ends of each minute.

    In my script the primary DataSeries is 1 Minute Bars and the secondary Dataseries is 1 Tick.

    Before to create my orderclose method without use SetTrailStop and SetProfitTarget
    I'd like to know if there is a better solution.

    thanks in advance

    #2
    Hello ealterani,

    Was that example helpful to you?

    We do have an intra-bar granularity sample you may find helpful..
    http://www.ninjatrader.com/support/f...ead.php?t=6652

    I think that if you add the secondary series not as a custom data series as is shown in that example, but as a series where you use the same primary instrument and just change the interval and this will cause the stop loss and profit target to work for the secondary series.

    For example:

    Add(PeriodType.Tick, 1);

    Should be all that is needed to add the secondary series using the same primary instrument but with a 1 tick interval.

    This would also allow both data series to fill the exit order.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry I've indicated an incorrect link for sample script. I saw that script it's the same that I've followed. I've tried to use Add(PeriodType.Tick, 1); but it doesn't work because OnBarUpdate() is not invoked.
      Instead if I use the overload method
      ( Add("$EURUSD",PeriodType.Tick,1,MarketDataType.Bid ); ) It works.

      I can manage two BarsInProgress both primary and secondary series. In primary I get High[1], in secondary series I execute logic for entry order.

      All work fine for entry order.

      The problem is that setTrailstop or setProfitTarget are executed always on primary series. So exactly on the end of the minute. for example 10:23:00 , 21:34:00 .....

      For more information: SetTrailStop SetProfitTarget and are set in Initialize().

      Thanks in advance
      Enrico

      Comment


        #4
        Hello ealterani,

        You cannot call Add() in OnBarUpdate. This has to be done in Initialize(). This is mentioned in the help guide on Add().

        http://www.ninjatrader.com/support/h...s/nt7/add3.htm

        You do need to use Add(PeriodType.Tick, 1); for this to work.


        Also, I haven't seen that using Add(PeriodType.Tick, 1); causes any issues when used in Initialize().

        Can I see a screenshot of the error you get when using this?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          OK, I've attached three files:

          - File Script_immage.png (My script)
          - Flle backtest_immageRUN1.png (backtest run with Add ("$ EURUSD", PeriodType.Tick, 1, MarketDataType.Bid);
          - File backtest_immage_RUN2.png (backtest run with Add(PeriodType.Tick, 1); )

          inside of the files you will find the notes I added

          Thanks in advance
          Attached Files

          Comment


            #6
            Hello ealterani,

            Are you getting any error messages in the Log tab of the Control Center?

            If so, what do these error messages say?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              No, no there is not error log.

              If I Run with Add("$EURUSD",PeriodType.Tick,1,MarketDataType.Bid ); it work but The problem is that setTrailstop or setProfitTarget are executed always on primary series. So exactly on the end of the minute. for example 10:23:00 , 21:34:00 .....

              If I run with Add(PeriodType.Tick, 1); nothing happens.

              In both cases there are no error log.

              Attached tab log screenshot.

              Thanks in advance
              Attached Files

              Comment


                #8
                Hello ealterani,

                Does your connection provide historical tick data?

                Who are you connected to?


                Attached is a test script that is working on my end.
                Does this script make any prints on your end?
                Attached Files
                Last edited by NinjaTrader_ChelseaB; 03-18-2015, 01:47 PM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Done, It's the same.
                  No log was printed!

                  Your test script is equal to my script.

                  I downloaded tick data from http://www.histdata.com/ provider at this link:


                  I've imported in ninja only Bid_tick_data with Generate Minute and day bars option flag to true.

                  I'm trying to test forex EURUSD pair.

                  Thanks in advance

                  Comment


                    #10
                    Hello ealterani,

                    So to confirm, you are not connected to a data provider that provides tick data.

                    You have imported data, have you verified the data imported correctly?

                    Did the imported data have the correct file and content format (historical data has to have a very specific format to import correctly)

                    If you open a $EURUSD 1 tick chart do you see all of the ticks for the entire period you are testing over?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I'm not connected to data provider.

                      Yes, I've verified my data imported correctly.

                      Now, I also imported ask_tick_data e last_tick_data. After this, your script print correctly output. My script also work now. I've run it with Add(PeriodType.Tick, 1);

                      but the problem remains.
                      setTrailstop or setProfitTarget are executed always on primary series. So exactly on the end of the minute.

                      Comment


                        #12
                        Hello ealterani,

                        Can you take a screenshot of a 1 tick $EURUSD chart on your system?

                        To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

                        Click here for instructions

                        Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

                        Click here for detailed instruction

                        That should be all that is necessary to have the example script (which is working perfectly on my end) to print to the output window.

                        May I also ensure that you have enabled the script?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          May I also ensure that you have enabled the script?
                          what you mean to enable a script? what should i do? I just compiled and run a backtest.

                          Attached screenshot and my script.
                          Attached Files

                          Comment


                            #14
                            Hello ealterani,

                            I'd like to schedule a call with you to assist.

                            Please send an email to platformsupport [at] ninjatrader [dot] com. In the email please include a link to this forum thread.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Ok, I've replied by mail.
                              Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Perr0Grande, Today, 08:16 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Perr0Grande  
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post quantismo  
                              Working...
                              X