Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can a wrong if(CurrentBar<x) check in indicator or strategy give a false signal?

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

    Can a wrong if(CurrentBar<x) check in indicator or strategy give a false signal?

    Hi all. I've been writing strategies and indicators with NT for a few weeks now, yet I still don't intuitively grasp the CurrentBar check in the start of OnBarUpdate that seems to be recommended.

    If I have a strategy that I'm testing, to base an indicator on, and it requires 50 bars, I've just been using if(CurrentBar<55) to give it plenty of bars. It occurred to me, if I run this strategy or indicator with, say, a setting of 60 bars, would the study potentially find a setup if all conditional checks are true on bar 58, or, bar[1], where I'm only expecting to get trades on bar[0]? (bar 0 being in my mind, the latest bar to close from the data feed) I hope my question is clear. Any insight would be great..
    Last edited by CSharpTrader; 11-19-2012, 07:50 PM.

    #2
    Hmmm... So what happened when you changed to 60 bars?


    QUOTE=CSharpTrader;310756]Hi all. I've been writing strategies and indicators with NT for a few weeks now, yet I still don't intuitively grasp the CurrentBar check in the start of OnBarUpdate that seems to be recommended.

    If I have a strategy that I'm testing, to base an indicator on, and it requires 50 bars, I've just been using if(CurrentBar<55) to give it plenty of bars. It occurred to me, if I run this strategy or indicator with, say, a setting of 60 bars, would the study potentially find a setup if all conditional checks are true on bar 58, or, bar[1], where I'm only expecting to get trades on bar[0]? (bar 0 being in my mind, the latest bar to close from the data feed) I hope my question is clear. Any insight would be great..[/QUOTE]

    Comment


      #3
      It's easy to see what happens... I'm looking for insight, clarity on the purpose, confirmation.

      Comment


        #4
        Originally posted by CSharpTrader View Post
        Hi all. I've been writing strategies and indicators with NT for a few weeks now, yet I still don't intuitively grasp the CurrentBar check in the start of OnBarUpdate that seems to be recommended.

        If I have a strategy that I'm testing, to base an indicator on, and it requires 50 bars, I've just been using if(CurrentBar<55) to give it plenty of bars. It occurred to me, if I run this strategy or indicator with, say, a setting of 60 bars, would the study potentially find a setup if all conditional checks are true on bar 58, or, bar[1], where I'm only expecting to get trades on bar[0]? (bar 0 being in my mind, the latest bar to close from the data feed) I hope my question is clear. Any insight would be great..
        It might. It depends on the conditions that are being evaluated at the time that the signal is generated, and how far back the Strategy looks to determine those conditions. IOW, the correct conditions may have occurred within the lookback period, and so will be seen when the Strategy starts to calculate. That is why it might be better if we can see the kind of code that you are asking about.

        Comment


          #5
          Thanks for the response.

          Here's a simple example:

          Code:
          protected override void OnBarUpdate()
           {
               if(CurrentBar<85){return;}
               else
               {
                   if(ToTime(Time[0])<= 140000)
                   {
                       if((Close[1]<EMA(50)[1])&& (Open[1]>EMA(50)[1])&&
                           (Close[0]<Open[0]&&Close[0]<EMA(50)[0])&&
                           ((High[0]-Close[0])/(High[0]-Low[0])>=.75)&&
                           (CountIf(delegate{return EMA(20)[0]>EMA(50)[0];},30)==30)&&
                           (CountIf(delegate{return (EMA(10)[0]>=EMA(20)[0]);},30)>=28)&&
                           ((Volume[0]>=SMA(Volume,15)[0]*1.5))||(Volume[1]>=SMA(Volume,15)[1]*1.5))
                       {
                           EnterShort();
                       }
                   }
                   if(Position.MarketPosition==MarketPosition.Short)
                   {
                       if(Close[0]>EMA(5)[0])
                           ExitShort();    
                   }
               }
           }
          This is a simple uptrend breakdown I'm trying to test. So... it looks to me to need 80 bars. If I have a check if CurrentBar<85, and I run the study with, 90, is that a safe assurance that I have adequate bars, or could it cause the conditions to be checked (and potentially find a trade) on a couple of bars back, whereas I'm only interested in it running on the latest bar. In a nutshell, I lack full understanding of how bars are processed/ the use of CurrentBar. I've read the docs but I don't quite have a full understanding.

          Comment


            #6
            Originally posted by CSharpTrader View Post
            Thanks for the response.

            Here's a simple example:

            Code:
            protected override void OnBarUpdate()
             {
                 if(CurrentBar<85){return;}
                 else
                 {
                     if(ToTime(Time[0])<= 140000)
                     {
                         if((Close[1]<EMA(50)[1])&& (Open[1]>EMA(50)[1])&&
                             (Close[0]<Open[0]&&Close[0]<EMA(50)[0])&&
                             ((High[0]-Close[0])/(High[0]-Low[0])>=.75)&&
                             [COLOR=red](CountIf(delegate{return EMA(20)[0]>EMA(50)[0];},30)==30)&&[/COLOR]
            [COLOR=red]                 (CountIf(delegate{return (EMA(10)[0]>=EMA(20)[0]);},30)>=28)[/COLOR]&&
                             ((Volume[0]>=SMA(Volume,15)[0]*1.5))||(Volume[1]>=SMA(Volume,15)[1]*1.5))
                         {
                             EnterShort();
                         }
                     }
                     if(Position.MarketPosition==MarketPosition.Short)
                     {
                         if(Close[0]>EMA(5)[0])
                             ExitShort();    
                     }
                 }
             }
            This is a simple uptrend breakdown I'm trying to test. So... it looks to me to need 80 bars. If I have a check if CurrentBar<85, and I run the study with, 90, is that a safe assurance that I have adequate bars, or could it cause the conditions to be checked (and potentially find a trade) on a couple of bars back, whereas I'm only interested in it running on the latest bar. In a nutshell, I lack full understanding of how bars are processed/ the use of CurrentBar. I've read the docs but I don't quite have a full understanding.
            The 2 conditions that I have highlighted in red, are looking back 30 bars for condition validity. However, they are merely gating conditions, which may be valid on bar85, which will be the first bar on which calculation will take place.

            So, if you are escaping 85 bars, it just means that your conditions, while true will not be evaluated, and cannot trigger any orders, until the Strategy processing code proper starts to run, which it only does on and after bar85.

            Comment


              #7
              OK... thank you. What if I run the strategy with 90 bars?

              Comment


                #8
                Originally posted by CSharpTrader View Post
                OK... thank you. What if I run the strategy with 90 bars?
                Gate as to when your Strategy processing code proper starts to run is by the number of bars you are escaping. The processing code, in this case starts running on bar85, with no knowledge of the future, so using 90 bars makes no difference: the code starts running on bar85.

                Comment


                  #9
                  Ok, that's what I thought... back to my original question then... in that case, could I get "false" trades/ signals on bars 86-89 (since 90 is the last, what I see as [0])

                  Comment


                    #10
                    Originally posted by CSharpTrader View Post
                    Ok, that's what I thought... back to my original question then... in that case, could I get "false" trades/ signals on bars 86-89 (since 90 is the last, what I see as [0])
                    It was a valid signal on whichever bar it triggered. Why are you calling it a false signal? At the time the signal triggered, it could not know what would happen on bar90, so why would it be a false signal. Processing is handled on a streaming basis.

                    Now, however, if the request is that you want the Strategy to only start processing from the time that you enable it, and ignore everything that happened before that bar when you started the Strategy, then what you are looking for is the statement at the start of OnBarUpdate():

                    Code:
                     
                    if (Historical) return;

                    Comment


                      #11
                      "False" to me. It's the crux of my whole issue/ question. Because I'd only be interested in an alert being triggered from the indicator on the latest bar. In our example, bar 90. It could trigger, then a couple bars later, the conditions could evaluate to false. I do realize that if that's the case, the signal I'm looking for would have fired a couple bars earlier. I'm trying for a full understanding on principle though..

                      Comment


                        #12
                        Originally posted by CSharpTrader View Post
                        "False" to me. It's the crux of my whole issue/ question. Because I'd only be interested in an alert being triggered from the indicator on the latest bar. In our example, bar 90. It could trigger, then a couple bars later, the conditions could evaluate to false. I do realize that if that's the case, the signal I'm looking for would have fired a couple bars earlier. I'm trying for a full understanding on principle though..
                        Hence my last response. By checking the Historical property, all action will only be handled on the most current bar at all times, as every bar becomes historical as soon as the next bar starts.
                        Last edited by koganam; 11-20-2012, 02:06 PM.

                        Comment


                          #13
                          OK, thanks.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          656 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          370 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          577 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X