• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Interpreting the code

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

    Interpreting the code

    Hi,

    Does the code below mean exit long if the previous low violates the 3 day DonchianChannel with a displacement by 1?

    if (Low[-1] < DonchianChannel(3).Lower[1])
    {
    ExitLong("", "");
    }

    Thanks
    Last edited by JT1230; 05-24-2016, 08:19 AM.

    #2
    Hello,

    Thank you for the question.

    The current syntax would read:

    If the low of 1 bar into the future is less than the Lower plot of the DonchianChannel of 1 bar ago , Exit Long.


    I believe you would instead be needing the following syntax if you mean to use 1 bars ago.


    Code:
    if (Low[1] < DonchianChannel(3).Lower[1])
    {
    ExitLong("", "");
    }
    This would be, if the low of 1 bar ago is less than the Lower plot of the donchianChannel of 1 bar ago.

    BarsAgo values are all positive numbers although you are going backwards in time, for example a positive 10 would equal 10 barsAgo into the past.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Sorry, I'm confused. Say for example I want to exit long now as the three day low trailing stop has been breached. Is the code the same?
      Attached Files

      Comment


        #4
        Hello,

        Thank you for the reply.

        I am not certain I understand the question.

        Could you clarify the statement: as the three day low trailing stop has been breached

        Are you referring to the DonchianChannel as shown in the prior syntax or are you referring to a trailing stop that was not included in the example?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Sorry Jess, I think I've mix up the two concepts. What I want is to exit long when there is a break of 3-day low. ( just like what the chart has depicted)

          Comment


            #6
            Hello,

            Thank you for clairifing that.

            To check if the Current Close has crossed below the 3 day low of the DonchianChannel, you could use a statement like the following:

            Code:
            if(CrossBelow(Close,DonchianChannel(3).Lower,1))
            {
                 ExitLong("", "");	
            }
            CrossBelow can be used to detect if a Cross had occured within 1 bars ago.
            http://ninjatrader.com/support/helpG...sub=crossbelow

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              May I know what is the difference between Bars ago and Look-back period?
              Last edited by JT1230; 05-31-2016, 03:26 AM.

              Comment


                #8
                Sorry for troubling you again Jesse. Say if I want to print the word "execute" on to the Output window when Close[1]>Close[0]. Should I add anything under "protected override void Initialize()" as the word "execute" is nowhere to be seen.

                Comment


                  #9
                  Hello,

                  Thank you for the replies.

                  The difference between a BarsAgo and a Lookback period would simply be that one is a fixed point in time, the other is a period of time. A BarsAgo value is a single bar, so 10 bars ago will always be 10 bars ago from the current bar. A LookBack Period of say 50 would include the 50 bars from the start of the period to the end.

                  Regarding printing Strings to the output window, "execute" would be up to you to program if you want that printed.

                  A Print statement can take a string, so in the condition you could simply write:

                  Code:
                  if(Close[1] > Close[0])
                  {
                      Print("Execute");
                  }
                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    It seem that this code isn't working as I couldn't set the value of barsago in DonchainChannel if Crossabove/ below is used.

                    if(CrossBelow(Close,DonchianChannel(3).Lower,1)) { ExitLong("", ""); }

                    Comment


                      #11
                      Problem solved. Thanks alot Jesse. One last question, is it possible to do an action right after the condition is fulfilled? Say I want to enter long if ADX is 35, and I want it to execute immediately instead of entering on the next opening
                      Last edited by JT1230; 06-01-2016, 09:18 AM.

                      Comment


                        #12
                        Hello,

                        Thank you for the reply.

                        To enter at the time of the condition, you would likely need to utilize a 1 tick series and then also the timeframe used for the main part of the logic. If you do not need this to occur historically, you could see about using OnMarketData as well.

                        You can find an example of a multi timeframe script included with the platform, it is named SampleMultiTimeFrame.
                        You can find an example of OnMarketData here: http://ninjatrader.com/support/helpG...b=OnMarketData

                        Also you could try using CalculateOnBarClose = false, but this will effect the overall logic you are currently using by executing on 1 tick increments for all logic. In the case you need logic to happen for the primary time frame but then also execute logic on a tick by tick bases this is usually the most correct route to use a multi timeframe script.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by newuser, Today, 08:37 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post newuser
                        by newuser
                         
                        Started by bc24fl, Today, 06:51 AM
                        1 response
                        4 views
                        0 likes
                        Last Post NinjaTrader_Jim  
                        Started by U0000999, Yesterday, 05:17 AM
                        1 response
                        15 views
                        0 likes
                        Last Post NinjaTrader_Kate  
                        Started by asmmbillah, Today, 05:03 AM
                        5 responses
                        31 views
                        0 likes
                        Last Post NinjaTrader_PaulH  
                        Started by lordvader34, Today, 06:18 AM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_PaulH  
                        Working...
                        X