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

Evaluate and DO NOTHING

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

    Evaluate and DO NOTHING

    Ok this is probably going to be a bit tricky to explain what I am going for here, but

    I have a SET 1 that will BUY - I have put AND OR conditions leveraging Groups
    I have a SET 2 that will sell based on similar reverse conditions...

    Now say I wan the prior bar to be assessed against the current bar before I BUY again
    For example, if my prior bar met an EXIT condition (Profit, Stop loss, Sell, ect.),

    I want to tell my Strategy to DO If the (Close, High, Low, ect) of the current bar is Less than the previous bar .... DO NOTHING and then repeat this evaluation process until there is a TRUE condition

    I have tried something like this in the SET1 as an IF ALL Default input [0]<BARSSinceExitExecution(0,@"Profit target",0), but seems this is evaluated against a DO of GO Long

    Without this I seem to be over trading and buying clearly were I shouldn't be....

    Hope this makes sense!


    #2
    Hello jstaft,

    With: "if my prior bar met an EXIT condition (Profit, Stop loss, Sell, ect.),"

    Only if the previous bar was the exit and not if the exit was more than 1 bar ago?

    The signal name provided must be the entry signal name not the name of the exit. Compare this with a numerical value set to 0 if Calculate on bar close, or 1 if Calculate on each tick or on price change.

    On the left select Misc -> Bars since exit, set Signal name to the name of the entry, select Misc -> Numeric value on the right, set the value 0.

    With: "If the (Close, High, Low, ect) of the current bar is Less than the previous bar "

    You want the current bar to be below the previous bar? If the high of the current bar is less than the low of the previous bar, the bar is completely below the previous bar.

    Select Price -> High on the left, select Less in the center, select Price -> Low on the right, and set the Bars ago for Low to 1 bar ago.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the response!

      I am a bit confused as to why for a "Bars Since Exit" I am defining the the Entry Signal of "Buy" when the last Bar looking left from the current bar was a "Profit target" or Stop loss" that was the EXIT.....

      So the thinking was I would do the following to evaluate the condition to qualify to GO LONG


      On the left select Price Close [0] > MISC Bars since exit, set Signal name to the name of the exit "@Profit target
      So in English what I feel like this is saying is
      If the Price of the Current bars close higher than the price of the last exit signal that was a Profit target then Go Long

      I tried your suggestion of On the left select Misc -> Bars since exit, set Signal name to the name of the entry, select Misc -> Numeric value on the right, set the value 0.
      and when I do my test returns 0 results

      So basically I am trying to put filter logic in my SET 1 Condition that will prevent over trading.. Without it as you can see in the image I provided that a profit target was hit and then the strategy immediately bought when the direction was lower and just keeps doing this

      I feel like I am missing the presence of an ELSE statement and all I haver are IFs ( So in my mind currently I am saying If A and B and C or D or E the do the thing .......What is missing is ELSE - (Do Nothing)


      Comment


        #4
        Hello jstaft,

        I understand that can be a bit confusing. The idea is that this is tied to a trade/position. The trade is opened by the entry and the entry signal name is used to track the trade. Both the barsSinceEntry and barsSinceExit will be referring to the trade using the signal name of the entry to identify it.

        Print the value to the output window to see what this is.

        First enable TraceOrders on the Defaults page. Then remove and re-add the instance of the strategy.

        Print the time of the bar, print BarsSinceExit using the signal name of the entry.

        Please include a screenshot of the print and include the text from the output.

        Below is a link to a forum post that demonstrates using prints to understand behavior. Please watch the video 'Debugging using prints with the Strategy Builder'.



        Comparing the Close[0] price like 3328.75 does not compare to a number of bars, like 5 bars ago. Print these, you will see these make no sense to compare.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks NinjaTrader_ChelseaB, I will go through and review what you suggested above but so far have found that in order to add prints I need to unlock my code and manually code them of which I will do a bit later.

          On a positive note, I implemented what you said in your 1st response but adding -1 since there are technically no trades present until there are... hahah
          By adding the following "BarsSinceExitExecution(0,@"Buy",0)=-1"

          This appears to now be doing what I was expecting and now not take a trade until much later and the other conditions are true!!

          I also put this in a group so I could toggle between If All / If Any

          Does the -1 make sense or did I added another condition here?

          Thanks for taking the time to have responded with such great level of detail!!

          Comment


            #6
            Hello jstaft,

            You do not need to unlock the script to use prints.

            Please watch the video 'Debugging using prints with the Strategy Builder''.

            I'm not able to design your logic, I can walk you through using prints to see if what you wrote is what you expect.

            There are consultants you can contact if you want help with logic. The community here on the forums can jump in as well.


            A -1 value means there has been no entry or there has been no exit. A value of 0 means the current bar is the entry or exit.

            Below is a link to the help guide where this is stated in the 'Method return value'.




            The if all and if any joins the conditions in 'ands' when set to 'if all' and with 'ors' when set to 'if any'.

            if condition 1
            and if condition 2
            and if condition 3
            -- if all of the conditions are true

            if condition 1
            or if condition 2
            or if condition 3
            -- if any of the conditions are true

            This is detailed in the Strategy Builder 301 training video.
            Below is a link to a forum post with helpful information about getting started with NinjaScript and C#.
            https://ninjatrader.com/support/foru...040#post786040
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks Again for the response and pushing me back to the 'Debugging using prints with the Strategy Builder''. That was a huge help and massive time saver on my part!!
              I am familiar with the IF ALL / IF ANY Function and why I use GROUP in my condition for greater control

              Also reviewed the help files on for BarSinceExitExecution and BarSinceEntryExecution

              Please see output on Strategy in image below

              It seems however that the condition you originally proposed is returning -1 for every bar when it is referencing a BUY in an a BarsSinceExitExecution(0,@"Buy",0)=0"

              However I put all of the "PRINTS" in the output for review

              BarsSinceExitExecution(0, @"Buy", 0)=0 (Result is -1 Always)
              BarsSinceExitExecution(0, @"Stop loss", 0)=0 (Result is number of bars)
              BarsSinceExitExecution(0, @"Profit target", 0)=0 (Result is number of bars)

              BarsSinceEntryExecution(0, @"Buy", 0)=0 (Result is number of bars)

              By all means I am not asking anyone to write my logic, just trying to better understand why what I am doing is not working.

              I did watch the 301 video and will watch it again as per recommendation as I am getting more familiar with the platform and would also welcome any collaboration with the community

              This dialog is of great value!

              Best Regards

              Comment


                #8
                Hello jstaft,

                From the prints I see I had that backwards. Thank you for posting the output that shows this.

                What is the current issue?

                BarsSinceExitExecution(0, @"Stop loss", 0)=0 (Result is number of bars)

                This is an incorrect value?

                The last print: '15:00:00 | Bars Since Exit Execution (Stop loss) = 309'.

                What value where you expecting here? It was 308 one bar ago..

                Did you enable TraceOrders? Where is the order submission showing?

                If you print the Position, on which bar does the position change?
                Last edited by NinjaTrader_ChelseaB; 02-03-2021, 08:21 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for the reply! I think the issue was my lack of understanding on these values and how I was trying to use them.

                  In my strategy I was trying to use the BAR Since last exit and put a condition that would not take any action based on PRICE.

                  Now printing this and evaluating I think what I am trying to do can not be accomplished with the use of BarSinceExit/Entry

                  I was trying to write a condition - if the PRICE of the current bars CLOSE s LESS than the BarSinceExitExecution DO nothing.
                  However if I am writing this in my SET 1 were I put all of my conditions to BUY, I realized I had to write this in a reverse condition so if the condition was met then it would buy

                  So I tried to say - if the PRICE of the Current Bar CLOSE was GREATER than the BarSinceExitExecution then to go long



                  But now based on the output from the prints I feel I am comparing APPLES and ORANGES

                  The BarsSinceExit/Entry are looking at the number of Bars
                  And the Price is looking at Price and the two can not be compared... (At Least this is my conclusion)

                  I will continue to debug with what I have learned with your assistance and apply this logic moving forward.

                  I will enable trace and review.

                  Thanks Chelsea!






                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Segwin, 05-07-2018, 02:15 PM
                  14 responses
                  1,789 views
                  0 likes
                  Last Post aligator  
                  Started by Jimmyk, 01-26-2018, 05:19 AM
                  6 responses
                  837 views
                  0 likes
                  Last Post emuns
                  by emuns
                   
                  Started by jxs_xrj, 01-12-2020, 09:49 AM
                  6 responses
                  3,294 views
                  1 like
                  Last Post jgualdronc  
                  Started by Touch-Ups, Today, 10:36 AM
                  0 responses
                  13 views
                  0 likes
                  Last Post Touch-Ups  
                  Started by geddyisodin, 04-25-2024, 05:20 AM
                  11 responses
                  63 views
                  0 likes
                  Last Post halgo_boulder  
                  Working...
                  X