Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ensuring onBarUpdate will not process already existing Bars?

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

    Ensuring onBarUpdate will not process already existing Bars?

    Hi Team,

    I have built an indicator that sends me an email each time a condition is met,
    The problem is, that when I load my indicator (which have 5 days back) I get emails every time this condition triggered on the "Old" data.

    Is there a way for me to start the sending only from the current bar onwards?

    Thank you!





















    #2
    Hello liadmz,

    Thanks for your post and welcome to the Ninjatrader forums!

    As your post relates to Indicators I will move this topic to the appropriate forum (you posted in strategy development)

    Just to confirm, you are asking about a NinjaTrader8 indicator you created?

    What method are you using to send the e-mail(s)? SendMail() or share() or??

    Perhaps you can post the line(s) of code that relate (change the e-mail addresses to something like xxxx.gmail.com so that you don't get unsolicited spambot mails.

    Comment


      #3
      Originally posted by liadmz View Post
      I have built an indicator that sends me an email each time a condition is met,
      The problem is, that when I load my indicator (which have 5 days back) I get emails every time this condition triggered on the "Old" data.

      Is there a way for me to start the sending only from the current bar onwards?
      Sounds like you want to avoid sending email on historical bars ...

      From your question, I presume you're not using Ninja's SendMail?

      If so, whenever your custom send email code needs to run, you
      need a 'guard' to prevent doing so on Historical bars, like this,

      if (State != State.Historical)
      {
      ... your code to send email
      }

      But, if you use NinjaScript's own SendMail, it already does this check.

      Comment


        #4
        Originally posted by NinjaTrader_PaulH View Post
        Hello liadmz,

        Thanks for your post and welcome to the Ninjatrader forums!

        As your post relates to Indicators I will move this topic to the appropriate forum (you posted in strategy development)

        Just to confirm, you are asking about a NinjaTrader8 indicator you created?

        What method are you using to send the e-mail(s)? SendMail() or share() or??

        Perhaps you can post the line(s) of code that relate (change the e-mail addresses to something like xxxx.gmail.com so that you don't get unsolicited spambot mails.
        Yes, I am talking about NT8 indicator I created

        The code is a simple API using C# (the server-side sends the actual email and SMS)

        Code:
        var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
        httpWebRequest.Method = "POST";
        httpWebRequest.ContentType = "application/json";
        
        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
             string json = "{\"text\":\"" + txt + "\"}";
             streamWriter.Write(json);
        }
        
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
             var result = streamReader.ReadToEnd();
        }

        Comment


          #5
          Originally posted by bltdavid View Post

          Sounds like you want to avoid sending email on historical bars ...

          From your question, I presume you're not using Ninja's SendMail?

          If so, whenever your custom send email code needs to run, you
          need a 'guard' to prevent doing so on Historical bars, like this,

          if (State != State.Historical)
          {
          ... your code to send email
          }

          But, if you use NinjaScript's own SendMail, it already does this check.

          Thank you!
          That is exactly what I was looking for!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          71 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          143 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X