Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry() in OnBarUpdate Script

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

    BarsSinceEntry() in OnBarUpdate Script

    I think I figured out the time portion of my problem, now I have a question about using BarsSinceEntry and BarsSinceExit as my entry and exit conditions.

    My understanding of using BarsSinceExit in an onbarupdate script is that it will either return the number of bars since exit, or -1 in the case of no history of an exit. Is this the case? The way I had envisioned using it is in the condition that BarsSinceExit!=0 as one of my entry conditions. The problem that I have is that I am worried the today, as with the BarsSinceEntry()!=0 may mean that today will make BarsSinceEntry()=1. That is, if I do enter today, then will that make BarsSinceEntry=1 in an onbarupdate method? Or will it still be at 0?

    The next day I expect that it will return a BarsSinceEntry of 1, since the program is now only running between 9:30 and 4 pm EST. Thus, I use both BarsSinceEntry() and BarsSinceExit()!=0. BarsSinceExit()!=0 is used for the entry, and BarsSinceEntry()>=1 or 2 depending on the answer you give to the question, does the BarsSinceEntry increase by 1 on the entry today? That is, if I buy today, will BarsSinceEntry be 0 or 1? It wasn't clear in the documents which it would be. I'm sure it will work the same for BarsSinceExit().

    Thanks,

    Beau

    #2
    Hi Beau,

    If the bar has not closed I believe it will not add to the counter.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Why didn't the order submit today?

      if (ToTime(Time[0]) >= 93000 && ToTime(Time[0]) <= 1600000)
      {
      if (s1b==false
      && BarsSinceExit() != 0
      && (GetCurrentAsk()) * (1 + -0.0025) <= (Bollinger(Low, 1.5, 10).Lower[0]) * (1 + -0.055)
      && LinReg(Close,
      10)[0] >= (Bollinger(Low, 1.5, 10).Lower[0]) * (1 + -0.055)
      && StdError(Close,
      3).Middle[0] >= 3)
      {
      EnterLongLimit(DefaultQuantity, (Bollinger(Low,
      1.5, 10).Lower[0]) * (1 + -0.055), "S1");

      Comment


        #4
        beauw,

        Please use TraceOrders = true and debug your order. Also use prints to figure out what your code is doing. Whenever you have difficulties with orders the first thing you want to do is make sure that your if-statement even evaluated to true. Use prints everywhere to determine this. Then you can proceed to debug what went wrong with your order.

        Please see these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          First, is that how you would make sure the time is between 9:30 am and 4 pm? Answer that question. The next question was about the BarsSinceExit!=0. That would be the only area that would have prevented this execution. The condition was true on at least 50 stocks today, but I think the BarsSinceExit prevented it, so explain why it wasn't submitted. The s1b==false is set to false at the beginning.

          Comment


            #6
            beauw,

            Yes, that is how you code the time filter. For information on using time filters please see this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=3226

            Your strategy behaves exactly as it is told by your code. If an order does not get placed it is because your if-statement was never evaluated to be true. If an order is ignored or rejected you need TraceOrders to determine the reason and adjust your code to accomodate for it.

            When debugging you cannot discount any portion of your code. You need to debug your condition bit by bit. You cannot just assume because it was true on 50 stocks that it will be true in this instance. You need to print out values for each and every single one of your conditions and run through them manually. It is time consuming, yes, but that is how you need to proceed while debugging your code.

            BarsSinceExit() is -1 when there is no exit to be found. After that it will take on a value representative of how many bars since the exit.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by WHICKED, Today, 12:56 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cre8able, Today, 01:16 PM
            0 responses
            1 view
            0 likes
            Last Post cre8able  
            Started by chbruno, 04-24-2024, 04:10 PM
            2 responses
            47 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by WHICKED, Today, 12:45 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by samish18, Today, 01:01 PM
            0 responses
            5 views
            0 likes
            Last Post samish18  
            Working...
            X