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

Re-running script doesn't work

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

    Re-running script doesn't work

    Hello,

    I'm a newbie and tried writing a very simple strategy. I am able to successfully write and execute a new strategy using the wizard. However, as soon as try to re-run the script with a new set of parameters, it executes with the original settings I used the first time! Why is that?

    Also, I can't seem to get the BarsSinceEntry function to trigger a new purchase. Here are the two conditions I setup using the script wizard:

    Code:
    protected override void OnBarUpdate()
            {
                // Condition set 1
                if (BarsSinceEntry() == BuyPeriod)
                {
                    EnterLong(DefaultQuantity, "");
                }
    
                // Condition set 2
                if (BuyAtStart == true
                    && Variable0 != 37)
                {
                    EnterLong(DefaultQuantity, "");
                    Variable0 = 37;
                }
    The second condition is the only way I could figure out how to start the strategy off with a purchase. My intent for the first condition is to trigger a purchase every X days where X = BuyPeriod which is a user entered integer parameter.

    Any help would be greatly appreciated!

    Thanks,
    Frustrated New User

    #2
    Hello jpmeyers,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    There would need to be a first entry before BarsSinceEntry() would work. Based on the code you provided there is no possible first entry. Your second condition is actually a great way to submit the first entry.

    For the strategy parameters can you detail the process you go through to enter the new parameters and re-run the strategy? Are you running the strategy in the Strategy Analyzer?

    I look forward to your response.

    Comment


      #3
      Patrick,

      Thank you for your quick response. I am confused about your answer for BarsSinceEntry(). When I run the sample code, it executes a long entry on the first bar. However, there are no subsequent long entries triggered after the first entry. Why is that? I ran the back test on about one year's worth of daily data, so I would expect to see about 35 long entries based on a BuyPeriod=7 initiation (what I was using to run the script). Here are the results from the trades log:

      Code:
      Trade-#    1
      Instrument    VOO
      Account    Backtest
      Strategy    MySecondStrat
      Market pos.    Long
      Quantity    1
      Entry price    137.98
      Exit price    168.21
      Entry time    2/2/2013
      Exit time    1/18/2014
      Entry name    Buy
      Exit name    Exit on close
      Profit    0.219089723
      Cum. profit    0.219089723
      Commission    0
      MAE    0.012755472
      MFE    0.227931584
      ETD    0.008841861
      Bars    243
      And here are the results from the settings tab for the backtest:

      Code:
      Item                     Value
      Parameters
      BuyAtStart               True
      BuyPeriod                7
      Data series
      Price based on         Last
      Type                   Day
      Value                  1
      Time frame
      From                   1/1/2013
      To                     1/20/2014
      General
      Include commission       False
      Label                    MySecondStrat
      Maximum bars look back   TwoHundredFiftySix
      Min. bars required       20
      Historical Fill Processing    
      Fill type                Default
      Slippage                 0
      Order Handling
      Entries per direction    1
      Entry handling           AllEntries
      Exit on close            True
      Order Properties
      Set order quantity       by strategy
      Time in force            Gtc
      As for the process I use to enter new parameters, here are the steps I take:

      1. I first execute the back test by right clicking on the security I want to test (i.e. VOO in the example above) and select "Backtest..."
      2. I fill in the parameters as I want them for the test and press the "Run Backtest" button. The first time through, this produces results I expect (except for the confusion above about why additional purchases aren't being triggered).
      3. When I want to re-run the backtest, I click on the sideways "backtest" button in the upper right hand corner which re-opens the parameters page with the parameters used the last time I executed the backtest.
      4. I then make changes to the parameters I want and press the "Run Backtest" button again. This time, the results don't change and when I look on the settings tab, the settings have reverted back to the values from the first test.

      Once again, thanks for your help.

      Comment


        #4
        Hello jpmeyers,

        Thank you for your response.

        Please attach you strategy to your response so I may investigate this matter further. you will find your strategy in the following directory on your PC: (My) Documents\NinjaTrader 7\bin\Custom\Strategy

        Comment


          #5
          Here's the script I was testing...
          Attached Files

          Comment


            #6
            Hello jpmeyers,

            Thank you for your response.

            The reason we only get one entry is because the EntriesPerDirection (http://www.ninjatrader.com/support/h...rdirection.htm) by default is one (1). Even if this is set to two (2) there are only two trades placed on the first day of the test, this is because the BarsSinceEntry is set to == instead of >=. With >= we do not need to use EntriesPerDirection, but it will only base it's entries off the first entry so you may wish to use entrySignalName strings for the entries.

            Please let me know if you have any questions.
            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,281 views
            0 likes
            Last Post Leafcutter  
            Started by WHICKED, Today, 12:45 PM
            2 responses
            19 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Tim-c, Today, 02:10 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Taddypole, Today, 02:47 PM
            0 responses
            5 views
            0 likes
            Last Post Taddypole  
            Started by chbruno, 04-24-2024, 04:10 PM
            4 responses
            53 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Working...
            X