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

Look Back Period

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

    Look Back Period

    I am having a problem with ‘look back period’ in Strategy Wizard.
    Using the same example “Condition Builder –Cross Over Conditions” in the help section. This is what I am trying to do.
    When a Cross Over occurs in the current bar, I want a trade triggered in the next coming bar (not the current one). I have entered the value 1 in the ‘Bars Ago’ parameter and a ‘look back period’ of 2. Unfortunately this doesn’t seem to work.
    I also have ‘On bar close’ unchecked (as I need some of my conditions to be executed in current bars)
    Some guidance would be much appreciated. Apologies in advance if this is a basic question.
    Thanks

    #2
    When backtesting, all orders will occur in the next bar. Your signal bar is already closed so you will not be able to trade on them. CalculateOnBarClose only has an effect in realtime trading.

    Using a lookback of 2 for CrossAbove/Belows simply means that the crossover can occur 2 bars back instead of just immediately here on the signal bar. It covers the whole range and not just 2 bars ago.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh for the reply.

      I am not backtesting, this is in real time trading.

      So my question is if I have 'On Bar Close' unchecked in realtime trading, how can I initiate a trade in the following bar if a cross over signal occurs in the current bar?

      Comment


        #4
        You can set a flag. Something like this may work.

        Code:
        if (Close[0] > Open[0])
             flag = true;
        
        if (flag && FirstTickOfBar)
        {
             EnterLong();
             flag = false;
        }
        Note: untested code
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh for the code, please bear with me as my questions are rather basic. I have 10 Conditions in my strategy, and I need to execute the order in the bar following the signal being triggered in only 2 of the conditions.
          Would I be correct if I insert your code at the bottom of each of the 2 condition sets it should work on only those sets?
          (My programming skills are not good as you see) So before I leave the safety of the Strategy Wizard, why does changing the parameter ‘Bars Ago’ from 0 to 1 not have the effect of initiating the trade in the next coming bar?

          Comment


            #6
            I do not know which Bars Ago parameter you are changing as there can be many. Also, bars ago of 0 means current bar. If you use 0 it is the latest information you have. Using 1 means previous bar not next bar. To get the next bar you don't do explicitly, you just wait for the next bar to open.

            If you require only 2 conditions to be true at the same time before you enter in the next bar you need to set two flags.

            Code:
            if (condition 1)
                 flag1 = true;
            
            if (condition 2)
                 flag2 = true;
            
            if (flag1 && flag2 && FirstTickOfBar)
            {
                 EnterLong();
                 flag1 = false;
                 flag2 = false;
            }
            else if (FirstTickOfBar)
            {
                 flag1 = false;
                 flag2 = false;
            }
            Again, not tested code.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I’ll give this a go, thanks again for your explanation and all your help!
              Regards
              John

              Comment


                #8
                Josh, quick question, where should the code be placed in the program?

                Comment


                  #9
                  In the OnBarUpdate() method. You may want to try some of the tutorials in the Help Guide first. http://www.ninjatrader-support.com/H...ogramming.html
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    thanks again Josh, I'll try and get my head around this!

                    Comment


                      #11
                      Originally posted by John833 View Post
                      Thanks Josh for the code, please bear with me as my questions are rather basic. I have 10 Conditions in my strategy, and I need to execute the order in the bar following the signal being triggered in only 2 of the conditions.
                      Would I be correct if I insert your code at the bottom of each of the 2 condition sets it should work on only those sets?
                      If you don't care which two of your ten conditions will trigger an order, just create a counter for the conditions. Start the counter at zero, and increment the counter each time one of the conditions is true. If you go through all the conditions and come out at the end with the counter 2 or greater, then you have an order trigger.
                      -Alex

                      Comment


                        #12
                        thanks for the tip

                        regards

                        john

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by wzgy0920, 04-20-2024, 06:09 PM
                        2 responses
                        26 views
                        0 likes
                        Last Post wzgy0920  
                        Started by wzgy0920, 02-22-2024, 01:11 AM
                        5 responses
                        32 views
                        0 likes
                        Last Post wzgy0920  
                        Started by wzgy0920, Yesterday, 09:53 PM
                        2 responses
                        49 views
                        0 likes
                        Last Post wzgy0920  
                        Started by Kensonprib, 04-28-2021, 10:11 AM
                        5 responses
                        192 views
                        0 likes
                        Last Post Hasadafa  
                        Started by GussJ, 03-04-2020, 03:11 PM
                        11 responses
                        3,234 views
                        0 likes
                        Last Post xiinteractive  
                        Working...
                        X