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

bars ago

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

    bars ago

    1) Using strategy builder you can specify on only certain indicators that a condition is true if its WITHIN a certain number of bars back (NOT talking about BARS AGO - thats on everything).
    How can you do a WITHIN bars for something like a price comparison (open > close)? I assume you'd have to hard code it and strategy builder couldnt do it? Can that be changed?

    2) bars since exit execution > 3 would only be true if the bars since the last exit was greater than 3? ...and bars since exit execution == -1 would mean its always true if there hasnt ever been a trade?

    Thanks!
    Last edited by ezrollin; 11-29-2021, 11:16 PM.

    #2
    Hello ezrollin,

    Thanks for your post.

    1)
    Using strategy builder you can specify on only certain indicators that a condition is true if its WITHIN a certain number of bars back (NOT talking about BARS AGO - thats on everything).
    How can you do a WITHIN bars for something like a price comparison (open > close)? I assume you'd have to hard code it and strategy builder couldnt do it? Can that be changed?
    Correct, you would have to "hard code" by specifying the bars ago. There are no alternatives. The strategy builder was made this way to prevent a very common scripting error which is referring to a bar (bars ago) that does not exist when using a variable in place of the bar ago value. The strategy builder generates code from what you enter so when you specify (hard code) a bars ago of 2 the strategy builder can create the needed code to prevent a bars ago error because it knows you need to access 2 bars ago. If you (could) replace that with a variable that is calculated at run time, the strategy builder would be unable to know what the worst case value of bars ago should be and thus could not generate the needed code that would prevent a bars ago referencing error. So while this is a limitation its purpose is to allow you to create strategies that won't generate errors.

    2)bars since exit execution > 3 would only be true if the bars since the last exit was greater than 3? ...and bars since exit execution == -1 would mean its always true if there hasnt ever been a trade?
    Correct, when using the BarsSinceExitExecution() as a condition to enter an order you have to account for the fact that if no previous order has been placed the method will return a -1. Otherwise, if an exit has occurred the method returns the bars ago value that the exit occurred. This means when you create this as an entry condition you would need to create as a "group" that is configured to "If any" which allows either condition to be true and thus allows the group to be true.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      So I set up that Bars since exit execution==3 to avoid getting stopped out over and over again in case the next signal is a false signal.
      So like: if i got stopped out, dont get back in on the next signal because it is also probably a false entry, so take a break for a few bars cause the next one is likely false as well and price is just gonna keep grinding higher/lower.
      It works great to keep me from stop outs!!

      But sometimes my perfect take profit Exit signal is also a new entry signal at the same time!
      So my bars since exit execution is keeping me from taking the reversal.
      How can I have the best of both worlds? I want my cake and eat it too!

      I want to delay if theres a stop out but enter if the exit wasnt a stop out (it was a take profit). I can send pics if needed. thanks!



      Comment


        #4
        Hello ezrollin,

        Thanks for your reply.

        One idea you can test out would be to create a bool variable, set to false. In a set you can check to see if the Strategy>UnrealizedPNL is less than 0 and when true to set the bool to true.
        You can then use the state of that bool to help drive if you enter immediately or delay.
        You will also need a set that resets the bool to false, such as when you are in a flat market position.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Bhavika, Yesterday, 09:03 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by slimcactus, Today, 10:26 AM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Monares, Today, 10:49 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_JustinD  
        Started by d122y, Today, 10:20 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by trader3000a, Today, 06:41 AM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X